Hi everyone, I am trying to setup a I2C comm between the two PIC18F2620s. The Master writes correctly to the slave, but when it tries to read back, it gets stuck at the "while" statement in the ReadI2C function. unsigned char ReadI2C( void ) { SSPCON2bits.RCEN = 1; // enable master for 1 byte reception while ( !SSPSTATbits.BF ); // wait until byte received return ( SSPBUF ); // return with read byte } I tried many different ways for more than a week now, but none of them works. Both PICs run at 8Mhz crystal + PLL = 32Mhz. I use MCC18 V2.44 with MPLAB 7.21. Please help! Thank you in advance. Master Code: #include #include #include unsigned char Temp1, Temp2; void main (void) { TRISA = 0b00100000; TRISC = 0b11110111; OpenI2C(MASTER, SLEW_OFF); SSPADD = 0x4F; // 100khz @ 32Mhz crystal IdleI2C(); // test for idle condition StartI2C(); IdleI2C(); // test for idle condition WriteI2C(0xA0); // addr byte IdleI2C(); // test for idle condition WriteI2C(0x01); // MSB word address IdleI2C(); // test for idle condition WriteI2C(0x02); // LSB word address IdleI2C(); // test for idle condition StopI2C(); IdleI2C(); // test for idle condition StartI2C(); IdleI2C(); // test for idle condition WriteI2C(0xA1); // addr byte IdleI2C(); // test for idle condition Temp1 = ReadI2C(); // read the byte while ( SSPCON2bits.RCEN ); // check that receive sequence is over SSPCON2bits.ACKDT = 0; // set acknowledge bit state for ACK SSPCON2bits.ACKEN = 1; // initiate bus acknowledge sequence while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over IdleI2C(); // test for idle condition Temp2 = ReadI2C(); // read the byte while ( SSPCON2bits.RCEN ); // check that receive sequence is over SSPCON2bits.ACKDT = 0; // set acknowledge bit state for ACK SSPCON2bits.ACKEN = 1; // initiate bus acknowledge sequence while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over IdleI2C(); // test for idle condition StopI2C(); while (1) { PORTAbits.RA4 = 0; // OFF Delay10KTCYx(200); PORTAbits.RA4 = 1; // ON Delay10KTCYx(200); } } Slave Code: #include #include unsigned char Temp1, Temp2, Status; void main (void) { TRISA = 0b00100000; TRISC = 0b11111111; PIR1 = 0x00; OpenI2C(SLAVE_7, SLEW_OFF); SSPADD = 0xA0; SSPSTAT = 0x00; PIR1bits.SSPIF = 0; PIE1bits.SSPIE = 1; //i2c IPR1bits.SSPIP = 1; // high RCONbits.IPEN = 1; // Enable Priority interrupt INTCONbits.GIEH = 1; // init GIEH INTCONbits.GIEL = 1; // init GIEL while (1) { PORTAbits.RA4 = 0; // OFF Delay10KTCYx(200); PORTAbits.RA4 = 1; // ON Delay10KTCYx(200); } } #pragma interrupt high_isr void high_isr(void) { if (PIR1bits.SSPIF && PIE1bits.SSPIE) // i2c Interrupt { Status = SSPSTAT & 0b00101101; PIR1bits.SSPIF = 0; // clear flag // I2C write operation, last byte was an address byte. if ((Status ^ 0b00001001) == 0) // state1 Temp1 = ReadI2C(); // dummy read // I2C write operation, last byte was a data byte. else if ((Status ^ 0b00101001) == 0) // state2 { Temp1 = Temp2; Temp2 = ReadI2C(); } // I2C read operation, last byte was an address byte. else if ((Status ^ 0b00001100) == 0) // state3 { WriteI2C(0x51); SSPCON1bits.CKP = 1; } // I2C read operation, last byte was a data byte. else if ((Status ^ 0b00101100) == 0) // state4 { WriteI2C(0x52); SSPCON1bits.CKP = 1; } // Slave I2C logic reset by NACK from master. else if ((Status ^ 0b00101000) == 0) // state5 Nop(); } } #pragma code high_vector=0x08 void high_interrupt(void) { _asm GOTO high_isr _endasm } #pragma code --------------------------------- Yahoo! Music Unlimited - Access over 1 million songs. Try it free. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist