658
SAM4CP [DATASHEET]
43051E–ATPL–08/14
33.7.3.10 Mode Fault Detection
The SPI has the capability to operate in multi-master environment. Consequently, the NPCS0/NSS line must be
monitored. If one of the masters on the SPI bus is currently transmitting, the NPCS0/NSS line is low and the SPI must not
transmit any data. A mode fault is detected when the SPI is programmed in Master mode and a low level is driven by an
external master on the NPCS0/NSS signal. In multi-master environment, NPCS0, MOSI, MISO and SPCK pins must be
configured in open drain (through the PIO controller). When a mode fault is detected, the MODF bit in the SPI_SR is set
until SPI_SR is read and the SPI is automatically disabled until it is re-enabled by writing a 1 to the SPIEN bit in the
SPI_CR.
By default, the Mode Fault detection is enabled. The user can disable it by setting the MODFDIS bit in the SPI_MR.
33.7.4 SPI Slave Mode
When operating in Slave Mode, the SPI processes data bits on the clock provided on the SPI clock pin (SPCK).
The SPI waits until NSS goes active before receiving the serial clock from an external master. When NSS falls, the clock
is validated and the data is loaded in the SPI_RDR depending on the BITS field configured in the SPI_CSR0. These bits
are processed following a phase and a polarity defined respectively by the NCPHA and CPOL bits in the SPI_CSR0.
Note that BITS, CPOL and NCPHA of the other Chip Select registers have no effect when the SPI is programmed in
Slave mode.
The bits are shifted out on the MISO line and sampled on the MOSI line.
For more information on BITS field, see also, the note
(1)
below the SPI_CSRx register bitmap (
Section 33.8.9 “SPI
Chip Select Register” on page 670
).
Note:
When all bits are processed, the received data is transferred in the SPI_RDR and the RDRF bit rises. If the SPI_RDR
has not been read before new data is received, the Overrun Error Status (OVRES) bit in the SPI_SR is set. As long as
this flag is set, data is loaded in the SPI_RDR. The user must read SPI_SR to clear the OVRES bit.
When a transfer starts, the data shifted out is the data present in the Shift register. If no data has been written in the
SPI_TDR, the last data received is transferred. If no data has been received since the last reset, all bits are transmitted
low, as the Shift register resets to 0.
When a first data is written in the SPI_TDR, it is transferred immediately in the Shift register and the TDRE flag rises. If
new data is written, it remains in the SPI_TDR until a transfer occurs, i.e., NSS falls and there is a valid clock on the
SPCK pin. When the transfer occurs, the last data written in the SPI_TDR is transferred in the Shift register and the
TDRE flag rises. This enables frequent updates of critical variables with single transfers.
Then, new data is loaded in the Shift register from the SPI_TDR. If no character is ready to be transmitted, i.e., no
character has been written in the SPI_TDR since the last load from the SPI_TDR to the Shift register, the SPI_TDR is
retransmitted. In this case the Underrun Error Status Flag (UNDES) is set in the SPI_SR.
Figure 33-12
shows a block diagram of the SPI when operating in Slave Mode.
Figure 33-12. Slave Mode Functional Block Diagram
Shift Register
SPCK
SPIENS
LSB
MSB
NSS
MOSI
SPI_RDR
RD
SPI
Clock
TDRE
SPI_TDR
TD
RDRF
OVRES
SPI_CSR0
CPOL
NCPHA
BITS
SPIEN
SPIDIS
MISO