TWI as Host or Client
The automatic reversal from host to client is not supported in case of a lost arbitration.
Then, in the case where TWI may be either a host or a client, the user must manage the pseudo Multi-Host mode described in the steps below:
- Program the TWI in Client mode (SADR + MSDIS + SVEN) and perform a client access (if TWI is addressed).
- If the TWI has to be set to Host mode, wait until TXCOMP flag is at 1.
- Program Host mode (DADR + SVDIS + MSEN) and start the transfer (ex: START + Write in THR).
- As soon as Host mode is enabled, the TWI scans the bus in order to detect if it is busy or free. When the bus is considered as free, the TWI initiates the transfer.
- 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.
- If the arbitration is lost (ARBLST is = 1), the user must program the TWI in Client mode in case the host that won the arbitration needs to access the TWI.
- If the TWI has to be set to Client mode, wait until TXCOMP flag
is at 1 and then program Client mode.Note: In case the arbitration is lost and the TWI is addressed, the TWI will not acknowledge even if it is programmed in Client mode as soon as ARBLST = 1. Then the host must repeat SADR.
The flowchart shown in the following figure gives an example of read and write operations in Multi-Host mode.