Search code examples
embeddedi2cfirmware

How to know if I2C bus is busy in Multi master environment?


Assuming an I2C network with multiple masters connected and some slaves. A master is already communicating with an particular slave. Now if the other master wants to initiate communication by sending some slave address in bus., then how would the new master come to know that the bus is already busy and it should wait until it gets freed up?


Solution

  • All the devices (both masters and slaves) would track the state of the bus.

    As soon as the Start condition is found, the bus is considered busy until the Stop is received. Which master exactly owns the bus is decided with the bus arbitration.

    The master that had lost the arbitration would report the loss of arbitration (through some flags in register) and will wait until Stop condition found.

    If master didn't initiate the transaction, it will report the bus is busy with some other flag, and will continue tracking the state of the bus to detect the Stop condition.

    There's no way to tell if the bus is free by sampling a bus lines just once. Yes, if you see some line has 0, that definitely means that the bus is busy, but when you see both lines as 1, that doesn't mean that the bus is free yet. All the devices must track the bus state changes to detect Start/Stop conditions.