The two masters can even generate a few cycles of the clock and data that ‘match’, but eventually one will output a ‘low’ when the other tries for a ‘high’. The ‘low’ wins, so the
14
AN10216-01 I2C Manual
‘loser’ device withdraws and waits until the bus is freed again.
There is no minimum clock speed; in fact any device that has problems to ‘keep up the pace’ is allowed to ‘complain’ by holding the clock line low. Because the device generating the clock is also monitoring the voltage on the SCL bus, it immediately ‘knows’ there is a problem and has to wait until the device releases the SCL line.
For full details of the bus capabilities refer to Philips Semiconductors Specification document ‘The I2C bus specification’ or ‘The I2C bus from theory to practice’ book by Paret and Fenger published by John Wiley & Sons. The I2C specification and other useful application information can be found on Philips Semiconductors web site at http://www.semiconductors.philips.com/i2c/
DesignCon 2003 TecForum I2C Bus Overview 34
I2C Address, 7-bit and 10-bit formats • The 1st byte after START determines the Slave to be addressed • Some exceptions to the rule: – “General Call” address: all devices are addressed : 0000 000 + R/W = 0 – 10-bit slave addressing : 1111 0XX + R/W = X
XX = the 2 MSBs The 8 remaining bits Only one device will acknowledge S A1 1 1 1 1 0 X X R/W X X X X X X X X A2 DATA •10-bit addressing The 7 bits Only one device will acknowledge S A X X X X X X X R/W DATA •7-bit addressing More than one device can acknowledge
“0” = Write
SCL
SDA
“1” = Read
SCL
SDA
Slide 34 Slide 34 shows the I2C address scheme. Any I2C device can be attached to the common I2C bus and they talk with each other, passing information back and forth. Each device has a unique 7-bit or 10-bit I2C address. For 7-bit devices, typically the first four bits are fixed, the next three bits are set by hardware address pins (A0, A1, and A2) that allow the user to modify the I2C address allowing up to eight of the same devices to operate on the I2C bus. These pins are held high to VCC, sometimes through a resistor, or held low to GND.
The last bit of the initial byte indicates if the master is going to send (write) or receive (read) data from the slave. Each transmission sequence must begin with the start condition and end with the stop condition. On the 8th clock pulse, SDA is set ‘high’ if data is going to be read from the other device, or ‘low’ if data is going to be sent (write). During its 9th clock, the
master releases SDA line to accomplish the Acknowledge phase. If the other device is connected to the bus, and has decoded and recognized its ‘address’, it will acknowledge by pulling the SDA line low. The responding chip is called the bus ‘slave’.
DesignCon 2003 TecForum I2C Bus Overview 35
I2C Read and Write Operations (1) • Write to a Slave device
The master is a “MASTER - TRANSMITTER”: –it transmits both Clock and Data during the all communication Each byte is acknowledged by the slave device • Read from a Slave device
Master Slave receivertransmitterS slave address W A data A data A P S slave address W A data A data A P < n data bytes >
The master is a “MASTER TRANSMITTER then MASTER - RECEIVER”: – it transmits Clock all the time – it sends slave address data and then becomes a receiver
S slave address R A data A data A P receiver transmitter
Each byte is acknowledged by the master device (except the last one, just before the STOP condition)
< n data bytes >
Slide 35
Terminology for Bus Transfer • F (FREE) - the bus is free; the data line SDA and the SCL clock are both in the high state. • S (START) or SR (Repeated START) - data transfer begins with a start condition (not a start bit). The level of the SDA data line changes from high to low, while the SCL clock line remains high. When this occurs, the bus is ‘busy’. • C (CHANGE) - while the SCL clock line is low, the data bit to be transferred can be applied to the SDA data line by a transmitter. During this time, SDA may change its state, as along as the SCL line remains low. • D (DATA) - a high or low bit of information on the SDA data line is valid during the high level of the SCL clock line. This level must be maintained stable during the entire time that the clock remains high to avoid misinterpretation as a Start or Stop condition. • P (STOP) - data transfer is terminated by a stop condition, (not a stop bit). This occurs when the level on the SDA data line passes from the low state to the high state, while the SCL clock line remains high. When the data transfer has been terminated, the bus is free once again.
15
AN10216-01 I2C Manual
DesignCon 2003 TecForum I2C Bus Overview 36
I2C Read and Write Operations (2) • Combined Write and Read
• Combined Read and Write
S slave address R A data A data A P < n data bytes > S slave address W A data A data A P Sr slave address W A data A data A P < m data bytes >
Each byte is acknowledged by the master device (except the last one, just before the Re-START condition)
Each byte is acknowledged by the slave device
S slave address W A data A data A P S slave address W A data A data A Sr < n data bytes >
Each byte is acknowledged by the slave device
Sr slave address R A data A data A P < m data bytes >
Each byte is acknowledged by the master device (except the last one, just before the STOP condition)
Slide 38 shows how multiple masters can synchronize their clocks, for example during arbitration. When bus capacitance affects the bus rise or fall times the master will also adjust its timing in a similar way.
“1” = Read “0” = Write
“0” = Write “1” = Read
No acknowledge
1
“0” “1” “0” “1”
DesignCon 2003 TecForum I2C Bus Overview 39
I2C Protocol - Arbitration • Two or more masters may generate a START condition at the same time • Arbitration is done on SDA while SCL is HIGH - Slaves are not involved
Start command
“1”
Master 1 loses arbitration DATA1 ≠SDA
“0”
Slide 36
Slide 36 shows a combined read and write operation.
DesignCon 2003 TecForum I2C Bus Overview 37
Acknowledge; Clock Stretching •Acknowledge Done on the 9th clock pulse and is mandatory Æ Transmitter releases the SDA line Æ Receiver pulls down the SDA line (SCL must be HIGH) Æ Transfer is aborted if no acknowledge
• Clock Stretching - Slave device can hold the CLOCK line LOW when performing other functions - Master can slow down the clock to accommodate slow slaves
Acknowledge
Slide 39
If there are two masters on the same bus, there are arbitration procedures applied if both try to take control of the bus at the same time. When two chips try to start communication at the same time they may even generate a few cycles of the clock and data that ‘match’, but eventually one will output a ‘low’ when the other tries for a ‘high’. The ‘low’ wins, so the ‘loser’ device withdraws and waits until the bus is freed again. Once a master (e.g., microcontroller) has control, no other master can take control until the first master sends a stop condition and places the bus in an idle state. Slide 37
DesignCon 2003 TecForum I2C Bus Overview 40
There are 3 basic ways to drive the I2C bus: 1) With a Microcontroller with on-chip I2C Interface Bit oriented - CPU is interrupted after every bit transmission (Example: 87LPC76x) Byte oriented - CPU can be interrupted after every byte transmission (Example: 87C552) 2) With ANY microcontroller: 'Bit Banging’ The I2C protocol can be emulated bit by bit via any bi-directional open drain port 3) With amicrocontrollerin conjunction with bus controller like the PCF8584 or PCA9564 parallel to I2C bus interface IC
Master
I2C BUS
Slave 4Slave 3Slave 2Slave 1
What do I need to drive the I2C bus?
Slide 37 shows how the Acknowledge phase is done and how slave devices can stretch the clock signal. Most Philips slave devices do not control the clock line.
DesignCon 2003 TecForum I2C Bus Overview 38
I2C Protocol - Clock Synchronization Vdd
CLK 1 CLK 2 SCL
Master 1 Master 2
• LOWperiod determined by the longestclock LOWperiod • HIGH period determined by shortest clock HIGH period
2 3 4
Slide 40 Slide 40 shows there are multiple ways to control I2C slaves.
Slide 38
16
AN10216-01 I2C Manual • The I2C bus is a de facto world standard that is implemented in over 1000 different ICs (Philips has > 400) and licensed to more than 70 companies
DesignCon 2003 TecForum I2C Bus Overview 41
Pull-up Resistor calculation DC Approach -Static Load Worst Case scenario: maximum current load that the output transistor can handle Æ 3 mA . This gives us the minimum pull-up resistor value Vdd min - 0.4 V R = With Vdd = 5V (min 4.5 V), Rmin = 1.3 kΩ 3 mA AC Approach -Dynamic load • maximum value of the rise time: –1µs for Standard-mode (100 kHz) –0.3 µs for Fast-mode (400 kHz) • Dynamic load is defined by: – device output capacitances (number of devices) –trace, wiring V(t) = VDD (1-e -t /RC ) Rising time defined between 30% and 70% Trise = 0.847.RC
DesignCon 2003 TecForum I2C Bus Overview 42
I2C Bus recovery • Typical case is when masters fails when doing a read operation in a slave • SDA line is then non usable anymore because of the “Slave-Transmitter” mode. • Methods to recover the SDA line are: – Reset the slave device (assuming the device has a Reset pin) – Use a bus recovery sequence to leave the “Slave-Transmitter” mode • Bus recovery sequence is done as following: 1 -Send 9 clock pulses on SCL line 2 - Ask the master to keep SDA High until the “Slave-Transmitter” releases the SDA line to perform the ACK operation 3 -Keeping SDA High during the ACK means that the “Master-Receiver” does not acknowledge the previous by