PCM/DSP Audio Client Mode of Operation

Use the following steps to set up the SPI module for the PCM/DSP Audio Client mode of operation:

  1. If using interrupts, disable the SPIx interrupts in the respective IECx register.
  2. Stop and reset the SPI module by clearing the ON bit (SPIxCON1[15]).
  3. Reset the SPIx Control Register 1, SPIxCON1.
  4. Clear the receive buffer.
  5. Clear the ENHBUF bit (SPIxCON1[0]) if using Standard Buffer mode or set the bit if using Enhanced Buffer mode.
  6. If using interrupts, the following additional steps are performed:
    1. Clear the SPIx interrupt flags/events in the respective IFSx register.
    2. Write the SPIx interrupt priority and sub-priority bits in the respective IPCx register.
    3. Set the SPIx interrupt enable bits in the respective IECx register.
  7. Clear the SPIROV bit (SPIxSTAT[6]).
  8. Write the desired setting in the SPIxCON1 register. The AUDMOD[1:0] bits (SPIxCON1[25:24]) must be set to ‘11’ for DSP/PCM mode and the AUDEN bit (SPIxCON1[31]) must be set to ‘1’ to enable audio protocol.
  9. Write the desired settings to the SPIxCON1 register:
    1. Set to Client mode, MSTEN (SPIxCON1[5]) = 0.
    2. Set MODE[32,16] (SPIxCON1[11:10]) = 0 for 16-bit audio channel data.
    3. Enable SPI operation by setting the ON bit (SPIxCON1[15]).
  10. Transmission (and reception) will start as soon as the host provides the BCLK and LRCK.

PCM/DSP Client Mode, 16-Bit Channel Data, 32-Bit Frame

/* The following code example will initialize the SPI1 Module in PCM/DSP Client Mode. */
_SPI1RXIP = 4;
SPI1STATbits.SPIROV = 0;       // clear the Overflow
SPI1CON1 = 0x83200400;         // AUDEN=1,PCM/DSP mode,stereo mode,FRMPOL=1, 
                               // 16 bits/32 channel transfer,Client mode,ckp=0
SPI1IMSKbits.SPIRBFEN = 1;     // SPI1 receive buffer full generates interrupt event
_SPI1RXIE = 1;                 // Enable interrupts
SPI1CON1bits.ENHBUF = 1;
SPI1CON1bits.ON = 1;
// from here, the device is ready to receive and transmit data