wilsonz91
Newbie level 3
Question for SPI
Hello,
i am trying to interface two PIC18F8722 with each other using SPI. I manage to get it going (one way communication) doing a simple countdown but there some problems which I could not find a solution to.
here is the code for:
master
Slave:
Connections are:
master slave
RC3 -> RC3 (SCK)
RC5 -> RC4 (master out to slave in)
RC4 -> RC5 (slave out to master in)
What I am trying to achieve is two-way communication where both master and slave would be counting down eg master-255, slave-254,master-253,slave,252.
Please advice, thank you =)
Hello,
i am trying to interface two PIC18F8722 with each other using SPI. I manage to get it going (one way communication) doing a simple countdown but there some problems which I could not find a solution to.
here is the code for:
master
Code:
#include <p18f8722.h>
#include "spi.h"
#include <delays.h>
void main()
{
unsigned char a = 0xFF,b;
TRISC = 0xD7;
TRISF = 0x00;
OpenSPI1(SPI_FOSC_4, MODE_01, SMPMID);
while(1){
WriteSPI1(a);
while(!DataRdySPI());
b=ReadSPI1();
LATF = b;
Delay10KTCYx(200);
a--;
if (a==0)
a = 0xFF;
}
}
Slave:
Code:
#include <p18f8722.h>
#include "spi.h"
void main()
{
unsigned char a;
TRISC = 0x1F;
TRISF = 0x00;
OpenSPI1(SLV_SSOFF, MODE_01, SMPMID);
LATF = ReadSPI1(); [I]//without this line, SPI would not work. why? wouldn't having this line in the while loop be sufficient?[/I]
while(1){
while(!DataRdySPI1());
a = ReadSPI1();
LATF = a;
a--;
WriteSPI1(a);
if (a == 0)
a = 0xFF;
}
}
Connections are:
master slave
RC3 -> RC3 (SCK)
RC5 -> RC4 (master out to slave in)
RC4 -> RC5 (slave out to master in)
What I am trying to achieve is two-way communication where both master and slave would be counting down eg master-255, slave-254,master-253,slave,252.
Please advice, thank you =)
Last edited: