Multimaster

Thread Starter

gogo00

Joined Oct 28, 2023
43
I'm trying to understand how I2C multimaster communication works. When multiple master devices want to talk to a single slave on the I2C bus, how do they decide which one gets to control the bus, and how do the others know the bus is busy? I know that starting communication involves pulling the SDA line low, but I'm looking for an explanation of the process when multiple masters are involved.
 

Ya’akov

Joined Jan 27, 2019
10,226
Welcome to AAC.

What have you read about this so far? What specific questions do you have that literature from manufacturers and the very large number of other sources covering this didn't answer?
 

BobaMosfet

Joined Jul 1, 2009
2,211
Read section

20.4 Multi-master Bus Systems, Arbitration and Synchronization

in the ATMEGA328A datasheet. i2C/TWI is really well explained (all aspects) in this datasheet.
 

Thread Starter

gogo00

Joined Oct 28, 2023
43
I've been looking the I2C standard, and I don't understand description about how multimaster communication works with a slave device. From my research, I understand that once a START condition is successfully initiated, no other device should attempt to access the I2C bus until a STOP condition is issued. Consider the situation where there are three masters, each wanting to communicate with the slave, how do the non-active masters know that the bus is currently in use? It seems that if one of the masters (let's say Master 2) pulls down the SDA line and takes control of the bus, the other masters can monitor the SDA line to see that it's low. This would signal to them that the bus is currently in use, and they should wait because Master 2 has already pulled down the SDA line. Is my understanding correct?
 

Ya’akov

Joined Jan 27, 2019
10,226
When a master pulls SDA low, and sends a START, it is a signal that all slaves on the bus must listen for their addresses. When a master is not in the state of controlling the bus, it is a slave, and it does the same. If the master's address is not specified, it must wait for a STOP before attempting to use the bus.

If there is a collision—that is, two masters try to write to a slave at exactly the same time, it is detected by the masters because they monitor the data lines to ensure they are in the state that represents the data they are trying to send. If the bits being sent match each other, the data is valid in any case, but if a master is trying to send a 1 and the bus stays LOW, it indicates that it are not controlling the bus and so it backs off and must wait for a STOP before retrying.

The signal is arbitration lost.
 

Thread Starter

gogo00

Joined Oct 28, 2023
43
I appreciate your explanation, but I'm still trying to understand how the decision is made regarding which master gets to control the bus and how the others know when the bus is busy. I understand the rule that once a START condition is initiated, no other device should attempt to access the I2C bus until a STOP condition is issued.

However, in a scenario with three masters trying for communication with the slave, I'm interested about how the non-active masters determine that the bus is currently in use. I think that if one of the master, like Master 2, pulls down the SDA line to take control of the bus, the other masters can monitor the SDA line to see that it's low. Does this signal to them that the bus is in use, prompting them to wait because Master 2 has already pulled down the SDA line? Is my understanding correctly
 

WBahn

Joined Mar 31, 2012
32,783
The section on arbitration goes through this.

No device on the bus can force one of the lines to go HI. All it can do is either actively pull it LO, or release it and less the passive pullup pull the line HI. So the only way that the line can be HI is if NO device is pulling it LO. So each decide is required to monitor the state of the line, particularly when it is wanting the line to be HI. If the line actually is HI, then it assumes, for the moment, that it has control of the bus and continues. But as soon as it releases the line with the intend of letting it be pulled HI and it senses that the line is actually LO, it knows that at least one other device is trying to control the bus and that it won this round. So the device that lost is required to immediately cease attempts to drive the line and to let the other device (or devices) continue. If you had, say, six devices trying to drive the line, then each bit when they are not all trying to make the line the same, the ones that are trying to take it LO win and continue, while the others shut up. The fact that, up to this point, multiple devices were controlling the line is irrelevant because, up to that point, they were all saying the same thing.
 
Top