691
SAM4CP [DATASHEET]
43051E–ATPL–08/14
34.7.4 Multi-master Mode
34.7.4.1 Definition
In multi-master mode, more than one master may handle the bus at the same time without data corruption by using
arbitration.
Arbitration starts as soon as two or more masters place information on the bus at the same time, and stops (arbitration is
lost) for the master that intends to send a logical one while the other master sends a logical zero.
As soon as arbitration is lost by a master, it stops sending data and listens to the bus in order to detect a stop. When the
stop is detected, the master that has lost arbitration may put its data on the bus by respecting arbitration.
Arbitration is illustrated in
Figure 34-23 on page 692
.
34.7.4.2 Different Multi-master Modes
Two multi-master modes may be distinguished:
1.
TWI is considered as a Master only and will never be addressed.
2.
TWI may be either a Master or a Slave and may be addressed.
Note:
Arbitration is supported in both multi-master modes.
TWI as Master Only
In this mode, TWI is considered as a Master only (MSEN is always at one) and must be driven like a Master with the
ARBLST (Arbitration Lost) flag in addition.
If arbitration is lost (ARBLST = 1), the user must reinitiate the data transfer.
If the user starts a transfer (ex.: DADR + START + W + Write in THR) and if the bus is busy, the TWI automatically waits
for a STOP condition on the bus to initiate the transfer (see
Figure 34-22 on page 692
).
Note:
The state of the bus (busy or free) is not indicated in the user interface.
TWI as Master or Slave
The automatic reversal from Master to Slave is not supported in case of a lost arbitration.
Then, in the case where TWI may be either a Master or a Slave, the user must manage the pseudo Multi-master mode
described in the steps below.
1.
Program TWI in Slave mode (SADR + MSDIS + SVEN) and perform a Slave Access (if TWI is addressed).
2.
If the TWI has to be set in Master mode, wait until TXCOMP flag is at 1.
3.
Program the Master mode (DADR + SVDIS + MSEN) and start the transfer (ex: START + Write in THR).
4.
As soon as the Master mode is enabled, TWI scans the bus in order to detect if it is busy or free. When the bus is
considered free, TWI initiates the transfer.
5.
As soon as the transfer is initiated and until a STOP condition is sent, the arbitration becomes relevant and the
user must monitor the ARBLST flag.
6.
If the arbitration is lost (ARBLST is set to 1), the user must program the TWI in Slave mode in case the Master that
won the arbitration wants to access the TWI.
7.
If the TWI has to be set in Slave mode, wait until TXCOMP flag is at 1 and then program the Slave mode.
Note:
If the arbitration is lost and the TWI is addressed, the TWI will not acknowledge even if it is programmed in Slave
mode as soon as ARBLST is set to 1. Then, the Master must repeat SADR.