RM0008
Figure 245. TXE/BSY behavior when transmitting (BIDIRMODE=0 and RXONLY=0) in the case of
Example with CPOL=1, CPHA=1
SCK
MOSI (out)
TXE flag
Tx buffer
(write to SPI_DR)
BSY flag
software writes 0xF1
software waits until TXE=1 but is
into SPI_DR
25.3.6
CRC calculation
A CRC calculator has been implemented for communication reliability. Separate CRC
calculators are implemented for transmitted data and received data. The CRC is calculated
using a programmable polynomial serially on each bit. It is calculated on the sampling clock
edge defined by the CPHA and CPOL bits in the SPI_CR1 register.
Note:
This SPI offers two kinds of CRC calculation standard which depend directly on the data
frame format selected for the transmission and/or reception: 8-bit data (CR8) and 16-bit data
(CRC16).
CRC calculation is enabled by setting the CRCEN bit in the SPI_CR1 register. This action
resets the CRC registers (SPI_RXCRCR and SPI_TXCRCR). In full duplex or transmitter
only mode, when the transfers are managed by the software (CPU mode), it is necessary to
write the bit CRCNEXT immediately after the last data to be transferred is written to the
SPI_DR. At the end of this last data transfer, the SPI_TXCRCR value is transmitted.
In receive only mode and when the transfers are managed by software (CPU mode), it is
necessary to write the CRCNEXT bit after the second last data has been received. The CRC
is received just after the last data reception and the CRC check is then performed.
At the end of data and CRC transfers, the CRCERR flag in the SPI_SR register is set if
corruption occurs during the transfer.
If data are present in the TX buffer, the CRC value is transmitted only after the transmission
of the data byte. During CRC transmission, the CRC calculator is switched off and the
register value remains unchanged.
SPI communication using the CRC is possible through the following procedure:
discontinuous transfers
DATA 1 = 0xF1
b0 b1 b2 b3 b4 b5 b6 b7
0xF1
late to write 0xF2 into SPI_DR
DocID13902 Rev 15
D
A
T
A
2
=
0
x
F
2
b0 b1 b2 b3 b4 b5 b6 b7
0xF2
software waits until TXE=1 but
is late to write 0xF3 into
SPI_DR
Serial peripheral interface (SPI)
D
A
T
A
3
=
0
x
b0 b1 b2 b3 b4 b5 b6 b7
0xF3
software waits
software waits until BSY=0
until TXE=1
F
3
ai17348
706/1128
742
Need help?
Do you have a question about the STM32F101 series and is the answer not in the manual?
Questions and answers