4.3 Receive-Only Mode
This SPI module also provides the ability to configure the master to operate in Receive-Only mode. For the SPI to operate in this mode and begin receiving data from the slave, a non-zero value must be written to the transfer counter. In this mode, the master will continually receive data until the transfer counter is empty or the SPI is disabled. To configure the SPI module in this mode of operation, the RXR bit of the SPIxCON2 register must be set and the TXR bit of the SPIxCON2 register must be cleared. Regardless of the BMODE status, the transfer counter must have a non-zero value written to initiate the data transfer. The example below demonstrates the basic configuration of the SPI module in Receive-Only mode.
CONFIGURATION OF A SPI MASTER IN RECEIVE ONLY MODE
uint8_t SPI1_Master_RecieveOnly (uint8_t data)
{
SPI1CON2bits.TXR = 0; //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;
}