For more content, you can join the Linux System Knowledge Base package (tutorials + videos + Q&A):Linux System Knowledge Base Package
Table of Contents
-
1. I2C Frame Format
-
1.1 Start and Stop Conditions
-
1.2 Addressing
-
1.3 Read/Write Bit
-
1.4 Data Frame
-
2. Transmission Steps
-
3. Advantages and Disadvantages
-
3.1 Advantages
-
3.3 Disadvantages
Consolidate, share, and grow, so that both you and others can gain something! š
š¢<span>I2C</span>
bus is a simple, bidirectional, two-wire synchronous serial bus developed by<span>Philips</span>
. It requires only two wires to transmit information. It combines the advantages of <span>SPI</span>
and <span>UART</span>
, allowing you to connect multiple slaves to a single master (like<span>SPI</span>
), and also enabling multiple masters to control one or more slaves.
1. I2C Frame Format
<span>I2C</span>
data transmission occurs in the form of multiple<span>msg</span>
, each<span>msg</span>
contains the binary address frame of the slave, as well as one or more data frames, including start and stop conditions, read/write bit, and the<span>ACK</span>
/<span>NACK</span>
bits between the data frames:
-
Start Condition (
<span>Start Condition</span>
): When<span>SCL</span>
is high, the<span>SDA</span>
line switches from high to low. -
Address Frame (
<span>Address Frame</span>
): A unique 7-bit or 10-bit sequence for each slave device used for address recognition between master and slave devices. -
Read/Write Bit (
<span>Read/Write Bit</span>
): A bit; if the master is sending data to the slave, it is low; if requesting data, it is high. -
<span>ACK/NACK</span>
: Each frame in the message is followed by an<span>ACK/NACK</span>
bit. If the address frame or data frame is successfully received, the receiving device will return an<span>ACK</span>
bit to indicate acknowledgment. -
Stop Condition (
<span>Stop Condition</span>
): When<span>SCL</span>
is high, the<span>SDA</span>
line switches from low to high.
1.1 Start and Stop Conditions
1.2 Addressing
Since<span>I2C</span>
does not have a chip select line like<span>SPI</span>
, it needs to use another method to confirm a specific slave device, which is addressing. The master sends the address of the slave it wants to communicate with to each slave, and then each slave compares it with its own address. If the address matches, it will send a low<span>ACK</span>
bit back to the master. If it does not match, no action is taken, and the<span>SDA</span>
line remains high.
Because<span>I2C</span>
uses addressing, multiple slaves can be controlled by one master. When using a<span>7</span>
-bit address, up to<span>128</span>
(<span>27</span>
) unique addresses can be used.
1.3 Read/Write Bit
The end of the address frame contains a read/write bit. If the master is sending data to the slave, it is low. If the master is requesting data from the slave, it is high.
1.4 Data Frame
When the master detects the<span>ACK</span>
bit from the slave, it can send the first data frame. The data frame is always<span>8</span>
bits long, and each data frame is followed by an<span>ACK/NACK</span>
bit to verify the reception status. After sending all data frames, the master can send a stop condition to terminate communication with the slave.
2. Transmission Steps
-
When the
<span>SCL</span>
line is high, the master starts bus communication by switching the<span>SDA</span>
line from high to low. -
The master sends the
<span>7</span>
-bit or<span>10</span>
-bit address of the slave it wants to communicate with, along with the read/write bit: -
Each slave compares the address sent by the master with its own address. If the address matches, the slave returns a low
<span>ACK</span>
bit by pulling the<span>SDA</span>
line low. If the master’s address does not match the slave’s address, the slave pulls the<span>SDA</span>
line high. -
The master sends or receives data frames:
-
After each data frame is transmitted, the receiving device returns another
<span>ACK</span>
bit to the sender to confirm that the frame has been successfully received:
3. Advantages and Disadvantages
3.1 Advantages
-
Uses only two wires
-
Supports multiple masters and multiple slaves
-
The baud rate of each
<span>UART</span>
must be within<span>10%</span>
of each other -
Hardware is simpler than
<span>UART</span>
-
Well-known and widely used protocol
3.3 Disadvantages
-
Data transmission rate is slower than
<span>SPI</span>
-
Data frame size is limited to
<span>8</span>
bits