AT32F421
Series Reference Manual
2022.11.11
Page 153
Rev 2.02
CRC calculation polynomial is configured by setting the SPI_CPOLY register.
CRC enable: The CRC calculation is enabled by setting the CCEN bit. This operation will reset
the SPI_RCRC and SPI_TCRC registers.
Select if or when the NTC bit is set, depending on DMA or CPU data register. See the following
descriptions.
Transmission using DMA
When DMA is used to write the data to be transmitted, if the CCEN bit is enabled, the hardware calculates
the CRC value automatically according to the value in the SPI_CPOLY register and each transmitted
data, and sends the CRC value at the end of the last data transmission. This result is regarded as the
value of the SPI_TCRC register.
Reception using DMA
When DMA is used to read the data to be received, if the CCEN bit is enabled, the hardware calculates
the CRC value automatically according to the value in the SPI_CPOLY register and each received data,
and waits until the completion of CRC data reception at the end of the last data reception before
comparing the received CRC value with the value of the SPI_RCRC register. If check error occurs, the
CCERR flag is set. An interrupt is generated if the ERRIE bit is enabled.
Transmission using CPU
Unlike DMA mode, after writing the last data to be transmitted, the CPU mode requires the NTC bit to
be set by software before the end of the last data transmission.
Reception using CPU
In two-wire unidirectional full-duplex mode, follow CPU transmission mode to operate the NTC bit, the
CRC calculation and check in CPU reception mode will be completed automatically.
In single-wire unidirectional reception-only mode and single-wire bidirectional reception-only mode, it is
required to set the NTC bit before the software receives the last data when the second-to-last data is
received.
13.2.6 DMA transfer
The SPI supports write and read operations with DMA. Refer to the following configuration procedure.
Special attention should be paid to: when the CRC calculation and check is enabled, the number of
data transferred by DMA is configured as the number of the data to be transferred. The number of data
read with DMA is configured as the number of the data to be received. In this case, the hardware will
send CRC automatically at the end of full transfer, and the receiver will also perform CRC check. Note
that the received CRC data will be moved into the SPI_DT register by hardware, with the RDBF being
set, and the DMA read request will be sent if then DAM transfer is enabled. Hence, it is recommended
to read the SPI_DT register to get the CRC value at the end of CRC reception in order to avoid the
upcoming transfer error.
Transmission with DMA
Select DMA channel: Select a DMA channel for the current SPI from DMA channel map table
described in DMA chapter.
Configure the destination of DMA transfer: Configure the SPI_DT register address as the
destination address bit of DMA transfer in the DMA control register. Data will be sent to this
address after transmit request is received by DMA.
Configure the source of DMA transfer: Configure the memory address as the source of DMA
transfer in the DMA control register. Data will be loaded into the SPI_DT register from the
memory address after transmit request is received by DMA.
Configure the total number of bytes to be transferred in the DMA control register.
Configure the channel priority of DMA transfer in the DMA control register.
Configure DMA interrupt generation after half or full transfer in the DMA control register.
Enable DMA transfer channel in the DMA control register.
Reception with DMA
Select DMA transfer channel: Select a DMA channel for the current SPI from DMA channel map
table described in DMA chapter.