sairyuva
Newbie level 4
i want to communicate 2 pic16f877a with spi protocol
i couldn't get far with this code
i couldn't get far with this code
Code:
/****spi stuff***/
/*master @ 20MHz*/
#include<htc.h>
__CONFIG(HS & BORDIS & LVPDIS & PWRTEN & WDTDIS);
unsigned char data=0xff;
void init()
{
SSPEN=1;
TRISC5=0; //sd0
TRISC3=0; //sck
TRISC4=1;
SMP=1;
CKE=1;
SSPCON=0x30;
TRISB=0x00;
PORTB=0x00;
SSPIF=0;
ei();
PEIE=1;
SSPIE=1;
}
void main()
{
init();
while(1)
{
PORTB=data;
while(BF);
SSPBUF=data;
}
}
void interrupt isr(void)
{
if(SSPIF)
{
SSPIF=0;
BF=0;
}
}
Code:
/****spi stuff***/
/*slave @ 20MHz*/
#include<htc.h>
__CONFIG(HS & BORDIS & LVPDIS & PWRTEN & WDTDIS);
unsigned char data;
void init()
{
TRISC5=0; //sd0
TRISC3=1; //sck
TRISC4=1;
SMP=0;
CKE=1;
SSPCON=0x30;
SSPEN=1;
SMP=0;
TRISB=0x00;
PORTB=0x00;
SSPOV=0;
SSPIF=0;
ei();
PEIE=1;
SSPIE=1;
}
void main()
{
init();
while(1)
{
if(BF)
data=SSPBUF;
BF=0;
PORTB=data;
}
}
void interrupt isr(void)
{
if(SSPIF)
{
// if(BF)
}
SSPIF=0;
}