Searching \ for '[PIC]: I2c comm between pics' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'I2c comm between pics'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: I2c comm between pics'
2001\04\15@185025 by Ronald Cotton

picon face
Please help,
I have configured 2 pics 16f877(slave) and 16f874(master) with what I think the proper setup is for I2c communication.

I can get the master to communicate with a slave that is 24lc01B; however, using the code that I have attached for the slave(877), I can not get the slave to respond. I have included the I2C setup code and the ISR for the slave.  Can anyone tell me what is wrong ?  Sorry for the horrible formatting.


#define STATE1 0X09
#define STATE2 0x29
#define STATE3 0x0c
#define STATE4 0x2c
#define STATE5 0x28
#define FALSE 0
#define TRUE 1
char data[4];
static char index;
void I2C_Setup(void)
   index =0; // Clear Index
   PIR1 =0; // Clear Interrupt Flag Register
   TRISC3 =1; // C3 is an input
   TRISC4 =1; // C4 is an input
   SSPCON = 0X36; // Setup SSP Module for 7-bit
   SSPADD = 0X0A; // Address for this Device 5
   SSPSTAT = 0X00; // Clear the Status Register
   SSPIE = 1; // Allow Interrupts FROM I2C

void main(void)
   I2C_Setup(); // Routine to initialize interrupts and all I2C registers
   while(1)        // loop forever


static void interrupt ISR(void)
char stat,counter,send,away;
static char FIRST;

if(SSPIF)        // Is this an I2c interrupt
       SSPIF =0; // Clear Interrupt Flag
       stat = 0x2d & SSPSTAT; // stat contains the current state of the I2C         switch(stat)
case STATE1: // Write operation, last byte was an address

for (counter=0;counter<=4;counter++)
data[counter]=0; // Clear Buffer
index =0; // Clear Buffer Index
away = SSPBUF; // Got read SSPBUF to clear Interrupt
// throw-away; this only acks.
FIRST = TRUE; // Start process

case STATE2: // Write Operation, last byte was data

       away = SSPBUF; // Get Value
       if(FIRST) // Address {
       FIRST =FALSE; // Got Address so No Longer First
       index = (25-away)-1; // Calculate Index value Index=0....4
       if(index>4) // Check to see if we have overrun the buffer
       index =0;
       data[index] = away; // Real Data, gotta save this
       ++index; // Increment pointer


case STATE3: // Read Operation, last byte was an address
   index =0; // Clear Index
   away = data[index]; // Retrieve Data from buffer     SSPBUF = away; // Write Data to Master
   ++index; // Increment Index
case STATE4: // Read Operation, last byte was data
// Send info to master
index = 0; // Reset Index
SSPBUF = data[index]; // Retrieve Data from buffer

++index; // Increment Index
case STATE5: // NACK Received from the Master
FIRST = FALSE; // Reset whether an address or data

-- Going offline? Don't AutoReply us!
email with SET PICList DIGEST in the body

2001\04\17@100025 by Michael Rigby-Jones

Started to wade through this and the first thing I have noticed is that you
are not setting the CKP bit after putting data into SSPBUF for transmision.
If this bit is not set, the PIC will hold the SCL line forever.



> {Original Message removed}

2001\04\17@101024 by Ronald Cotton

After reviewing AN734, I also found that I was not setting CKP;however, I
still can not communicate.


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...