May 8, 2010 #1 S 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; }
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; }
Mar 15, 2012 #2 S Sridutt Newbie level 1 Joined Mar 15, 2012 Messages 1 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,284 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.
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.
Sep 12, 2012 #3 M madhusuthanan Full Member level 3 Joined Jan 3, 2012 Messages 188 Helped 8 Reputation 16 Reaction score 8 Trophy points 1,298 Location madurai Activity points 1,963 you missed the pull up resistor at pin 23 & 24.