Client Mode Additional Features

The following additional features are provided in the Client mode:

Client Select Synchronization

The SSx pin allows a Synchronous Client mode. If the SSEN bit (SPIxCON1[7]) is set, transmission and reception are enabled in Client mode only if the SSx pin is driven to a low state. The port output or other peripheral outputs must not be driven in order to allow the SSx pin to function as an input. If the SSEN bit is set and the SSx pin is driven high, the SDOx pin is no longer driven and will tri-state, even if the module is in the middle of a transmission. An aborted transmission will be retried the next time the SSx pin is driven low using the data held in the SPIxTXB register. If the SSEN bit is not set, the SSx pin does not affect the module operation in Client mode.

SPITBE Status Flag Operation

The SPITBE bit (SPIxSTAT[3]) has a different function in the Client mode of operation. The following describes the function of SPITBE for various settings of the Client mode of operation:

  • If SSEN (SPIxCON1[7]) is cleared, the SPITBE bit is cleared when SPIxBUF is loaded by the user code. It is set when the module transfers SPIxTXB to SPIxTXSR. This is similar to the SPITBE bit function in Host mode.
  • If SSEN is set, SPITBE is cleared when SPIxBUF is loaded by the user code. However, it is set only when the SPI module completes data transmission. A transmission will be aborted when the SSx pin goes high and may be retried at a later time. So, each data word is held in SPIxTXB until all bits are transmitted to the receiver.
    Note: Client Select cannot be used when operating in Frame mode.
Figure 19-10. SPIx Client Mode Operation in 8-Bit Mode with Client Select Pin Disabled (MODE32 = 0, MODE16 = 0, SSEN = 0)
Note:
  1. Two SPI Clock modes are shown here only to demonstrate the functionality of bits, CKP (SPIxCON1[6]) and CKE (SPIxCON1[8]). Any combination of CKP and CKE bits can be chosen for module operation.
  2. If there are no pending transmissions or a transmission is in progress, SPIxBUF is transferred to SPIxTXSR as soon as the user writes to SPIxBUF.
  3. Operation for 8-bit mode is shown; 16-bit and 32-bit modes are similar.
Figure 19-11. SPIx Client Mode Operation in 8-Bit Mode with Client Select Pin Disabled (MODE32 = 0, MODE16 = 0, SSEN = 0)
Note:
  1. When the SSEN (SPIxCON1[7]) bit is set to ‘1’, the SSx pin must be driven low so as to enable transmission and reception in Client mode.
  2. Transmit data is held in SPIxTXB, and SPITBE (SPIxSTAT[3]) remains clear until all bits are transmitted.
  3. Operation for 8-bit mode is shown; 16-bit and 32-bit modes are similar.

Initialization Code for 16-Bit SPI Client Mode

/* The following code example will initialize the SPI1 in Client mode. */
_SPI1RXIP = 4;                     //Set SPI Interrupt Priorities
SPI1STATbits.SPIROV = 0;          // clear the Overflow
SPI1CON1 = 0x0400;                // 16 bits transfer, Client mode,ckp=0,cke=0,smp=0
SPI1IMSKbits.SPIRBFEN = 1;        // SPI1 receive buffer full generates interrupt event
_SPI1RXIE = 1;                    // Enable interrupts
SPI1CON1bits.ON = 1;
// from here, the device is ready to transmit and receive data. Buffer can be loaded to
transmit data.