This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C interrupts

This is the example code i used for the simulation in keil.

after runs the simulation, the status reg changes to 0x08, but not entering to interrupt service routine.

#include <LPC21xx.H>

unsigned char I2CAddress;
unsigned char I2CData;


void I2CISR (void)              // I2C interrupt routine
{
switch (I2STAT)                 // Read result code and switch to next action
{
case ( 0x08):                   // Start bit
I2CONCLR = 0x28;        // Clear start bit
I2DAT = I2CAddress;     // Send address and
                                                // write bit
break;
case (0x18):                    // Slave address+W, ACK
I2DAT = I2CData;                 // Write data to tx register
 break;
case (0x20):                    // Slave address +W, Not ACK
I2DAT = I2CAddress;     // Resend address and write bit
 break;
case (0x28):                    // Data sent, Ack
I2CONSET = 0x10;                // Stop condition
 break;
 default :
 break;
 }

I2CONCLR = 0x08;   // Clear I2C interrupt flag
VICVectAddr = 0x00000000; // Clear interrupt in
}

void init()
{

VICVectCntl1 = 0x00000029;       // select a priority slot for a given interrupt
VICVectAddr1 = (unsigned)I2CISR;
VICIntEnable = 0x00000200;
PINSEL0 = 0x50;
I2SCLH  = 0x08;
I2SCLL  = 0x08;

}

void I2CTransferByte(unsigned Addr,unsigned Data) {

I2CAddress = Addr; // Place address and data in Globals to be used by
                                        // the interrupt
I2CData = Data;
I2CONCLR = 0xFF; // Clear all I2C settings
I2CONSET = 0x40; // Enable the I2C interface
I2CONSET = 0x20; // Start condition
}



void main()
{
init();
I2CTransferByte(0x81,0x90);

while(1);

}