4.1 Full-Duplex Mode
Full-Duplex mode most closely matches the operation of the SPI incorporated into the MSSP module of older PIC devices, allowing for simultaneous exchange of data between the master and slave devices. To configure the SPI module as a master in Full-Duplex mode, the RXR and TXR registers of the SPIxCON2 register must both be set high. Depending on the status of the BMODE bit, the transfer counter may need to be loaded to initiate the SPI module to begin transferring data. The example below demonstrates the basic configuration of the SPI module in Full-Duplex mode.
CONFIGURATION OF A SPI MASTER IN FULL DUPLEX MODE
uint8_t SPI1_Master_FullDuplex (uint8_t data)
{
SPI1CON2bits.TXR = 1; //Transmit Data-Required Bit;
SPI1CON2bits.RXR = 1; // Receive FIFO Space-Required Bit;
SPI1TCNT = 1; // Load SPI Transfer Counter;
SPI1TXB = data; // Load data into SPI transmit buffer;
while (PIR2bits.SPI1RXIF == 0); // Check for any SPI Receive Interrupts;
return (SPI1RXB); // Return data from SPI Receive Buffer Register;
}