General protocol
The I2C protocol is more elaborated than the serial communication protocol because it has to support communication between several devices. Let's see how it works using examples:
Master -> Slave
If the master wants to send data to the slave:
- Master: Broadcast START
- M: Broadcast slave address (7 bits) + the R/W (8th) bit set to WRITE
- Slave: Responds ACK (ACKnowledgement)
- M: Send one byte
- S: Responds ACK
- Repeat steps 4 and 5 zero or more times
- M: Broadcast STOP OR (broadcast RESTART and go back to (2))
NOTE The slave address could have been 10 bits instead of 7 bits long. Nothing else would have changed.
Master <- Slave
If the master wants to read data from the slave:
- M: Broadcast START
- M: Broadcast slave address (7 bits) + the R/W (8th) bit set to READ
- S: Responds with ACK
- S: Send byte
- M: Responds with ACK
- Repeat steps 4 and 5 zero or more times
- M: Broadcast STOP OR (broadcast RESTART and go back to (2))
NOTE The slave address could have been 10 bits instead of 7 bits long. Nothing else would have changed.