GD32VF103 User Manual
382
18.5.
SPI function overview
18.5.1.
SPI clock timing and data format
CKPL and CKPH bits in SPI_CTL0 register decide the timing of SPI clock and data signal.
The CKPL bit decides the SCK level when idle and CKPH bit decides either first or second
clock edge is a valid sampling edge. These bits take no effect in TI mode.
Figure 18-2. SPI timing diagram in normal mode
SCK (CKPH=0 CKPL=0)
SCK (CKPH=0 CKPL=1)
SCK (CKPH=1 CKPL=0)
SCK (CKPH=1 CKPL=1)
MOSI
MISO
NSS
D[0]
LF=1,FF16=0
D[0]
D[7]
D[7]
In normal mode, the length of data is configured by the FF16 bit in the SPI_CTL0 register.
Data length is 16 bits if FF16=1, otherwise is 8 bits.
Data order is configured by the LF bit in SPI_CTL0 register, and SPI will first send the LSB if
LF=1, or the MSB if LF=0. The data order is fixed to MSB first in TI mode.
18.5.2.
NSS function
Slave mode
When slave mode is configured (MSTMOD=0), SPI gets NSS level from NSS pin in hardware
NSS mode (SWNSSEN = 0) or from SWNSS bit in software NSS mode (SWNSSEN = 1), and
SPI transmits/receives data only when NSS level is low. In software NSS mode, NSS pin is
not used.
Master mode
In master mode (MSTMOD=1), if the application uses multi-master connection, NSS can be
configured to hardware input mode (SWNSSEN=0, NSSDRV=0) or software mode
(SWNSSEN=1). Then, once the NSS pin (in hardware NSS mode) or the SWNSS bit (in
software NSS mode) goes low, the SPI automatically enters slave mode and triggers a master
fault flag CONFERR.
If the application wants to use NSS line to control the SPI slave, NSS should be configured
to hardware output mode (SWNSSEN=0, NSSDRV=1). NSS stays high after SPI is enabled