www.geehy.com Page 367
Disable SPI (SPIEN=0)
Clear CRCEN bit
Set CRCEN bit to 1
Enable SPI (SPIEN=1)
DMA function
For high-speed data transmission, the request/response DMA mechanism in
SPI improves the system efficiency and can transfer data to SPI transmit buffer
promptly, and the receive buffer can read the data in time to prevent overflow.
When SPI only transmits data, it is only needed to enable DMA transmission
channel; when SPI only receives data, it is only needed to enable DMA
receiving channel.
DMA function of SPI mode can be enabled by configuring TXDEN and RXDEN
bits of SPI_CTRL2 register.
When transmitting: When TXBEFLG flag bit is set to 1, issue the DMA
request, DMA controller writes data to SPI_DATA register, and then
the TXBEFLG flag bit will be cleared.
When receiving: When setting RXBNEFLG flag bit to 1, issue the
DMA request, DMA controller reads data from SPI_DATA register, and
then RXBNEFLG flag bit is cleared.
By monitoring BSYFLG flag bit, confirm whether SPI communication is over
after DMA has transferred all data to be sent in transmitting mode, which can
avoid damaging the transmission of last data.
DMA function with CRC
By the end of communication, if SPI enables both CRC operation and DMA
function, transmitting and receiving of CRC bytes will be completed
automatically.
At the end of data and CRC transmission, if CRCEFLG flag bit of SPI_STS
register is set to 1, it indicates that an error occurred during transmission.
Disable SPI
After data transmission is over, end the communication by closing SPI module.
In some configurations, if SPI is disabled before data transmission is completed,
data transmission error may be caused. Different methods are required in
different operation modes to close SPI
Maser mode/full-duplex slave mode
Wait until RXBNEFLG flag bit is set to 1, and receive the last data