GD32F10x User Manual
489
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
transmiting 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.
Configure data format (FF16 bit in the SPI_CTL0 register).
3.
Configure the clock timing register (CKPL and CKPH bits in the SPI_CTL0 register).
4.
Configure the frame format (LF bit in the SPI_CTL0 register).
5.
Configure the NSS mode (SWNSSEN and NSSDRV bits in the SPI_CTL0 register)
according to the application’s demand as described above in
6.
Configure MSTMOD, RO, BDEN and BDOEN depending on the operating modes
section.
7.
Enable the SPI (set the SPIEN bit).
Note:
During communication, CKPH, CKPL, MSTMOD, PSC[2:0] and LF bits should not be
changed.
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 begins to toggle at SCK pin 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 transmited. 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.
Summary of Contents for GD32F10 Series
Page 63: ...GD32F10x User Manual 63 programmed during the chip production ...
Page 117: ...GD32F10x User Manual 117 010 1 0 011 0 9 ...
Page 416: ...GD32F10x User Manual 416 shadow register updates every update event ...
Page 427: ...GD32F10x User Manual 427 value ...
Page 518: ...GD32F10x User Manual 518 These bits are not used in SPI mode ...