void Config_SPI(void)
{
SCK = 0; // SCK as output
SDO = 0; // SDO as output
SDI = 1; // SDI as input
WP = 0; // WP as O/P
//HOLD = 0; // HOLD as O/P
CS = 0; // CHIP SELECT as O/P
}
void Init_SPI(void)
{
Config_SPI(); // Configuration for SPI Modules.
// SPI Status Control Registers
SPI1STATbits.SPIEN = 0; // Disable the SPI Module.
SPI1STATbits.SPISIDL = 0; // Continue the Operation in Idle Mode.
SPI1STATbits.SRMPT = 0; // SPI shift register is not empty.
SPI1STATbits.SPIROV = 0; // No overflow has occured.
SPI1STATbits.SRXMPT = 0; // RX FIFO not empty
SPI1STATbits.SISEL = 3; // Buffer Interrupt Mode - Interrupt when SPI receive buffer is full.
SPI1STATbits.SPITBF = 0; // Transmit has started, SPIx transmit buffer is empty.
SPI1STATbits.SPIRBF = 0; // Receive is incomplete, SPIx Receive buffer is empty.
// SPI Control Regsiter 1
SPI1CON1bits.DISSCK = 0; // Internal SPI clock is enabled.
SPI1CON1bits.DISSDO = 0; // SDO is controller by module.
SPI1CON1bits.MODE16 = 1; // 1 - 16 bit , 0 - 8 bit mode
SPI1CON1bits.SMP = 1; // Input data is sampled at end of data output time.
SPI1CON1bits.CKE = 0; // Clock Edge Selected
SPI1CON1bits.SSEN = 0; // SSx pin is not used by module, pin is controller by port function.
SPI1CON1bits.CKP = 0; // Idle when clock is low level, active state is high level
SPI1CON1bits.MSTEN = 1; // Master Mode enable bits.
SPI1CON1bits.SPRE = 0; // Secondary prescalar bits.
SPI1CON1bits.PPRE = 0; // Primary Prescalar bits.
SPI1CON2bits.FRMEN = 0; // Framed SPI Support -> 1 - enabled, 0 - disabled.
/*
*/
}