
GD32F403xx User Manual
469
Quad-SPI mode
Before leaving quad wire mode or disabling SPI, software should first check that, TBE bit is
set and TRANS bit is cleared, then the QMOD bit in SPI_QCTL register and SPIEN bit in
SPI_CTL0 register are cleared.
19.3.6.
DMA function
The DMA function frees the application from data writing and reading process during transfer,
thus improve the system efficiency.
DMA function in SPI is enabled by setting DMATEN and DMAREN bits in SPI_CTL1 register.
To use DMA function, application should first correctly configure DMA modules, then configure
SPI module according to the initialization sequence, at last enable SPI.
After being enabled, If DMATEN is set, SPI will generate a DMA request each time TBE=1,
then DMA will acknowledge to this request and write data into the SPI_DATA register
automatically. If DMAREN is set, SPI will generate a DMA request each time RBNE=1, then
DMA will acknowledge to this request and read data from the SPI_DATA register automatically.
19.3.7.
CRC function
There are two CRC calculators in SPI: one for transmission and the other for reception. The
CRC calculation uses the polynomial in SPI_CRCPOLY register.
Application can switch on the CRC function by setting CRCEN bit in SPI_CTL0 register. The
CRC calculators continuously calculate CRC for each bit transmitted and received on lines,
and the calculated CRC values can be read from SPI_TCRC and SPI_RCRC register.
To transmit the calculated CRC value, application should set the CRCNT bit in SPI_CTL0
register after the last data is written to the transmit buffer. In full-duplex mode (MFD or SFD)
the SPI treats the incoming data as a CRC value when it transmits a CRC and will check the
received 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.
If DMA function is enabled, application doesn’t need to operate CRCNT bit and hardware will
automatically process the CRC transmitting and checking.
19.3.8.
SPI interrupts
Status flags
◼
Transmit buffer empty flag (TBE)
This bit is set when the transmit buffer is empty, the software can write the next data to the
transmit buffer by writing the SPI_DATA register.
◼
Receive buffer not empty flag (RBNE)