
AT32F413
Series Reference Manual
2022.06.27
Page 131
Rev 2.00
stage at this time.
7.
EV3: RDBF=1. Reading the I2C_DT register clears the RDBF.
8.
End of communication.
11.4.3 Utilize DMA for data transfer
I
2
C data transfer can be done using DMA controller. An interrupt is generated by enabling the transfer
complete interrupt bit. The DATAIEN bit in the I2C_CTRL2 register must be set 0 when using DMA for
data transfer. The following sequence is for data transfer with DMA.
Transmission using DMA
1.
Set the peripheral address (DMA_CxPADDR=
I2C_D
T address)
2.
Set the memory address (DMA_CxMADDR=data memory address)
3.
The transmission direction is set from memory to peripheral (DTD=1 in the DMA_CHCTRL
register)
4.
Configure the total number of bytes to be transferred in the DMA_CxDTCNT register
5.
Configure other parameters such as priority, memory data width, peripheral data width,
interrupts, etc in the DMA_CHCTRL register
6.
Enable the DMA channel by setting CHEN=1 in the DMA_CxCTRL register
7.
Enable I
2
C
DMA request by setting DMAEN=1 in the
I2C_CTRL2 register. Once the TDBE
bit in the
I2C_STS1 register is set, the data is loaded from the programmed memory to the
I2C_DT register through DMA
8.
When the number of data transfers, programmed in the DMA controller, is reached
(DMA_CxDTCNT=0), the data transfer is complete (An interrupt is generated if enabled).
9.
Master transmitter: Once the TDC flag is set, the STOP condition is generated, indicating that
transfer is complete.
Slave transmitter: Once the ACKFAIL flag is set, clear the ACKFAIL flag, transfer is complete.
Reception using DMA
1.
Set the peripheral address (DMA_CxPADDR =
I2C_DT address
)
2.
Set the memory address (DMA_CxMADDR = memory address)
3.
The transmission directionis set from peripheral to memory (DTD=0 in the DMA_CHCTRL
register)
4.
Configure the total number of bytes to be transferred in the DMA_CxDTCNT register
5.
Configure other parameters such as priority, memory data width, peripheral data width,
interrupts, etc in the DMA_CHCTRL register
6.
Enable the DMA channel by setting CHEN=1 in the DMA_CxCTRL register
7.
Enable
I
2
C
DMA request by setting DMAEN=1 in the
I2C_CTRL2 register. Once the RDBE
bit in the
I2C_STS1 register is set, the data is loaded from the
I2C_DT register
to the
programmed memory
through DMA
8.
When the number of data transfers, programmed in the DMA controller, is reached
(DMA_CxDTCNT=0), the data transfer is complete (An interrupt is generated if enabled).
9.
Master receiver: Clear the ACKFAIL flag, the STOP condition is generated, indicating that the
transfer is complete (when the number of bytes to be transferred is greater >=2 and
DMAEND=1, the NACK signal is generated automatically after transfer complete
(DMA_CxDTCNT=0))
Slave receiver: Once the STOPF flag is set, clear the STOPF flag, and the transfer is complete.