What is I2C? How does it work? // Technology

Bus arbitration

Bus arbitration is fairly basic, but works well. Every master device on the bus will monitor the SDA line even whilst sending.
The first to pull the SDA line low indicating a start sequence will win the arbitration.
In the, unusual but possible, event of two masters transmitting data at exactly the same time as in this scenario,
the master that detects a difference on the bus will back off and become a slave until a stop sequence is seen from the other master.
Another way of looking at it is; the master that wanted SDA high, but was pulled low by another master will lose. So bus arbitration extends for the duration of the interaction not just the beginning.

Note that slaves can transmit on the bus but will always be clocked by a master and don’t possess the same bus arbitration that exists on a master.

Masters can actually “claim the bus” by not sending a stop sequence, but instead continuing on talking to as many slaves as it wants to.

Clock stretching

When a slave is sending data to the master, it is the master that controls the clock, but sometimes the slave isn’t ready to send data back to the master. If this happens the slave can pull down the SCL line, at which point the master will detect this change and will not take any action until the slave releases SCL.
This is called clock stretching and is a primitive form of flow control.