UG-1262
Rev. B | Page 242 of 312
In master mode, the SPIx_CTL register controls the polarity and phase of the clock, and the bit rate is defined in the SPIx_DIV register
as follows:
2 (1
_
)
SCLK
PCLK
f
SPIx DIV[5 : 0]
(25)
where
PCLK
is the system clock divided by the factor set in CTL1, Bits[13:8].
By reducing the clock rate to the SPI blocks, it is possible to reduce the power consumption of the SPI block. The maximum data rate is 13 Mbps.
In slave mode, the SPIx_CTL register must be configured with the phase and polarity of the expected input clock. The slave accepts data
from an external master up to 20 Mbps. In both master and slave mode, data is transmitted on one edge of the SCLK signal and sampled
on the other. Therefore, it is important that the polarity and phase be configured the same for the master and slave devices.
P0.3/SPI0_CS Pin and P1.5/SPI1_CS Pin
In SPI slave mode, a transfer is initiated by the assertion of the chip select, which is an active low input signal. The SPI port then
transmits and receives 8-bit data until the transfer is concluded by deassertion of CS. In slave mode, CS is always an input.
In SPI master mode, CS is an active low output signal. The pin asserts itself automatically at the beginning of a transfer and deasserts
itself upon completion.
master wants to communicate with multiple SPI slaves, GPIOs can be connected to the chip select lines of the slaves.
Use the CSRISE and CSFALL bits (SPIx_STAT, Bit 13 and SPIx_STAT, Bit 14, respectively) to determine when to pull the GPIOs low or high.
SPI TRANSFER INITIATION
In master mode, the transfer and interrupt mode bit (SPIx_CTL, Bit 6) determines the manner in which an SPI serial transfer is initiated. If this
bit is set, a serial transfer is initiated after a write to the transmit FIFO. If this bit is cleared, a serial transfer is initiated after a read of the receive
FIFO. The read must be performed while the SPI interface is idle. A read performed during an active transfer does not initiate another transfer.
For any setting of SPIx_CTL, Bit 1 and SPIx_CTL, Bit 6, the SPI simultaneously receives and transmits data. Therefore, during data
transmission, the SPI is also receiving data and filling up the receive FIFO. If the data is not read from the receive FIFO, the overflow
interrupt occurs when the FIFO starts to overflow. If the user does not want to read the receive data or receive overflow interrupts, set
SPIx_CTL, Bit 12 and the receive data is not saved to the receive FIFO. Similarly, to only receive data and not write data to the transmit
FIFO, set SPIx_CTL, Bit 13 to avoid receiving underrun interrupts from the transmit FIFO.
Transmit Initiated Transfer
For transfers initiated by a write to the transmit FIFO, the SPI starts transmitting as soon as the first byte is written to the FIFO,
irrespective of the configuration in SPIx_IEN, Bits[2:0]. The first byte is immediately read from the FIFO, written to the transmit shift
register, and the transfer commences.
If the continuous transfer enable bit, SPIx_CTL, Bit 11, is set, the transfer continues until no valid data is available in the transmit FIFO.
This completion is either the end of SPIx_CNT, Bits[13:0] number of bytes (if SPIx_CNT, Bits[13:0] > 0) or when no valid data is available in
the transmit FIFO (if SPIx_CNT, Bits[13:0] = 0). Chip select remains asserted for the duration of the complete transfer. If SPIx_CNT, Bit 15 is
cleared and SPIx_CNT, Bits[13:0] > 0, the transfer stops when all the bytes in SPIx_CNT, Bits[13:0] have been transferred. If SPIx_CNT,
Bit 15 is set, a new frame starts after every SPIx_CNT, Bits[13:0] number of bytes. Multiples of bytes in SPIx_CNT, Bits[13:0] are always
transferred in this case. If there is no data or space in the FIFO, the transfer stalls until it is available. Conversely, the transfer continues
while there is valid data in the FIFO. If SPIx_CTL, Bit 11 is cleared, each transfer consists of a single 8-bit serial transfer. If valid data
exists in the transmit FIFO, a new transfer is initiated after a stall period, and a chip select is deasserted.
Receive Initiated Transfer
Transfers initiated by a read of the receive FIFO depend on the number of bytes received in the FIFO. If SPIx_IEN, Bits[2:0] = 0b111 and
a read to the receive FIFO occurs, the SPI initiates an 8-byte transfer. If continuous mode is set (SPIx_CTL, Bit 11 = 1), the eight bytes
occur continuously with no deassertion of chip select between bytes. However, in continuous mode, if SPIx_CNT, Bits[13:0] > 0, the chip
select asserts for the entire frame duration. The SPI introduces stall periods by not clocking SPI0_CLK or SPI1_CLK until FIFO space is
available. If continuous mode is not set, the eight bytes occur with stall periods between transfers where the chip select output is deasserted.
If SPIx_IEN, Bits[2:0] = 0b110, a read of the receive FIFO initiates a 7-byte transfer. If SPIx_IEN, Bits[2:0] = 0b001, a read of the receive
FIFO initiates a 2-byte transfer. If SPIx_IEN, Bits[2:0] = 0b000, a read of the receive FIFO initiates a 1-byte transfer. A read of the receive
FIFO while the SPI is receiving data does not initiate another transfer after the present transfer is complete.