Detailed Interface Descriptions
I2C (Inter-Integrated Circuit) is a synchronous, half-duplex, serial communication bus that is commonly used for issuing instructions and establishing handshakes. It can also be used to transfer data, but it is typically used for slow output data devices such as sensors.
Supports multiple master and slave devices on one I2C bus.
Half-duplex: Data can be transmitted or received, but not both at the same time.
Slow data rate: Typical data rates are 100 kHz to 400 kHz.
Open-drain output: The output drivers of I2C devices are open-drain, which means that they can only pull the bus line low. This allows multiple devices to share the same bus without conflict.
I2C communication is based on a simple protocol that consists of four types of messages:
Start bit: This bit signals the beginning of a message.
Slave address: This bit indicates the address of the slave device that the message is intended for.
Command/data: This bit indicates whether the message is a command or data.
Stop bit: This bit signals the end of a message.
I2C devices are addressed using a 7-bit address. This allows for 128 (2^7) unique slave addresses. However, in practice, it is not practical to have all 128 addresses on one bus due to limited bus bandwidth.
Each I2C message consists of an 8-bit packet frame. The packet frame is structured as follows:
Start bit (1 bit)
Slave address (7 bits)
R/W bit (1 bit)
Data byte (8 bits)
Stop bit (1 bit)
If two master devices attempt to access the bus at the same time, a process called arbitration is used to determine which device will have control of the bus. Arbitration is based on the principle of "first come, first served."
If a slave device needs more time to process the current data before the next data frame is transferred, it can stretch the clock. Clock stretching is done by the slave device holding the clock line low until it is ready to continue.
Helpful Software Debug Tools
There are a number of software tools that can be used to debug I2C communication. One popular tool is the i2c-tools package, which is available for Linux. This package provides a number of commands that can be used to read and write data on the I2C bus, as well as to query the status of the bus.
A I2C logic analyzer can be used to sniff, read, and write on I2C bus. Two popular logic analyzers are the Salae logic analyzer and the Aardvark I2C/SPI Host Adapter. These logic analyzers come with their own analysis software that can be used to view and analyze I2C traffic.