Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top