I'm doing spi interfacing between two pic18F452 microcontrollers in mikroC but my program doesn't give any output. I send a data from Master and slave have to display it on LCD.
Here is my code for both master and slave:
MASTER CODE:
unsigned char key='a';
void main(void)
{
TRISC.F2=0; //output for Slave select
TRISC.F3=0; //SCK output
TRISC.F4=1; //SDI input
TRISC.F5=0; //SDO output
Spi_Init_Advanced(Master_OSC_div64, Data_SAMPLE_MIDDLE, CLK_Idle_HIGH, HIGH_2_LOW);
SSPCON1.SSPEN=1; //Synchronus serial port enable
SSPSTAT.SMP=0; //sampled at middle of data output time
while(1)
{
PORTC.F2=0;
SSPBUF=key;
while(!SSPSTAT.bf);
spi_write(key);
}
}
///////end//////
SLAVE CODE:
#define LCD PORTB
unsigned char key;
void main(void)
{
TRISB=0; //LCD output
TRISC.F4=1; //SDI input
TRISC.F3=1; //SCK input from master
TRISC.F5=0; //SDO output
TRISA.F5=1; //Slave select input from master
SSPSTAT.SMP=0; //input data sampled at middle
SSPSTAT.CKE=0; // transition from idle to active
SSPCON1.=0x22;
Spi_Init_Advanced(SLAVE_SS_ENABLE, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
Lcd_init(&PORTB);
Lcd_cmd(Lcd_clear);
Lcd_cmd(Lcd_cursor_off);
while(1)
{
if(SSPSTAT.BF)
{
key=spi_read(SSPBUF);
}
}
}
////////end///////
i am not sure about this part
Lcd_init(&PORTB);
Lcd_cmd(Lcd_clear);
Lcd_cmd(Lcd_cursor_off);
try declaring your lcd port like this . i use port d
and for initing and clearing
that delay part might comes handy some times.