i2c Protocol (2)
i2c Protocol (2)
PROTOCOL???
TYPES:
I. INTER SYSTEM
PROTOCOL
II. INTRA SYSTEM
THUMB RULE FOR ANY LEARNING
1-WIRE INTERFACE (OPTIONAL)
• 1-WIRE PROTOCOL BY DALLAS SEMICONDUCTOR
• NO CLOCK AND ONLY ONE DATA LINE
• HALF DUPLEX, BIDIRECTIONAL, LOW SPEED AND POWER
• LONG DISTANCE SERIAL DATA COMMUNICATION
• ONLY MASTER- SLAVE CONFIGURATION – ONE MASTER AND UPTO 100 SLAVE DEVICE
• DOESNOT USE CLOCK SIGNAL INSTEAD SLAVE DEVICES ARE INTERNALLY CLOCKED
AND SYNCHRONIZED WITH A SIGNAL FROM THE MASTER DEVICE
• TYPICAL DATA SPEED – 15.4KBPS AND MAXIMUM 125KBPS
I2C – INTER-INTEGRATED CIRCUITS – IIC OR
TWI
• WHO – PHILIPS SEMICONDUCTOR (NOW NXP SEMICONDUCTORS), ATMEGA,
INTEL
• WHEN – 1982, 1992, 1995
• WHY – ESTABLISH COMMUNICATION BETWEEN TWO OR MORE IC
• WHERE – EEPROM, I/O INTERFACES, PERIPHERAL DEVICES
CONTROLLER AS MASTER & PERIPHERAL DEVICES AS SLAVES
WHAT
• SYNCHRONOUS – SENDER GETS ACK RESPONSE FROM RECEIVER WHEN DATA RECEIVED
SUCCESSFULLY
• HALF DUPLEX BIDIRECTIONAL – DATA FLOW FROM MASTER TO SLAVE OR SLAVE TO
MASTER
• MULTI-CONTROLLER/MULTI-TARGET (MASTER/SLAVE)
• PACKET SWITCHED
• SINGLE-ENDED
• SERIAL COMMUNICATION BUS (TWO WIRED –SDA, SCL)
• BUILT IN COLLISION DETECTION
• CLOCK FREQUENCY – (0-1MHZ) DRIVING AT 30 MILLI AMPS
• OPERATING TEMP - -40 TO +85 DEGREE CELSIUS
• MODES – STANDARD AND FAST COMMONLY USED
• DEVICES – 128 DEVICE (7 BIT ADDRESSING – 0-127 (2^7))
OVERCOME LIMITATION BASED ON OTHER MODES 8,10 BIT ADDRESSING
(8 BIT – 2^8, 10 BIT – 2^10)
I2C Mode Speed
Standard Mode 100 kbps
Fast Mode 400 kbps
Fast Mode Plus 1 Mbps
High Speed Mode 3.4 Mbps
Ultra-Fast Mode 5 Mbps
IF RESISTORS MISSING, SCL & SDA LINES ALWAYS LOW – NEARLY 0 VOLTS AND I2C BUS WILL
NOT WORK
STEPS OF I2C DATA TRANSMISSION
1. The master sends the start condition to every connected slave by switching the SDA line
from a high voltage level to a low voltage level before switching the SCL line from high to
low
2. The master sends each slave the 7 or 10 bit address of the slave it wants to
communicate with, along with the read/write bit
3. Each slave compares the address sent from the master to its own address. If the
address matches, the slave returns an ACK bit by pulling the SDA line low for one bit. If the
address from the master does not match the slave’s own address, the slave leaves the
SDA line high
6. To stop the data transmission, the master sends a stop condition to the slave by
switching SCL high before switching SDA high
SINGLE MASTER WITH
MULTIPLE
Because I2C uses addressing, multiple SLAVES
slaves can be controlled from a single master. With a 7 bit
address, 128 (27) unique address are available. Using 10 bit addresses is uncommon, but provides
1,024 (210) unique addresses.
To connect multiple slaves to a single master, wire them like this, with 4.7K Ohm pull-up resistors
connecting the SDA and SCL lines to Vcc:
MULTIPLE MASTERS WITH MULTIPLE SLAVES
Multiple masters can be connected to a single slave or multiple slaves.
Problem: When two masters try to send or receive data at the same time over the SDA line.
Solution: Each master needs to detect if the SDA line is low or high before transmitting a message.
If the SDA line is low, this means that another master has control of the bus, and the master should
wait to send the message.
If the SDA line is high, then it’s safe to transmit the message.
To connect multiple masters to multiple slaves, use the following diagram, with 4.7K Ohm pull-up
resistors connecting the SDA and SCL lines to Vcc:
EXAMPLE
I2C HARDWARE DESIGN - PHYSICAL
LAYER
VDD I2C System Features
SDA
VDD
VDD
VDD
SDA
SDA
SDA
SDA
SCL
SCL
SCL
SCL
Bi-directional
communication, half
Microcontroller Microcontroller ADC DAC
Controller 1 Controller 2 Target 1 Target 2
duplex
Allows for multiple
GND
GND
GND
GND
controllers and multiple
GND targets
GND
Requires pull-up
resistors on both SDA
and SCL
1
9
I2C PHYSICAL LAYER – OPEN-DRAIN
CONNECTION
VD When NMOS turns
D Pull- ON, SDA or SCL is
up
SDA, resisto
pulled low
r
SCL SDA, SCL
Voltage VDD
Device
I2C
logic
GN
D
Open- GND Quick transition from high to low as NMOS
drain
connectio
pulls charge from any bus capacitance
n from SDA, SCL
2
0
I2C PHYSICAL LAYER – OPEN-DRAIN
CONNECTION
VD When NMOS turns OFF,
D Pull- SDA or SCL is released and
up
SDA, resisto
returns high from the pullup
r resistor
SCL
D D
Q1 Q3 connection is called a
• Open drain output
Device
On Off
“wired-OR”
cannot connect
Device
I2C I2C
logic Off On logic
Bus Contention
Q2 Output at
indeterminate
Q4 together
Push-Pull GND
state
GND Push-Pull
• Connecting outputs
Output
Output
tries to
dive high tries to
dive low
together can cause a
bus contention where
the output state is
indeterminate
DESIGN (ARCHITECTURE)
• BUS HAS TWO ROLES FOR NODES: MASTER AND SLAVE
• MASTER NODE – NODE GENERATES THE CLOCK AND INITIATES COMMUNICATION
WITH SLAVE
• SLAVE NODE – NODE THAT RECEIVES THE CLOCK AND RESPOND WHEN
ADDRESSED BY MASTER
• 4 POTENTIAL MODES OF OPERATION FOR BUS DEVICE, MOST DEVICE USE A SINGLE
ROLE AND TWO MODES
• MASTER TRANSMIT – MASTER NODE SENDING DATA TO SLAVE
• MASTER RECEIVE - MASTER NODE RECEIVING DATA TO SLAVE
• SLAVE TRANSMIT - SLAVE NODE SENDING DATA TO MASTER
• SLAVE RECEIVE - SLAVE NODE RECEIVING DATA TO MASTER
BUILDING BLOCKS OF I2C SERIAL
INTERFACE
ADVANTAGE OF I2C
• I2C REQUIRES TWO SIGNALS/PINS TO COMMUNICATE NUMEROUS DEVICES
• USES CHIP ADDRESSING, WE ADD ADDITIONAL DEVICES TO BUS– NO NEED OF
WIRING
• DEVICE CAN WORK AS BOTH MASTER AND SLAVE
• EMPLOYS BETTER ERROR HANDLING FUNCTIONALITY
DISADVANTAGE OF I2C
SDA
SCL
QUIZ: BASICS OF I2C: THE I2C
PROTOCOL
2. In the address frame, after the controller device sends the 7 bit
address, what is the next part of the I2C protocol sent?
a. The target device sends the ACK to acknowledge the communication
coming from the controller device
b. The controller device sends the R/W bit to indicate if it wants to read from
or write to the target device
c. The controller device send a STOP condition before sending the next data
QUIZ: BASICS OF I2C: THE I2C
PROTOCOL
2. In the address frame, after the controller device sends the 7 bit
address, what is the next part of the I2C protocol sent?
a. The target device sends the ACK to acknowledge the communication
coming from the controller device
b. The controller device sends the R/W bit to indicate if it wants to read from
or write to the target device
c. The controller device send a STOP condition before sending the next data
A6 A5 A4 A3 A2 A1 A0
R/W
QUIZ: BASICS OF I2C: THE I2C
PROTOCOL
3. Because of the NMOS open-drain connection to SDA and SCL,
which part of the communication waveform is faster?
a. The rise time of SDA and SCL
b. The fall time of SDA and SCL
c. The rise time and fall time of SDA and SCL are the same
QUIZ: BASICS OF I2C: THE I2C
PROTOCOL
3. Because of the NMOS open-drain connection to SDA and SCL,
which part of the communication waveform is faster?
a. The rise time of SDA and SCL
b. The fall time of SDA and SCL
c. The rise time and fall time of SDA and SCL are the same
SDA, SCL
Voltage VDD
GND
• EVENT HANDLERS – MANAGE DATA RECEIVED FROM OTHER DEVICES IN I2C NETWORK
• SNIFFER – PASSIVELY LISTEN TO SIGNALS ON THE BUS AND DETECTS THE RESPONSIBLE
DEVICE EVEN IF CHIP NOT KNOWN
I2C REGISTER