Saturday, 5 May 2012

Understanding I2C - Part 3

Beginners need to know that I2C is a simple synchronous serial communication protocol.


I2C routing/external cable distance:
If you are routing I2C lines on PCB or using external cables, we have to keep in mind the maximum distance to which it can be done. Generally, without considering any factors, the length can be 9-12 feet. But length depends on following factors:
1.    Speed
2.    Load (capacitance)
3.    Source for pull-up

The distance can be increased by using a active current source instead of simple pull-up resistor. This is what is used in current amplifiers used as I2C repeater. For the same capacitance, I2C lines with repeater can be routed over longer distance than I2C lines with no repeater.

General Call in I2C:

In some cases, it is required that master need to communicate with all slaves at a time. In that case, Master has an option of sending “0000 0000” as address. This is called general call to which all the slaves will respond.


Multi Master Configuration:
Consider an application which demands two microcontrollers and ‘N’ number of sensors. This is a multi master application and clock need to be controlled carefully by either of the master. In this case, masters need to deal with Arbitration and Clock synchronization. Arbitration is like masters fighting for bus and one of them getting control at a specific time. Clock synchronization is like different masters may use different clocks and this can be differentiating factor in the case of slaves deciding which master has initiated the transaction. In case, a master doesn’t want to lose control of the bus, it may send repeated start bit in place of stop bit. This helps the master keep control of the bus. We need to remember that when a “START” signal is sent from Master to slave, the internal logic of slave is set to specific state. SCL need not ne bi-directional but in multi-master mode, the SCL needs to be bi-directional.
Genuine I2C routine:
DATA = 1;
CLK = 1; // initially CLK and DATA are high
Delay(n);
DATA = 0; // data made low from high to indicate START
Delay(n);
CLK = 0; // clock made low and in this state data bit can be put on the bus
Delay(n);
DATA = 0 or 1; // as, clock is made low, we are sending data byte
Delay(n);
CLK = 1; // Now clock is high and bit is freezed

Note: ‘n’ in delay function depends on clock cycle.

No comments:

Post a Comment