575
/
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
order and then loaded into the SPI_DAT register in parallel. The software operation process is as follows:
1.
Set SPI_CTRL1.SPIEN = 1, Enable SPI module.
2.
Write the first data to be sent into SPI_DAT register (this operation will clear SPI_STS.TE bit).
3.
Wait for SPI_STS.TE bit to be set to '1', and write the second data to be sent into SPI_DAT. Wait for
SPI_STS.RNE bit to be set to '1', read SPI_DAT to get the first received data, and the SPI_STS.RNE bit will be
cleared by hardware while reading SPI_DAT. Repeat the above operation, sending subsequent data and
receiving n-1 data at the same time;
4.
Wait for SPI_STS.RNE bit to be set to '1' to receive the last data;
5.
Wait for SPI_STS.TE to be set to '1', then wait for SPI_STS.BUSY bit to be cleared and turn off SPI module.
The process of data sending and data receiving can also be implemented in the interrupt handler generated by the
rising edge of the SPI_STS.RNE or SPI_STS.TE flag.
Figure 21-5 Schematic diagram of the change of TE/RNE/BUSY when the host is continuously transmitting in full duplex mode
Master two-wire one-way send-only mode (SPI_CTRL1.MSEL = 1, SPI_CTRL1.BIDIRMODE = 0,
SPI_CTRL1.RONLY = 0)
Master two-wire one-way send-only mode is similar to master full-duplex mode. The difference is that this mode will
not read the received data, so the SPI_STS.OVER bit will be set to '1', and the software will ignore it. The software
operation process is as follows:
1.
Set SPI_CTRL1.SPIEN = 1, Enable SPI module.
2.
Write the first data to be sent into SPI_DAT register (this operation will clear SPI_STS.TE bit).
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
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=0xAA
DATA2=0xBB
DATA3=0xCC
SCK
MISO/MOSI
(out)
TE flag
BUSY flag
MISO/MOSI
(
in
)
RNE flag
Rx buffer
(
read SPI_DAT
)
Master mode
:
CLKPOL=1.CLKPHA=1
Set\clear by hardware
Set by hardware
Set by software
0xAA
0xBB
0xCC
Set by hardware
Set by software
Write 0x11 into SPI_DAT
Wait TE=1
,
write 0x22 into SPI_DAT
Wait RNE=1
,
read 0xAA from SPI_DAT
Wait TE=1
,
write 0x33 into SPI_DAT
Wait RNE=1
,
read 0xBB from SPI_DAT
Wait RNE=1
,
read 0xCC from SPI_DAT
0x22
0x33
0x11
Tx buffer
(
write SPI_DAT
)