pic spi slave
Hi,
I have attached my circuit which i have used, Slave select is controlled by master before starting my communication. This is my master and slave spi initiallisations
SPI Initialization with respect to Master (Pic 18F8722)
void InitSPI_Master(void)
{
TRISDbits.TRISD6 = 0; // Define clock pin as output
TRISDbits.TRISD5 = 1; // Define SDI as Input
TRISDbits.TRISD4 = 0; // Define SDO as Output
TRISDbits.TRISD7 = 0; // Define chip select as output
SSP2STATbits.SMP = 0; // Sampled at the Middle
SSP2STATbits.CKE = 1; // Data Transmitted on Falling Edge
SSP2CON1 = 0x22; /* Configures SDo, SDI,SCK and SS pins as serial port pins. Clock idle state Low and FOSC/64 */
INTCONbits.INT0IE = 0; // INT0 External Interrupt Disable bit
INTCONbits.INT0IF = 0;
INTCON2bits.RBPU =1 ; // Disable Pullups
INTCON2bits.INTEDG0 =1; // Interrupt on Rising Edge
}
SPI Initialization with respect to Slave (Pic 18F2525)
void InitSPI_S(void)
{
TRISCbits.TRISC5 = 0; // Define SDO pin as output
TRISCbits.TRISC4 = 1; // Define SDI as Input
TRISCbits.TRISC3 = 1; // Define SCK as Input
TRISAbits.TRISA5 = 1; // Define chip select as Input
SSPSTATbits.SMP = 0; // Cleared in Slave Mode
SSPSTATbits.CKE = 1; // Data Transmitted on Falling Edge
SSPCON1 = 0x24; /* Configures SDo, SDI,SCK and SS pins as serial port pins. Slave mode and SS controlled */
INTCONbits.INT0IE = 0; // INT0 External Interrupt Disable bit
INTCONbits.INT0IF = 0;
INTCON2bits.RBPU =1 ; // Disable Pullups
INTCON2bits.INTEDG0 =1; // Interrupt on Rising Edge
}