I2S Audio Client Mode of Operation
Use the following steps to set up the SPI module for the I2S Audio 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 (SPIxCON1[15]).
 - Reset the SPIx Control Register 1, SPIxCON1.
 - 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 need to be 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.
- AUDMOD[1:0] bits (SPIxCON1[25:24]) = 
00 - AUDEN bit (SPIxCON1[15]) = 
1 
 - AUDMOD[1:0] bits (SPIxCON1[25:24]) = 
 - Write the desired settings to the SPIxCON1 register:
- MSTEN (SPIxCON1[5]) = 
0 - CKP (SPIxCON1[6]) =
                                
1 - MODE[32,16] (SPIxCON1[11:10]) = 
0for 16-bit audio channel data. - Enable SPI operation by setting the ON bit (SPIxCON1[31]).
 
 - MSTEN (SPIxCON1[5]) = 
 - Transmission (and reception) will start as soon as the host provides the BCLK and LRCK.
 
I2S Client Mode, 16-Bit Channel Data, 32-Bit Frame
/* The following code example will initialize the SPI1 Module in I2S Client mode. */
_SPI1RXIP = 4;
SPI1STATbits.SPIROV = 0;      // clear the Overflow
SPI1CON1=0x80000440;          // AUDEN=1, I2S mode, stereo mode, 
                              // 16 bits/32 channel transfer, Client mode,CKP =1
SPI1IMSKbits.SPIRBFEN = 1;    // SPI1 receive buffer full generates interrupt event
_SPI1RXIE = 1;                // Enable interrupts
SPI1CON1bits.ON = 1;
// from here, the device is ready to receive and transmit data
        