keil_examples/i2cslave/i2cslave1.c
/*****************************************************************************
** Function name:		I2C_IRQHandler
**
** Descriptions:		I2C interrupt handler, deal with master mode only.
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
Function name:         I2C_IRQHandler
Descriptions:          I2C interrupt handler, deal with master mode only.

None
Returned value:                None
Function name : I2C_IRQHandler Descriptions : I2C interrupt handler deal with master mode only . None Returned value : None
void I2C1_IRQHandler(void) 
{
  uint8_t StatValue;
  StatValue = LPC_I2C1->STAT;
  switch ( StatValue )
  {
	case 0x60:					
	case 0x68:
	RdIndex = 0;
	LPC_I2C1->CONSET = I2CONSET_AA;	
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	I2CSlaveState = I2C_WR_STARTED;
	break;
	case 0x80:					
	case 0x90:
	if ( I2CSlaveState == I2C_WR_STARTED )
	{
	  I2CRdBuffer[RdIndex++] = LPC_I2C1->DAT;
	  LPC_I2C1->CONSET = I2CONSET_AA;	
	}
	else
	{
	  LPC_I2C1->CONCLR = I2CONCLR_AAC;	
	}
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	break;
	case 0xA8:					
	case 0xB0:
	RdIndex = 0;
	LPC_I2C1->CONSET = I2CONSET_AA;	
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	I2CSlaveState = I2C_RD_STARTED;
	WrIndex = I2CRdBuffer[0];	
	break;
	case 0xB8:					
	case 0xC8:
	if ( I2CSlaveState == I2C_RD_STARTED )
	{
	  LPC_I2C1->DAT = I2CRdBuffer[WrIndex+1];
	  WrIndex++;							
	  LPC_I2C1->CONSET = I2CONSET_AA;		
	}
	else
	{
	  LPC_I2C1->CONCLR = I2CONCLR_AAC;		
	}	
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	break;
	case 0xC0:					
	LPC_I2C1->CONCLR = I2CONCLR_AAC;			
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	I2CSlaveState = DATA_NACK;
	break;
	case 0xA0:					
	LPC_I2C1->CONSET = I2CONSET_AA;	
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	I2CSlaveState = I2C_IDLE;
	break;
	default:
	LPC_I2C1->CONCLR = I2CONCLR_SIC;
	LPC_I2C1->CONSET = I2CONSET_I2EN | I2CONSET_SI;	
	break;
  }
  return;
}
void I2C1_IRQHandler ( void ) { uint8_t StatValue ; StatValue = LPC_I2C1 -> STAT ; switch ( StatValue ) { case 0x60 : case 0x68 : RdIndex = 0 ; LPC_I2C1 -> CONSET = I2CONSET_AA ; LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; I2CSlaveState = I2C_WR_STARTED ; break ; case 0x80 : case 0x90 : if ( I2CSlaveState == I2C_WR_STARTED ) { I2CRdBuffer [ RdIndex ++ ] = LPC_I2C1 -> DAT ; LPC_I2C1 -> CONSET = I2CONSET_AA ; } else { LPC_I2C1 -> CONCLR = I2CONCLR_AAC ; } LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; break ; case 0xA8 : case 0xB0 : RdIndex = 0 ; LPC_I2C1 -> CONSET = I2CONSET_AA ; LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; I2CSlaveState = I2C_RD_STARTED ; WrIndex = I2CRdBuffer [ 0 ] ; break ; case 0xB8 : case 0xC8 : if ( I2CSlaveState == I2C_RD_STARTED ) { LPC_I2C1 -> DAT = I2CRdBuffer [ WrIndex + 1 ] ; WrIndex ++ ; LPC_I2C1 -> CONSET = I2CONSET_AA ; } else { LPC_I2C1 -> CONCLR = I2CONCLR_AAC ; } LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; break ; case 0xC0 : LPC_I2C1 -> CONCLR = I2CONCLR_AAC ; LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; I2CSlaveState = DATA_NACK ; break ; case 0xA0 : LPC_I2C1 -> CONSET = I2CONSET_AA ; LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; I2CSlaveState = I2C_IDLE ; break ; default : LPC_I2C1 -> CONCLR = I2CONCLR_SIC ; LPC_I2C1 -> CONSET = I2CONSET_I2EN | I2CONSET_SI ; break ; } return ; }
Function name:         I2C_IRQHandler
Descriptions:          I2C interrupt handler, deal with master mode only.
Function name : I2C_IRQHandler Descriptions : I2C interrupt handler deal with master mode only .
/* this handler deals with master read and master write only */ /* An own SLA_W has been received. */ /* assert ACK after SLV_W is received */ /*  data receive */ /* assert ACK after data is received */ /* assert NACK */ /* An own SLA_R has been received. */ /* assert ACK after SLV_R is received */ /* The 1st byte is the index. */ /* Data byte has been transmitted */ /* write the same data back to master */ /* Need to skip the index byte in RdBuffer */ /* assert ACK  */ /* assert NACK  */ /* Data byte has been transmitted, NACK */ /* assert NACK  */ /* Stop condition or repeated start has */ /* been received, assert ACK.  */