19.4.1.5.2 Client Mode Operation
The following steps are used to set up the SPI module for the Client mode of operation:
- If using interrupts, disable the SPIx interrupts in the respective IECx register.
- Stop and reset the SPI module by clearing the ON bit.
- Clear the receive buffer.
- Clear the ENHBUF bit (SPIxCON1[0]) if using Standard Buffer mode or set the bit if using Enhanced Buffer mode.
- If using interrupts, the following additional steps are performed:
- Clear the SPIx interrupt flags/events in the respective IFSx register.
- Write the SPIx interrupt priority and sub-priority bits in the respective IPCx register.
- Set the SPIx interrupt enable bits in the respective IECx register.
- Clear the SPIROV bit (SPIxSTAT[6]).
- Write the desired settings to the SPIxCON1 register with MSTEN (SPIxCON1[5]) =
0
. - Enable SPI operation by setting the ON bit (SPIxCON1[15]).
- Transmission (and reception) will start as soon as the host provides the serial clock.
In Client mode, data is transmitted and received as the external clock pulses appear on the SCKx pin. The CKP bit (SPIxCON1[6]) and the CKE bit (SPIxCON1[8]) determine on which edge of the clock data transmission occurs.
Both data to be transmitted and data that is received are respectively written into or read from the SPIxBUF register.
The rest of the operation of the module is identical to that in the Host mode, including Enhanced Buffer mode.