What is I2C?
I2C stands for inter-integrated circuit. It is used for short distance communication. Bidirectional data transfer between 1 master and multiple slaves. half-duplex communication There are two wires, SCL (serial clock), and SDA (serial data)
Exchanging data
two nodes, like a master and a slave, exchange data using “messages”. In I2C, the idle state of both SDA and SCL is HIGH due to pull-up resistors connecting them to ground when the a line is pulled low.
a message is consisted of the following:
- the start condition occurs when the SDA line switches to LOW (i.e. the circuit closes), and then pulls SCL line to LOW
- this is to “claim” the bus, and reduces the risk of having two nodes try and grab the bus.
- following the start condition, there is a slave address, which is 7 bits long, with the most significant bit first.
- addresses may be hardcoded.
- immediately following the slave address is a read/write operation.
- if the Read/Write bit is 0, the Master wants to write data to the slave
- if the Read/Write bit is 1, the Master wants to read data from the slave
- ACK bit is send by the receiver of a byte of data.
- if the bit is 0, it is interpreted as ACK
- if the bit is 1, it is interpreted as NACK (negative acknowledgement)
- Data byte: which actually contains the information being transferred between the master and slave.
- memory, register contents, adresses, etc
- data is always 8 bits long (1 byte), MSB first.
Multiple Data Bytes
in many cases, multiple data bytes are sent in one I2C frame.
- Each data byte is followed by an ACK bit
An example here, would be that the bytes might not be actual data to be written. It could be that the first byte is a register location and the second byte is the data to be written to that register.
Stop Condition
the stop condition indicates the end of data bytes
- first, SCL returns and remains HIGH
- then, SDA returns and remains HIGH.
Packet Structure
I found the packet structure here
Disadvantages of I2C
- I2C is slower than SPI
- size of data frame is limited to 1 byte
- more complicated hardware needed to implement than SPI