PIR1bits.SSP1IF = 0; // clear the slave interrupt flag
i2c_data = SSP1BUF; // read SSPBUF to clear BF
if(1 == SSP1STATbits.R_nW)
{
if((1 == SSP1STATbits.D_nA) && (1 == SSP1CON2bits.ACKSTAT))
{
// callback routine can perform any post-read processing
}
else
{
// callback routine should write data into SSPBUF
}
}
else if(0 == SSP1STATbits.D_nA)
{
slaveWriteType = SLAVE_DATA_ADDRESS;
// this is an I2C address
// callback routine should prepare to receive data from the master
}
else if(1 == SSP1STATbits.P)
{
//经过打印走不到!!
}
else
{
I2C1_slaveWriteData = i2c_data;
switch(slaveWriteType)
{
case SLAVE_DATA_ADDRESS:
eepromAddress = I2C1_slaveWriteData;
break;
case SLAVE_NORMAL_DATA:
default:
// the master has written data to store in the eeprom
break;
} // end switch(slaveWriteType)
slaveWriteType = SLAVE_NORMAL_DATA;
// callback routine should process I2C1_slaveWriteData from the master
}
SSP1CON1bits.CKP = 1; // release SCL
} // end I2C1_ISR()