![GigaDevice Semiconductor GD32E23 Series User Manual Download Page 513](http://html.mh-extra.com/html/gigadevice-semiconductor/gd32e23-series/gd32e23-series_user-manual_2225794513.webp)
GD32E23x User Manual
513
Application can enable the CRC function by setting CRCEN bit in SPI_CTL0 register. The
CRC calculators calculate CRC for each bit transmitted and received on lines continuously,
and the calculated CRC values can be read from SPI_TCRC and SPI_RCRC registers.
To transmit the calculated CRC value, application should set the CRCNT bit in SPI_CTL0
register after the last data is written to the transmission buffer/TXFIFO. In full-duplex mode
(MFD or SFD), when the SPI transmits a CRC and prepares to check the received CRC
value, the SPI treats the incoming data as a CRC value. In reception mode (MRB, MRU,
SRU and SRB), the application should set the CRCNT bit after the second last data frame is
received. When CRC checking fails, the CRCERR flag will be set.
For SPI0, if the data length is 8-bit, the CRC calculation is based on the CRC8 standard. If i
the data length is 16-bit, the CRC calculation is based on the CRC16 standard. If the DMA
function is enabled, the software does not need to set the CRCNT bit, and the hardware will
handle the CRC transmission and verification automatically.
For SPI1, only when the data length is 8-bit or 16-bit, SPI provides CRC calculation function,
and independent of the data length, it can be fixedly set to 8-bit or 16-bit CRC calculation.
For all other data lengths, CRC function is invalid. CRC data exchange usually requires one
or more data communication time after the end of the data sequence. For example, when
setting the data length to 8 bits and doing a 16-bit CRC check, it takes two frames to send
the complete CRC data. If the DMA function is enabled, the hardware will handle the CRC
transmission and verification automatically, but the SPI needs to set the counter value of the
DMA transmitting channel and the receiving channel. The transmitting DMA counter value is
the number of data frames that do not include the CRC frame. The configuration of receiving
the DMA counter value is as follows:
1. Full duplex mode: Suppose the amount of data received by SPI is L, when CRCL = 0 and
DZ = 8, then the count of the DMA receive channel is L + 1, otherwise the count of the DMA
receive channel is L + 2.
2. Receive only mode: DMA receive channel count is only equal to the amount of data
received .After receiving data, the CRC value is obtained by reading SPI_RCRC register by
software.
Note:
When SPI is in slave mode and CRC function is enable, the CRC calculator is
sensitive to input SCK clock whether SPI is enable or not. The software must enable CRC
only when the clock is stable to avoid wrong CRC calculation. And when SPI works as a
slave, the NSS internal signal needs to be kept low between the data phase and CRC phase.
18.3.9.
SPI interrupts
Status flags
Transmission buffer/TXFIFO empty flag (TBE)
This bit is set when the transmission buffer is empty or the TXFIFO level is lower or equal to