5.2 SPI Transmitter Data Interrupt

The SPI Transmitter data interrupt is set when the transmit FIFO is not full, and is cleared when the transmit FIFO is full. For DMA-based operation the user does not need to enable the transmit interrupt required for another operation. The status of the SPI transmitter data interrupt flag can be monitored by reading the SPI transmit interrupt flag.

The DMA module can also be configured to take data from another memory region on the PIC microcontroller and move that to the TXFIFO to be transmitted by the SPI. This allows the SPI to continually transmit data without software involvement. Instead of needing to write to the transmit buffer every time a message needs to be sent, the DMA can move data into the transmit buffer as it empties out. The example below demonstrates how to configure the DMA to move data from Flash memory into the SPI transmit FIFO.

USING DMA TO LOAD SPI TRANSMIT BUFFER

// DMA Configuration (Destination SPI1TXB)
DMA1CON0 = 0xC0; // DMA Enable; SIRQEN;
DMA1CON1 = 0x0B; // DMODE; SMR; SMODE; SSTP;
DMA1SSA = 0x1000; // DMA Source Start Address - PFM;
DMA1SSZ = 0x32; // DMA Source Size (50);
DMA1DSA = &SPI1TXB; // DMA Destination Start Address (SPI1TXB);
DMA1DSZ = 0x01; // DMA Destination Size (1);
DMA1SIRQ = 0x15; // DMA Start Interrupt Request Source (SPI1TXB:21);