GD32A50x User Manual
555
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.
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 bit in the SPI_CTL0 register and NSSDRV bit in
the SPI_CTL1
register) according to the application’s demand as described above in
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
described in
Table 21-5. SPI operating modes
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.
9.
Enable the SPI (set the SPIEN bit).
Note:
During communication, CKPH, CKPL, MSTMOD, PSC[2:0] and LF bits should not be
changed.
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