I2C Frame Format
An I2C transaction is made from a sequence of protocol fields. The exact sequence depends on whether the controller is writing to a target, reading from a target, or performing a register-based access.
The basic frame contains:
- START condition
- Target address
- Read/write bit
- ACK/NACK bit
- Data byte or bytes
- ACK/NACK after each byte
- STOP condition
START condition
A START condition marks the beginning of an I2C transaction.
When target devices detect a START condition, they start listening for an address.
Target address
After START, the controller sends the target address. The most common format uses a 7-bit address. The address is followed by one read/write bit.
For example, if a device has 7-bit address 0x50, the controller sends:
- 0xA0 for write, because (0x50 << 1) | 0 = 0xA0
- 0xA1 for read, because (0x50 << 1) | 1 = 0xA1
This is why datasheets sometimes create confusion between 7-bit addresses and 8-bit address bytes. The 7-bit address is the device address. The 8-bit value includes the read/write bit.
I2C also supports 10-bit addressing, but 7-bit addressing is more common in many embedded systems.
Read/write bit
The read/write bit tells the target the direction of transfer.
| R/W bit | Operation | Direction |
|---|---|---|
| 0 | Write | Controller sends data to target |
| 1 | Read | Target sends data to controller |
ACK and NACK bit
After every address byte and data byte, the receiver sends an acknowledgement bit.
- ACK: Receiver pulls SDA LOW during the acknowledge clock pulse.
- NACK: Receiver leaves SDA HIGH during the acknowledge clock pulse.
ACK means the receiver accepted the byte. NACK means the byte was not accepted, the target is unavailable, or the receiver wants to end the transfer.
For a write transfer, the target ACKs each received byte.
For a read transfer, the controller ACKs bytes it wants to continue reading and NACKs the last byte to indicate the read is complete.
Data byte
Data is transferred 8 bits at a time, most significant bit first.
Each byte is followed by an ACK/NACK bit. There is no fixed limit in the protocol for the number of bytes in a transfer, but devices define their own behavior.
STOP condition
A STOP condition marks the end of a transaction.
After STOP, the bus becomes idle if both SDA and SCL are HIGH.
Repeated START condition
A repeated START is a START condition sent without first sending a STOP. It allows the controller to change direction or address another target while keeping control of the bus.
Repeated START is commonly used in register-based read operations:
- Controller writes the register address.
- Controller sends repeated START.
- Controller reads data from that register.
I2C Protocol