UG-1262
Rev. B | Page 244 of 312
Full Duplex Operation
Simultaneous reads and writes are supported on the SPI. When implementing full duplex transfers in master mode, use the following procedure:
1.
Initiate a transfer sequence via a transmit on the P0.1/SPI0_MOSI pin and the P1.3/SPI1_MOSI pin. Set SPIx_CTL, Bit 6 = 1. If
interrupts are enabled, interrupts are triggered when a transmit interrupt occurs but not when a byte is received.
2.
If using interrupts, the SPI transmit interrupt indicated by SPIx_STAT, Bit 5 or the transmit FIFO underrun interrupt (SPIx_STAT,
Bit 4) is asserted approximately three to four SPI clock periods into the transfer of the first byte. If necessary, reload a byte into the
transmit FIFO by writing to the SPIx_TX register.
3.
The first byte received via the MISO pin does not update the receive FIFO status bits (SPIx_FIFO_STAT, Bits[11:8]) until 12 SPI
clock periods after CS goes low. Therefore, two transmit interrupts can occur before the first receive byte is ready to be processed.
4.
After the last transmit interrupt occurs, it may be necessary to read two more bytes. It is recommended that SPIx_FIFO_STAT,
Bits[11:8] be polled outside of the SPI interrupt handler after the last transmit interrupt is handled.
SPI INTERRUPTS
There is one interrupt line per SPI and 11 sources of interrupts. SPIx_STAT, Bit 0 reflects the state of the interrupt line, and SPIx_STAT,
Bits[15:12] and SPIx_STAT, Bits[7:1] reflect the state of the 11 sources. The SPI generates either transmit or receive interrupts. Both
interrupts cannot be enabled at the same time. The appropriate interrupt is enabled using SPIx_CTL, Bit 6. If TIM = 1, the transmit IRQ
is enabled. If TIM = 0, the receive IRQ is enabled. In addition, the SPI0 and SPI1 interrupt source must be enabled in the NVIC register
as follows: ISER0, Bit 15 = SPI0, ISER0, Bit 16 = SPI1.
Transmit Interrupt
If SPIx_CTL, Bit 6 is set, the transmit FIFO status causes the interrupt. The SPIx_IEN, Bits[2:0] control when the interrupt occurs, as
shown in Table 304.
Table 304. SPIx_IEN, Bits[2:0] IRQ Mode Bits
SPIx_IEN, Bits[2:0] Settings
Interrupt Condition
000
An interrupt occurs after each byte that is transmitted. The interrupt occurs when the byte is read from the
FIFO and written to the shift register.
001
An interrupt occurs after every two bytes that are transmitted.
010
An interrupt occurs after every third byte that is transmitted.
011
An interrupt occurs after every fourth byte that is transmitted.
100
An interrupt occurs after every fifth byte that is transmitted.
101
An interrupt occurs after every sixth byte that is transmitted.
110
An interrupt occurs after every seventh byte that is transmitted.
111
An interrupt occurs after every eighth byte that is transmitted.
The interrupts are generated depending on the number of bytes transmitted and not on the number of bytes in the FIFO. The transmit
interrupt is different from the receive interrupt, which depends on the number of bytes in the receive FIFO and not on the number of
bytes received.
The transmit interrupt is cleared by a read to the status register. The status of this interrupt can be read by reading SPIx_STAT, Bit 5.
The interrupt is disabled if SPIx_CTL, Bit 13 is left high. A write to the control register, SPIx_CTL, resets the transmitted byte counter
back to 0. For example, if SPIx_IEN, Bits[2:0] are set to 0x3 and SPIx_CTL is written to after three bytes are transmitted, the transmit
interrupt does not occur until another four bytes are transmitted.
Receive Interrupt
If the TIM bit (SPIx_CTL, Bit 6) is cleared, the receive FIFO status causes the receive interrupt to be generated. SPIx_IEN, Bits[2:0]
control when the interrupt occurs. The interrupt is cleared by a read of the SPIx_STAT register. The status of this interrupt can be read
in SPIx_STAT, Bit 6.
Interrupts are only generated when data is written to the FIFO. For example, if SPIx_IEN, Bits[2:0] is set to 0b000, an interrupt is
generated after the first byte is received. When the status register is read, the interrupt is deactivated. If the byte is not read from the
FIFO, the interrupt is not regenerated. Another interrupt is not generated until another byte is received in the FIFO.
The interrupt depends on the number of valid bytes in FIFO and not on the number of bytes received. For example, when SPIx_IEN,
Bits[2:0] is set to 0b001, an interrupt is generated after a byte is received if there are two or more bytes in the FIFO. The interrupt is not
generated after every two bytes received. The receive interrupt is disabled if SPIx_CTL, Bit 12 is left high.