GD32W51x User Manual
677
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.
In master mode, software should write the next data into SPI_DATA register before the
transmission of current data frame is completed if it desires to generate continuous
transmission.
Reception sequence
After the last valid sample clock, the incoming data will be moved from shift register to the
receive buffer and RBNE (receive buffer not empty) will be set. The application should read
SPI_DATA register to get the received data and this will clear the RBNE flag automatically.
In MRU and MRB modes, hardware continuously sends clock signal to receive the next data
frame, while in full-duplex master mode (MFD), hardware only receives the next data frame
when the transmit buffer is not empty.
SPI operation sequence in different modes (Not Quad-SPI, TI mode or NSSP
mode)
In full-duplex mode, either MFD or SFD, the RBNE and TBE flags should be monitored and
then follow the sequences described above.
The transmission mode (MTU, MTB, STU or STB) is similar to the transmission sequence of
full-duplex mode regardless of the RBNE and OVRE bits.
The master reception mode (MRU or MRB) is different from the reception sequence of full-
duplex mode. In MRU or MRB mode, after SPI is enabled, the SPI continuously generates
SCK until the SPI is disabled. So the application should ignore the TBE flag and read out
reception buffer in time after the RBNE flag is set, otherwise a data overrun fault will occur.
The slave reception mode (SRU or SRB) is similar to the reception sequence of full-duplex
mode regardless of the TBE flag.