www
.mcu.com.cn
172
/
239
Rev.
1.00
CMS80F731x Reference Manual
20.5.1
Write Conflict Error
If the SPI data registers are written during the transfer, a write violation occurs. The transfer continues uninterrupted, and
the write data that causes the error is not written to the shifter. Write conflicts are indicated by the WCOL flag in the SPSR
register.
When a WCOL error occurs, the WCOL flag is automatically set to 1 by the hardware. To clear the WCOL bits, the user
should perform the following steps:
-
Read the contents of the SPSR register;
-
Access the SPDR register (read or write).
In the SPI master mode, the write conflict error when the clock polarity CPOL=0 and the clock phase CPHA=0 of SPI are
configured as shown in the following figure:
MOSI
SCLK
WCOL
NSS
D6
D5
D4
D3
D2
D1
D0
D7
D6
D5
D4
D3
D2
D1
D0
SPIIF
D7
The specific conditions for the occurrence of write conflicts are: during the data transmission process, when the NSS is low,
the first data starts to be sent from the moment to the 8th SCLK falling edge, if you write SPDR during this period, a write conflict
will occur, and the WCOL will be set to 1.
Note: When you start sending data, after writing spdr, the NSS does not immediately go low, and you need to wait for at
most one SPI clock before it starts to be low. After the NSS is low, it is necessary to wait for a system clock to start sending the
first data before entering the real data transfer state. Between writing the SPDR to the time it enters the real data transfer state,
writing the SPDR again does not create a write conflict. However, the operation updates the data that is ready to be sent. If there
are multiple writes to the SPDR, the data sent will be the last value written to the SPDR.
Since SPI has only one transmit buffer, it is recommended to determine whether the last data was sent before writing the
SPDR, and then write the SPDR register after the transmission is completed to prevent write conflicts.