45.6.3.9.1 Data Transmit with the DMA in Host Mode
If Alternative Command mode is disabled (ACMEN bit set to ‘0’):
The DMA transfer size must be defined with the buffer size minus 1. The remaining character must be managed without DMA to ensure that the exact number of bytes are transmitted regardless of system bus latency conditions during the end of the buffer transfer period.
- Initialize the DMA (channels, memory pointers, size - 1, etc.);
- Configure the Host mode (DADR, CKDIV, MREAD = 0, etc.) or Client mode.
- Enable the DMA.
- Wait for the DMA status flag indicating that the buffer transfer is complete.
- Disable the DMA.
- Wait for the TXRDY flag in TWIHS_SR.
- Set TWIHS_CR.STOP.
- Write the last character in TWIHS_THR.
- (Only if peripheral clock must be disabled) Wait for the TXCOMP flag to be raised in TWIHS_SR.
If Alternative Command mode is enabled (ACMEN bit set to ‘1’):
- Initialize the transmit DMA (memory pointers, transfer size).
- Configure the Host mode (DADR, CKDIV, etc.) and TWIHS_ACR.
- Start the transfer by setting the DMA TXTEN bit.
- Wait for the DMA ENDTX flag either by using the polling method or ENDTX interrupt.
- Disable the DMA by setting the DMA TXTDIS bit.
- (Only if peripheral clock must be disabled) Wait for the TXCOMP flag to be raised in TWIHS_SR.