42.7.3.8.2 Data Receive with the DMA in Host Mode

The DMA transfer size must be defined with the buffer size -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, buffer size -2, and so on).
  2. Configure the Host mode (DADR, CKDIV, MREAD = 1, and so on) or Client mode.
  3. Enable the DMA.
  4. Write TWIHS_CR.START to start the transfer (Host only).
  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. Wait for the TXCOMP flag to be raised in TWIHS_SR (only if peripheral clock must be disabled).