pic16f877a spi communication

Status
Not open for further replies.

sairyuva

Newbie level 4
Joined
Mar 19, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
i want to communicate 2 pic16f877a with spi protocol
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;
}

 

Can I get to know what problem you are facing, I am trying to do same but the problem is the Txn stops when the first Transmission is completes.
 

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…