582
/
838
Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
entering the shutdown mode (or turn off the SPI module clock).
21.3.5
SPI communication using DMA
Users can choose DMA for SPI data transfer, the application program can be released, and the system efficiency can
be greatly improved.
When the send buffer DMA is enabled (SPI_CTRL2.TDMAEN = 1), each time the TE flag (SPI_STS.TE) bit is 1, a
DMA request will be generated, and the DMA will automatically write the data to the SPI_DAT register, which will
clear the TE flag (SPI_STS.TE) bit. When the receive buffer DMA is enabled (SPI_CTRL2.RDMAEN = 1), each
time the RNE flag (SPI_STS.RNE) bit is set to 1, a DMA request will be generated, and the DMA will automatically
read the SPI_DAT register, which will clear the RNE flag (SPI_STS.RNE) bit.
When the SPI is only used for sending data, only the send DMA channel of the SPI needs to be enabled
(SPI_CTRL2.TDMAEN = 1).
When the SPI is only used for receiving data, only the receive DMA channel of the SPI needs to be enabled
(SPI_CTRL2.RDMAEN = 1).
In send mode, after DMA has sent all the data to be sent (DMA_INTSTS.TXCF = 1), BUSY flag (SPI_STS.BUSY)
can monitor to confirm whether SPI communication is over, which can avoid destroying the transmission of the last
data when the SPI is turned off or enters the shutdown mode. Therefore, the software needs to wait for the TE flag
(SPI_STS.TE) bit to be set to 1, and wait for the BUSY flag (SPI_STS.BUSY) bit to be set to 0.
Figure 21-11 Transmission using DMA
b0
b2
b1
b3
b4
b6
b5
b0
b7
b1
b2
b3
b5
b4
b6
b7
b1
b0
b3
b2
b4
b5
b7
b6
DATA1=0x11
DATA2=0x22
DATA3=0x33
SCK
MISO/MOSI
(out)
TE flag
Tx buffer
(
write to SPI_DAT
)
BUSY flag
CLKPOL=1.CLKPHA=1
The flag set/clear by hardware
Set by hardware
Clear by DMA
write
Configure the DMA
Tx channel and
enable the SPI
DMA writes 0x11 into
SPI_DAT
DMA tansfer is
complete
Wait TX=1
Wait BUSY=0
0x22
0x33
0x1
1
DMA request
DMA writes to
SPI_DAT
DMA flag
(
DMA transfer complete
)
DMA writes 0x22 into
SPI_DAT
DMA writes 0x33 into
SPI_DAT
Set by hardware
Clear by software