Kerry -
Here is the code for the slave initialization and interrupt handler.
This interrupt handler follows the slave path in the flowchart provided in the operators manual.
Slave initialization:
void initializeHWI2C(void)
{
if(boardID == 0){
I2C0_F_bit.MULT = 0x01;
I2C0_F_bit.ICR = 0x18;
}
PORTB_PCR3_bit.MUX = 2;
PORTB_PCR4_bit.MUX = 2;
I2C0_A1_bit.AD = boardID;
I2C0_C1_bit.IICEN = 1;
I2C0_C1_bit.IICIE = 1;
I2C0_C1_bit.WUEN = 1; //12-5 JLG to wakeup without peripheral clocks running
I2C0_FLT_bit.SSIE = 1;
NVIC_EnableIRQ(I2C_IRQ);
I2C0_C1_bit.TX = 1;
I2C0_C2_bit.ADEXT = 1;
I2C0_C2_bit.AD = 0; //extended 10-bit addr 10:8
}
Slave IRQ handler:
void I2C0_IRQHandler(void)
{
unsigned char dummy;
if(I2C0_FLT_bit.STOPF){
I2C0_FLT_bit.STOPF = 1;
I2C0_S_bit.IICIF = 1;
if(i2cRxCounter > 1){
dataReady = 1;
}
i2cRxCounter = 0;
i2cTxCounter = 0;
startCount = 0;
return;
}
if(I2C0_FLT_bit.STARTF){
I2C0_FLT_bit.STARTF = 1;
I2C0_S_bit.IICIF = 1;
startCount++;
if(startCount <= 1)
return;
}
else{
I2C0_S_bit.IICIF = 1;
}
if((i2cReadFlag > 1) && (i2cTxCounter==3) && (I2C0_C1_bit.TX == 1)){
I2C0_C1_bit.TXAK = 0;
I2C0_C1_bit.TX = 0;
dummy = I2C0_D_bit.DATA;
return;
}
// Master Mode
if(I2C0_C1_bit.MST){
// Tx
if(I2C0_C1_bit.TX){
// Last byte transmitted?
if(i2cTxCounter >= i2cTxTotalBytes){
I2C0_C1_bit.MST = 0;
}
else{
// RXAK = 0?
if(I2C0_S_bit.RXAK == 0){
if((i2cTxCounter == 2) && (i2cReadFlag==1)){
I2C0_C1_bit.RSTA = 1;
i2cReadFlag++;
}
else{
I2C0_D_bit.DATA = I2C_Tx_Buffer[i2cTxCounter++];
}
}
else{
I2C0_C1_bit.MST = 0;
}
}
}
// Rx
else{
if(i2cRxCounter >= i2cRxTotalBytes){
I2C0_C1_bit.MST = 0;
rxComplete = 1;
}
else if((i2cRxCounter+1) == i2cRxTotalBytes){
I2C0_C1_bit.TXAK = 1;
}
else{ }
I2C_Rx_Buffer[i2cRxCounter++] = I2C0_D_bit.DATA;
}
}
// Slave Mode
else{
if(I2C0_S_bit.IAAS){
if(I2C0_S_bit.SRW == 1){
I2C0_C1_bit.TX = 1;
updateI2Ccommand();
I2C0_D_bit.DATA = I2C_Tx_Buffer[i2cTxCounter++];
}
else{
I2C0_C1_bit.TX = 0;
dummy = I2C0_D_bit.DATA;
}
}
else{
if(I2C0_S_bit.SRW){
if(I2C0_S_bit.RXAK==0){
I2C0_D_bit.DATA = I2C_Tx_Buffer[i2cTxCounter++];
}
else{
I2C0_C1_bit.TX = 0;
dummy = I2C0_D_bit.DATA;
}
}
else{
I2C_Rx_Buffer[i2cRxCounter++] = I2C0_D_bit.DATA;
}
}
}
}
The following waveforms are a slave write (left) and slave read (right). The slave address is 0b0000000001.


From reference manual:
