45.6.3.9.2 Data Receive 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 2. The two remaining characters must be managed without DMA to ensure that the exact number of bytes are received regardless of system bus latency conditions encountered during the end of buffer transfer period.

  1. Initialize the DMA (channels, memory pointers, size - 2, etc.);
  2. Configure the Host mode (DADR, CKDIV, MREAD = 1, etc.) or Client mode.
  3. Enable the DMA.
  4. (Host Only) Write TWIHS_CR.START to start the transfer.
  5. Wait for the DMA status flag indicating that the buffer transfer is complete.
  6. Disable the DMA.
  7. Wait for the RXRDY flag in the TWIHS_SR.
  8. Set TWIHS_CR.STOP.
  9. Read the penultimate character in TWIHS_RHR.
  10. Wait for the RXRDY flag in the TWIHS_SR.
  11. Read the last character in TWIHS_RHR.
  12. (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’):

  1. Initialize the transmit DMA (memory pointers, transfer size).
  2. Configure the Host mode (DADR, CKDIV, etc.) and TWIHS_ACR.
  3. Set the DMA RXTEN bit.
  4. (Host Only) Write TWIHS_CR.START to start the transfer.
  5. Wait for the DMA ENDTX Flag either by using the polling method or ENDTX interrupt.
  6. Disable the DMA by setting the DMA TXTDIS bit.
  7. (Only if peripheral clock must be disabled) Wait for the TXCOMP flag to be raised in TWIHS_SR.