Slave I2C

Status
Not open for further replies.

YAN-1

New Member
Hello everyone. I am trying to configure a PIC (16F877A) as a slave in I2C communication with another PIC acting as a master. The slave is driven through interrupts. I wrote my Interrupt Service Routine (ISR) but I was wondering if anyone could take a look at it and check my IF statements that mask the SSPSTAT register to determine what to do. Your reviews are much appreciated. Thanks a lot.

Code (ISR):



static void interrupt
interr (void){

if (SSPIF){
x = SSPSTAT;

//If add was sent with intention of master read
if ((x & 0b00111101) == 0b00001101){
temp = SSPBUF;
SSPOV = 0;}

//If add was sent with intention of master write
if ((x & 0b00111101) == 0b00001001){
temp = SSPBUF;
SSPOV = 0;}

//if data was sent by master
if ((x & 0b00111101) == 0b00101001){
desiredbyte= SSPBUF;
SSPOV = 0;}

//if first byte has been requested by master
if ((x & 0b00111101) == 0b00001100){
SSPBUF = byte1;
CKP = 1;//release the clock line
SSPOV = 0;}

//if another byte is requested by master
if ((x & 0b00111101) == 0b00101100){
SSPBUF = byte2;
CKP = 1; //release the clock line
SSPOV = 0;}

SSPIF = 0;
}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…