EasyManuals Logo

ST STM8S Reference Manual

ST STM8S
449 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #269 background imageLoading...
Page #269 background image
RM0016 Serial peripheral interface (SPI)
Doc ID 14587 Rev 8 269/449
In master unidirectional receive-only mode (MSTR = 1, BDM = 0, RXONLY = 1)
or bidirectional receive mode (MSTR = 1, BDM = 1, BDOE = 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 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 a transfer.
In slave receive-only mode (MSTR = 0, BDM = 0, RXONLY = 1) or bidirectional
receive mode (MSTR = 0, BDM = 1, BDOE = 0):
1. You can disable the SPI (write SPE = 1) whenever you want: the current transfer will
complete before being effectively disabled.
2. Then, if you want to enter Halt mode, you must first wait until BSY = 0 before entering
Halt mode (or disabling the peripheral clock).
20.3.9 Error flags
Master mode fault (MODF)
Master mode fault occurs when the master device has its NSS pin pulled low (in NSS
hardware mode) or SSI bit low (in NSS software mode), this automatically sets the MODF
bit. Master mode fault affects the SPI peripheral in the following ways:
The MODF bit is set and an SPI interrupt is generated if the ERRIE bit is set.
The SPE bit is reset. This blocks all output from the device and disables the SPI
interface.
The MSTR bit is reset, thus forcing the device into slave mode.
Use the following software sequence to clear the MODF bit:
1. Make a read or write access to the SPI_SR register while the MODF bit is set.
2. Then write to the SPI_CR1 register.
To avoid any multiple slave conflicts in a system comprising several MCUs, the NSS pin
must be pulled high during the MODF bit clearing sequence. The SPE and MSTR bits can
be restored to their original state after this clearing sequence.
As a security, hardware does not allow you to set the SPE and MSTR bits while the MODF
bit is set.
In a slave device the MODF bit cannot be set. However, in a multi-master configuration, the
device can be in slave mode with this MODF bit set. In this case, the MODF bit indicates that
there might have been a multimaster conflict for system control. You can use an interrupt
routine to recover cleanly from this state by performing a reset or returning to a default state.

Table of Contents

Other manuals for ST STM8S

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the ST STM8S and is the answer not in the manual?

ST STM8S Specifications

General IconGeneral
BrandST
ModelSTM8S
CategoryMicrocontrollers
LanguageEnglish

Related product manuals