I2C is a bus structure. One master, one or more slave,
Each slave device is differentiated by a 7-bit address. The address is followed by one read/write bit, which indicates reading (= 1) or writing (= 0). Therefore, sometimes we can see an 8-bit device address, at this time, each device has two read and write addresses, and the seven-bit high address is actually the same.
The I2C data format is as follows:
No dataSCL = 1, SDA = 1;
Start bit(Start): SDA changes from 1 to 0 when the SCL is 1;
Stop bit(STOP): SDA changes from 0 to 1 when the SCL is 1;
Data bit: When the check box changes from 0 to 1, the sender controls the SDA. In this case, the SDA is valid data and cannot be changed randomly. When the check box is set to 0, data on SDA can be changed at will;
Address bit: Defines the same data bit, but only the master sends it to slave;
Response bit(ACK): When the sender sends 8 bits, the sender releases the SDA, which is controlled by the receiver and SDA = 0;
No response bit(NACK): When the sender sends 8 bits, the sender releases the SDA, which is controlled by the receiver and SDA = 1.
When data is transmitted in a single byte, Format:
Start bit, 8-bit address bit (including 1-bit read/write bit), response, 8-bit data, response, stop bit.
When data is transmitted as a string of bytes, Format:
Start bit, 8-bit address bit (including 1-bit read/write bit), response, 8-bit data, response, 8-bit data, response ,......, 8-bit data, response, and stop bit.
Note that:
1, The SCL is always controlled by the master. , SDA follows the data transmission direction, Slave controls SDA when reading data , SDA is controlled by the master when writing data. . After the eight-bit data is transferred, the SDA control of the response bit or no response bit is opposite to that of the Data bit transfer.
2, The Start bit "start" and stop bit "stop" can only be issued by the master .
3, After the 8-bit address is transferred, the slave device with the address configured must send "Ack" . Otherwise, after a certain period of time, the master will be deemed as timeout, and data transmission will be abandoned and "stop" will be sent ".
4, When writing data , The master sends 8 data bits each time, If the slave device still has space to accept the next byte, the answer should be "Ack". If the slave device does not have space to accept more bytes, the answer should be "Nack" When the master receives "Nack" or does not receive any data after a certain period of time, it will be deemed as timeout. At this time, the master disconnects data transmission and sends "stop ".
5, When reading data The slave device sends 8 data bits each time, If the master wants to continue reading the next byte, the master should answer "Ack" to prompt slave to prepare the next data. If the master does not want to read more bytes, the master should answer "Nack" to prompt the slave device to receive the stop signal. .
6, When the master node is too fast and the slave end is too late to handle the problem, the slave device can lower the SCL and not put it. ("Line and" will occur when the SCL = 0) to prevent the master from sending more data. In this case, the master will slow down or stop data transmission as needed.