GD32VF103 User Manual
385
Figure 18-6. A typical bidirectional connection
Master
MTB/MRB
MISO
MOSI
SCK
NSS
Slave
SRB/STB
MISO
MOSI
SCK
NSS
SPI initialization sequence
Before
transmitting or receiving
data, application should follow the SPI initialization sequence
described below:
1.
If master mode or slave TI mode is used, program the PSC [2:0] bits in SPI_CTL0 register
to generate SCK with desired baud rate, or configure the Td time in TI mode, otherwise,
ignore this step.
2.
Program data format (FF16 bit in the SPI_CTL0 register).
3.
Program the clock timing register (CKPL and CKPH bits in the SPI_CTL0 register).
4.
Program the frame format (LF bit in the SPI_CTL0 register).
5.
Program the NSS mode (SWNSSEN and NSSDRV bits in the SPI_CTL0 register)
according to the application
’s demand as described above in
section.
6.
If TI mode is used, set TMOD bit in SPI_CTL1 register, otherwise, ignore this step.
7.
Configure MSTMOD, RO, BDEN and BDOEN depending on the operating modes
section.
8.
If Quad-SPI mode is used, set the QMOD bit in SPI_QCTL register. Ignore this step if
Quad-SPI mode is not used.
1. Enable the SPI (set the SPIEN bit).
SPI basic transmission and reception sequence
Transmission sequence
After the initialization sequence, the SPI is enabled and stays at idle state. In master mode,
the transmission starts when the application writes a data into the transmit buffer. In slave
mode the transmission starts when SCK clock signal at SCK pin begins to toggle and NSS
level is low, so application should ensure that data is already written into transmit buffer before
the transmission starts in slave mode.
When SPI begins to send a data frame, it first loads this data frame from the data buffer to
the shift register and then begins to transmit the loaded data frame, TBE (transmit buffer
empty) flag is set after the first bit of this frame is transmitted. After TBE flag is set, which
means the transmit buffer is empty, the application should write SPI_DATA register again if it
has more data to transmit.