Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
520
/
631
MOSI pin. The received data bits are sequentially and consecutively shifted serially into an shift register and then
loaded into the SPI_DAT register (receive buffer) in parallel.
Slave one-wire bidirectional send mode (SPI_CTRL1.MSEL = 0, SPI_CTRL1.BIDIRMODE = 1 and
SPI_CTRL1.BIDIROEN = 1)
When the slave device receives the first edge of the clock signal, the sending process starts. No data is received in
this mode, and the software must ensure that the data to be sent has been written in the SPI_DAT register before the
SPI master device starts data transmission.
Slave one-wire bidirectional receive mode (SPI_CTRL1.MSEL = 0, SPI_CTRL1.BIDIRMODE = 1 and
SPI_CTRL1.BIDIROEN = 0)
Data receiving begins when the slave device receives the first clock edge and a data bit from the MOSI pin. There
is no data output in this mode, the received data bits are sequentially and consecutively shifted serially into an shift
register, and then loaded into the SPI_DAT register (receive buffer) in parallel.
Note: The software operation process of the slave can refer to the master.
SPI initialization process
1.
The baud rate of serial clock is defined by the SPI_CTRL1.BR[2:0] bits (this step is ignored if it is working in
slave mode).
2.
Select SPI_CTRL1.CLKPOL bit and SPI_CTRL1.CLKPHA bit to define the phase relationship between data
transmission and serial clock (see Figure 24-4).
3.
Set SPI_CTRL1.DATFF bit to define 8-bit or 16-bit data frame format.
4.
Configure the SPI_CTRL1.LSBFF bit to define the frame format.
5.
Configure the NSS mode as described above for the NSS function.
6.
Run mode is configured by SPI_CTRL1.MSEL bit, SPI_CTRL1.BIDIRMODE bit, SPI_CTRL1.BIDIROEN
bit and SPI_CTRL1.RONLY bit.
7.
Set the SPI_CTRL1.SPIEN = 1 to enable SPI.
Basic send and receive process
When SPI sends a data frame, it first loads the data frame from the data buffer into the shift register, and then starts
to send the loaded data. When the data is transferred from the send buffer to the shift register, the send buffer empty
flag is set (SPI_STS.TE = 1), and the next data can be loaded into the send buffer; if the TEINTEN bit is set
(SPI_CTRL2.TEINTEN = 1), an interrupt will be generated; writing data to the SPI_DAT register will clear the
SPI_STS.TE bit.
At the last edge of the sampling clock, when the data is transferred from the shift register to the receive buffer, the
receive buffer non-empty flag is set (SPI_STS.RNE = 1), at this time the data is ready and can be read from the
SPI_DAT register; if the receive buffer non-empty interrupt is enabled (SPI_CTRL2.RNEINTEN = 1), an interrupt
will be generated; the SPI_STS.RNE bit can be cleared by reading the SPI_DAT register data.
In master mode, the sending process starts when data is written to the send buffer. If the next data has been written
into the SPI_DAT register before the current data frame sending is completed, the continuous sending function can