In this lesson, you will learn how to design logic that allows multiple bus masters to transmit simultaneously without corrupting data by detecting mismatches during the address phase.
The Challenge of Multiple Masters
When two or more masters attempt to control the bus at the same time, we encounter bus contention. If one master tries to drive a signal high while another drives it low, we create a short circuit or "garbled" data. In protocols like I2C, this is managed through multi-master arbitration.
Designing Arbitration Logic
The core strategy is "listen while you talk." Because I2C uses open-drain signaling (where a low signal physically overrides a high signal), a master can detect if it has "lost" the arbitration by comparing the state of the bus to the data it intended to send.
If Master A sends a 1 (releasing the line) but observes a 0 on the bus, it knows that Master B is currently sending a 0. Because Master B is asserting a logic low, it has "won" the contention, and Master A must immediately stop transmitting to prevent a collision.
Conceptual Implementation
You can implement this in your bus controller by checking the signal level at each bit transmission during the address phase:
// Pseudo-code for arbitration check during address phase
void transmit_bit(uint8_t bit) {
write_bus(bit); // Drive the bus with the bit
wait_for_sync(); // Allow signal to stabilize
uint8_t bus_state = read_bus(); // Observe what is actually on the wire
// If we sent a '1' (high) but read a '0' (low), we lost arbitration
if (bit == 1 && bus_state == 0) {
handle_arbitration_loss(); // Disable transmitter, enter slave mode
}
}
This logic ensures that if multiple masters start transmitting simultaneously, the master sending the lowest value (the most dominant signal) wins the right to control the bus, while all other masters gracefully back off. This prevents data corruption during the critical address phase, ensuring that only one master successfully completes its transaction while the others wait for the bus to become free again.
Key Takeaway: Arbitration is achieved by constantly comparing the transmitted signal against the actual state of the physical bus; if a mismatch occurs, the losing master must cease transmission immediately to prevent bus contention.