#include <LPC213X.H>unsignedint I2Caddress;//global variable for addressunsignedint I2Cdata;//global variable for dataunsignedchar*message;void i2c_isr(void)__attribute__((interrupt("IRQ")));//interrupt service routinevoid i2c_transfer_byte(unsigned add,unsigned data);//function for transferring bytesvoid i2c_receive_byte(void);//function for receivingvoid i2c_init()//I2C initialization{
VICVectCntl1=0X00000029;// vectored control pin for I2C
VICVectAddr1=(unsigned)i2c_isr;//passing IRQ address to the VIC slot
VICIntEnable =0x00000200;//enable interrupt
PINSEL0|=0X50;//selecting pin for I2C
I2C0SCLL=0X08;//for a frequency of 57.6 KHz
I2C0SCLH=0X08;}void i2c_transfer_byte(unsigned add,unsigned data){
I2Caddress=add;
I2Cdata=data;
I2C0CONCLR=0X000000FF;//clear all I2c settings
I2C0CONSET=0X00000040;//enable I2C
I2C0CONSET=0X00000020;//start condition}void i2c_isr(void){switch(I2C0STAT){case(0X08): I2C0CONCLR=0X20;//clear start bit
I2C0DAT=I2Caddress;break;case(0X18): I2C0DAT=I2Cdata;//send data break;case(0X20):I2C0DAT=I2Caddress;//resend slave address+Wbreak;case(0X28):I2C0CONSET=0X00000010;//stop conditionbreak;}
I2C0CONCLR=0X08;//i2c interrupt clear bit
VICVectAddr=0X00000000;//clear all interrupts}void i2c_receive_byte(void){switch(I2C0STAT){case(0X40):I2C0CONSET=0x04;//SLAVE +READ+ackbreak;case(0X48):I2C0CONSET=0X20;//resend start conditionbreak;case(0X50):*message=I2C0DAT;//receive data into message buffer
I2C0CONSET=0X10;break;case(0X58):I2C0CONSET=0X20;//data received ,resend start conditionbreak;}}int main(){int addr=0X00;
i2c_init();
i2c_transfer_byte(addr,'R');
i2c_receive_byte();
i2c_isr();}
by executing above code the interrupt enable bit is not getting set though i declared in the i2c_init function as well on the keil i2c module data is shown only received with the value shown 02!