25.3.2.2.2 Buffer Mode

To avoid data collisions, the SPI peripheral can be configured in Buffered mode by writing a ‘1’ to the Buffer Mode Enable bit in the Control B register (BUFEN in SPIn.CTRLB). In this mode, the SPI has additional interrupt flags and extra buffers. The extra buffers are shown in Figure 25-1. There are two different modes for the Buffer mode, selected with the Buffer mode Wait for Receive bit (BUFWR). The two different modes are described below with timing diagrams.

Slave Buffer Mode with Wait for Receive Bit Written to ‘0

In Slave mode, if the Wait for Receive bit (BUFWR in SPIn.CRTLB) is written to ‘0’, a dummy byte will be sent before the transmission of user data starts. Figure 25-3 shows a transmission sequence with this configuration. Notice how the value 0x45 is written to the Data register (SPIn.DATA) but never transmitted.

Figure 25-3. SPI Timing Diagram in Buffer Mode with BUFWR in SPIn.CTRLB Written to ‘0

When the Wait for Receive bit (BUFWR in SPIn.CTRLB) is written to ‘0’, all writes to the Data register (SPIn.DATA) goes to the Transmit Data Buffer register. The figure above shows that the value 0x43 is written to the Data register (SPIn.DATA), but it is not immediately transferred to the shift register so the first byte sent will be a dummy byte. The value of the dummy byte equals the values that was in the shift register at the time. After the first dummy transfer is completed the value 0x43 is transferred to the shift register. Then 0x44 is written to the Data register (SPIn.DATA) and goes to the Transmit Data Buffer register. A new transfer is started, and 0x43 will be sent. The value 0x45 is written to the Data register (SPIn.DATA), but the Transmit Data Buffer register is not updated since it is already full containing 0x44 and the Data Register Empty Interrupt Flag (DREIF in SPIn.INTFLAGS) is low. The value 0x45 will be lost. After the transfer, the value 0x44 is moved to the shift register. During the next transfer, 0x46 is written to the Data register (SPIn.DATA), and 0x44 is sent out. After the transfer is complete, 0x46 is copied into the shift register and sent out in the next transfer.

The DREIF goes low every time the Transmit Data Buffer register is written, and goes high after a transfer when the previous value in the Transmit Data Buffer register is copied into the shift register. The Receive Complete Interrupt Flag (RXCIF in SPIn.INTFLAGS) is set one cycle after the DREIF goes high. The Transfer Complete Interrupt Flag is set one cycle after the Receive Complete Interrupt Flag is set when both the value in the shift register and the Transmit Data Buffer register have been sent.

Slave Buffer Mode with Wait for Receive Bit Written to ‘1

In Slave mode, if the Wait for Receive bit (BUFWR in SPIn.CRTLB) is written to ‘1’, the transmission of user data starts as soon as the SS pin is driven low. Figure 25-4 shows a transmission sequence with this configuration. Notice how the value 0x45 is written to the Data register (SPIn.DATA) but never transmitted.

Figure 25-4. SPI Timing Diagram in Buffer Mode with CTRLB.BUFWR Written to ‘1

All writes to the Data register (SPIn.DATA) go to the Transmit Data Buffer register. The figure above shows that the value 0x43 is written to the Data register (SPIn.DATA) and since the SS pin is high it is copied to the shift register in the next cycle. Then the next write (0x44) will go to the Transmit Data Buffer register. During the first transfer the value 0x43 will be shifted out. In the figure above, the value 0x45 is written to the Data register (SPIn.DATA), but the Transmit Data Buffer register is not updated since the DREIF is low. After the transfer is completed, the value 0x44 from the Transmit Data Buffer register is copied to the shift register. The value 0x46 is written to the Transmit Data Buffer register. During the next two transfers, 0x44 and 0x46 are shifted out. The flags behave identical to Buffer Mode Wait for Receive Bit (BUFWR in SPIn.CTRLB) set to ‘0’.