Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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.
 

Kurenai_ryu

Advanced Member level 2
Joined
Jun 10, 2006
Messages
671
Helped
159
Reputation
316
Reaction score
99
Trophy points
1,308
Location
Bolivia
Activity points
5,913
mmmm... I´mnot sure but shouldn't you initialize the master spi as ''master" ?
 

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
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top