UG-1262
Rev. B | Page 245 of 312
Underrun and Overflow Interrupts
SPIx_STAT, Bit 7 and SPIx_STAT, Bit 4 generate SPI interrupts. When a transfer starts with no data in the transmit FIFO, SPIx_STAT,
Bit 4 is set to indicate an underrun condition, which causes an interrupt. The interrupt and status bits are cleared upon a read of the
status register. This interrupt occurs irrespective of SPIx_IEN, Bits[2:0]. This interrupt is disabled if SPIx_CTL, Bit 13 is set.
When data is received and the receive FIFO is already full, SPIx_STAT, Bit 7 is set to 1, indicating an overflow condition, which causes
an interrupt. The interrupt and status bit are cleared upon a read of the status register. This interrupt occurs irrespective of SPIx_CTL,
Bits[2:0]. This interrupt is disabled if SPIx_CTL, Bit 12 is set.
When the SPI receive overflow bit (SPIx_STAT, Bit 7) is set to 1, the contents of the SPI receive FIFO are undetermined and must not be
used. The user must flush the receive FIFO upon detecting this error condition. All interrupts are cleared either by a read of the status
register or when SPIx_CTL, Bit 0 is cleared to 0. The receive and transmit interrupts are also cleared if the relevant flush bits are asserted.
Otherwise, the interrupts remain active even if the SPI is reconfigured.
SPI WIRE-OR’ED MODE
To prevent contention when the SPI is used in a multimaster or multislave system, the data output pins, MOSI and MISO, can be
configured to behave as open circuit drivers. An external pull-up resistor is required when this feature is selected. The wire-OR bit
(SPIx_CTL, Bit 4) controls the pad enable outputs for the data lines.
SPI CSERR CONDITION
The CSERR bit (SPIx_STAT, Bit 12) indicates if an erroneous deassertion of the CS signal has been detected before the completion of all
eight SCLK cycles. This bit generates an interrupt and is available in all modes of operation: slave, master, and during DMA transfers. If
an interrupt generated by SPIx_STAT, Bit 12 occurs, SPIx_CTL, Bit 0 must be disabled and restarted to enable a clean recovery to ensure
that subsequent transfers are error free.
SPI DMA
Two DMA channels are dedicated to transmit and receive. The SPI DMA channels must be configured in the microDMA controller of
the Arm Cortex-M3 processor. It is possible to enable a DMA request on one or two channels at the same time by setting the DMA request bits
for receive or transmit in the SPIx_DMA register. If only the DMA transmit request (SPIx_DMA, Bit 1) is enabled, the receive FIFO
overflows during an SPI transfer, unless the received data is read by user code, in which case an overflow interrupt is generated. To avoid
generating overflow interrupts, set the receive FIFO flush bit, or disable the SPI interrupt in the NVIC. If only the DMA receive request
(SPIx_DMA, Bit 2) is enabled, the transmit FIFO is underrun. To avoid an underrun interrupt, the SPI interrupt must be disabled.
The SPI transmit (SPIx_STAT, Bit 5) and SPI receive (SPIx_STAT, Bit 6) interrupts are not generated when using DMA. The SPI
transmit underflow (SPIx_STAT, Bit 4) and receive overflow (SPIx_STAT, Bit 7) interrupts are generated when using the microDMA
controller. SPIx_IEN, Bits[2:0] are not used in transmit mode and must be set to 0b000 in receive mode.
SPIx_DMA, Bit 0 controls the start of a DMA transfer. DMA requests are only generated when SPIx_DMA, Bit 0 = 1. At the end of a
DMA transfer, this bit must be cleared to prevent extra DMA requests to the microDMA controller. The data still present in the transmit
FIFO is transmitted if in transmit mode. All DMA data transfers are 16-bit transfers. Program the DMA accordingly. For example, if 16 bytes of
data are to be transferred over the SPI, program the DMA to perform eight half word (16-bit) transfers. If 17 bytes are to be transferred,
nine half word transfers are required.
In DMA mode, the transmit and receive FIFOs are two bytes wide. Bits[7:0] are first accessed by the SPI, followed by Bits[15:8]. This is
irrespective of count or SPIx_CTL, Bit 5 settings.
For example, if SPI_CNT, Bits[13:0] = 3, the order of transmission and reception is Byte 1, Byte 0 followed by Byte 3 (ignore), and Byte 2.
SPI_CTL, Bit 5 does not affect the FIFO access order in DMA mode. SPI_CTL, Bit 5 only affects how each byte is transferred over SPI.
DMA Master Transmit Configuration
The DMA SPI transmit channel must be configured. Configure the NVIC to enable DMA transmit master interrupts.
All DMA transfers are 16-bit transfers. When all data present in the DMA buffer is transmitted, the DMA generates an interrupt. User
code must disable the DMA request. Data is still in the transmit FIFO because the DMA request is generated each time there is free space
in the transmit FIFO to keep the FIFO full. User code can check how many bytes are still present in the FIFO in the SPIx_FIFO_STAT
register. The SPI block must be configured as follows: