SPI Problem! INTERFACING TWO PICs

Status
Not open for further replies.

RuH_iranga

Junior Member level 3
Joined
Nov 4, 2010
Messages
31
Helped
7
Reputation
14
Reaction score
6
Trophy points
1,288
Location
sri lanka
Activity points
1,480
Dear all

I m trying to communicate two 16f877 PICs with SPI protocol. And USART is used to display the received data from the slave. But my program is not working. I used variable Y=7 in master and send it to slave and then read it from USART. here is my code.
Master
Code:
// code for spi master



void main()
{
trisc.f3=0;
trisc.f4=1;
trisc.f5=0;
trisa.f2=0;
porta.f2=1;

     Spi_Init_Advanced(SLAVE_SS_ENABLE, DATA_SAMPLE_END, CLK_IDLE_LOW, LOW_2_HIGH);
     while(1)
       {
            int y=7  ;
            Spi_Write(y);
            porta.f2=0;
       }
}

Slave
Code:
    // code for spi slave


void main()
{
unsigned int buffer, gdata =0;
buffer=0;

trisa.f5=1;
trisc.f4=1;
trisc.f5=0;
trisc.f3=1;


Usart_Init(2400);
Spi_Init_Advanced(SLAVE_SS_ENABLE, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);

while(1)
{
gdata=Spi_Read(buffer);
Usart_Write(gdata);
}
}

Please could anyone help me, I can not identify what is wrong with my code. I used MikroC compiler.

Thank you.
 

mmmm... I´mnot sure but shouldn't you initialize the master spi as ''master" ?
 
Yes, sometimes That may be the problem, I'll check and currently I can not programming. I'll post my results. Thank you very much
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…