
RM0008
Serial peripheral interface (SPI)
Doc ID 13902 Rev 12
693/1096
25.3.8
Disabling the SPI
When a transfer is terminated, the application can stop the communication by disabling the
SPI peripheral. This is done by clearing the SPE bit.
For some configurations, disabling the SPI and entering the Halt mode while a transfer is
ongoing can cause the current transfer to be corrupted and/or the BSY flag might become
unreliable.
To avoid any of those effects, it is recommended to respect the following procedure when
disabling the SPI:
In master or slave full-duplex mode (BIDIMODE=0, RXONLY=0)
1.
Wait until RXNE=1 to receive the last data
2. Wait
until
TXE=1
3.
Then wait until BSY=0
4.
Disable the SPI (SPE=0) and, eventually, enter the Halt mode (or disable the peripheral
clock)
In master or slave unidirectional transmit-only mode (BIDIMODE=0,
RXONLY=0) or bidirectional transmit mode (BIDIMODE=1, BIDIOE=1)
After the last data is written into the SPI_DR register:
1.
Wait until TXE=1
2.
Then wait until BSY=0
3.
Disable the SPI (SPE=0) and, eventually, enter the Halt mode (or disable the peripheral
clock)
In master unidirectional receive-only mode (MSTR=1, BIDIMODE=0,
RXONLY=1) or bidirectional receive mode (MSTR=1, BIDIMODE=1, BIDIOE=0)
This case must be managed in a particular way to ensure that the SPI does not initiate a
new transfer:
1.
Wait for the second to last occurrence of RXNE=1 (n–1)
2.
Then wait for one SPI clock cycle (using a software loop) before disabling the SPI
(SPE=0)
3.
Then wait for the last RXNE=1 before entering the Halt mode (or disabling the
peripheral clock)
Note:
In master bidirectional receive mode (MSTR=1 and BDM=1 and BDOE=0), the BSY flag is
kept low during transfers.
In slave receive-only mode (MSTR=0, BIDIMODE=0, RXONLY=1) or
bidirectional receive mode (MSTR=0, BIDIMODE=1, BIDOE=0)
1.
You can disable the SPI (write SPE=1) at any time: the current transfer will complete
before the SPI is effectively disabled
2.
Then, if you want to enter the Halt mode, you must first wait until BSY = 0 before
entering the Halt mode (or disabling the peripheral clock)