I2C Bus
I2C Bus
This results in lots of wiring on the PCB's to route the address and data lines.
The I2C bus has been adopted by several leading chip manufacturers like
Xicor, ST Microelectronics, Infineon Technologies, Intel, Texas Instruments,
Maxim, Atmel, etc..
The active wires, called SDA and SCL, are both bi-directional.
The I2C protocol specification states that, one who initiates a data transfer
on the bus is considered the Bus Master and all the other Ic’s are slave.
Data validity
• The data on the SDA line must be stable during the HIGH period of the
clock. The HIGH or LOW state of the data line can only change when the
clock signal on the SCL line is LOW.
I2C Bus Events: The START and STOP conditions
• The start condition acts as a signal to all connected IC's that something is about to
be transmitted (ADDRESS) on the bus. As a result, all connected chips will listen to
the bus.
• After a message has been completed, a STOP condition is sent.
• This is the signal for all devices on the bus that the bus is available again.
• If a chip was accessed and has received data during the last
transaction, it will now process this information.
• A Stop condition ALWAYS denotes the END of a transmission. Even it can be
issued in the middle of a transaction or in the middle of a byte, in this case, it
disregards the information sent and resumes the "listening state", waiting for a new
start condition.
• Once the start condition has been sent, a byte can be transmitted by the
MASTER to the SLAVE
• This first byte after a start condition will identify the slave on the bus
(address) and will select the mode of operation which is specified by the LSB.
I2C Bus operation
As the I2C bus gained popularity, it was soon discovered that the number of available
addresses was too small.
one of the reserved addresses has been allocated to a new task to switch to 10-bit
addressing mode.
• If there are slaves on the bus that can operate in the extended 10-bit addressing
mode, they will ALL respond with an ACK signal to the master.
• The second byte that gets transmitted by the master will then be taken in and
evaluated against their address.
• Note:
Even in 10-bit extended addressing mode, Bit 0 of the first byte after
the Start condition determines the slave access mode ('1' = read / '0' = write).
Theory of Operation
I2C has a master/slave protocol. The master initiates the communication. The
sequence of events are:
1. The Master device issues a start condition. This condition informs all the slave devices to
listen on the serial data line for instructions.
2. The Master device sends the address of the target slave device and a read/write flag.
3. The Slave device with the matching address responds with an acknowledgement signal.
4. Communication proceeds between the Master and the Slave on the data bus. Both the
master and slave can receive or transmit data depending on whether the communication is
a read or write. The transmitter sends 8-bits of data to the receiver which replies with a 1-
bit acknowledgement.
5.When the communication is complete, the master issues a stop condition indicating that
everything is done.
Reserved addresses
• Notes 3 and 4:
These addresses are used when data other than I2C data has to be
transmitted over the bus.
• Note 5:
These addresses are for further expansion.
When an address or data byte has been transmitted onto the bus then
this must be ACKNOWLEDGED by the slave.
• The I2C bus was originally developed as a multi-master bus. This means
that more than one device initiating transfers can be active in the system.
• When using only one master on the bus there is no real risk of
corrupted data, except if a slave device is malfunctioning or if there is a fault
condition involving the SDA / SCL bus lines.
How can you know if some other device is transmitting on the bus ?
• The physical bus setup helps us out.
• Since the bus structure is designed in such a way (if one device pulls a line
low it stays low), you can test if the bus is idle or occupied.
• When a master changes the state of a line to HIGH, it MUST always check
that the line really has gone to HIGH.
• If it stays low then this is an indication that the bus is occupied and some
other device.
• If a master can't get a certain line to go high, it lost arbitration and needs to
back off and wait until a stop condition.
• The problem of data corruption will occur if both the masters pulls the SDA
low at the same time.
• The two MCU's are accessing a slave in write mode at address 1111001.
• The slave acknowledges this. So far, both masters are under the impression
that they "own" the bus.
• MCU1 wants to transmit 01010101 to the slave.
• MCU2 wants to transmit 01100110 to the slave.
• The moment the data bits do not match anymore one of them loses
arbitration and backs off.
• For as long as there has been no STOP present on the bus, it won't touch the
bus and leave the SDA and SCL lines alone.
• The moment a STOP was detected, MCU2 can attempt to transmit again to
acquire the owner ship of the bus again.
Clock Synchronization
• All masters generate their own clock on the SCL line to transfer messages on
the I2C-bus.
• Data is only valid during the HIGH period of the clock.
NOTE:
• A synchronized SCL clock is generated with its LOW period determined by
the device with the longest clock LOW period.
• Its HIGH period determined by the one with the shortest clock HIGH period.
• Sync clock
• Master clk
• Device clk
TRANSFERRING DATA
Acknowledge:
• The receiver must pull down the SDA line during the acknowledge clock
pulse so that it remains stable LOW during the HIGH period of this clock
pulse .