Tuesday, October 6, 2009

INTERRUPT SERVICE ROUTINE (IRQ)

******************INTERRUPT SERVICE ROUTINE (IRQ) **************

IRQ Driver:::::::: I2C
MASTER ::::::: LPC2368 (ARM 7)

Do’s & Don’ts of ISR: 1. The variables declared inside an Interrupt should be declared using "volatile" Keyword . Only after declaring "volatile" , user may get the desired output . for eg : global var declaration area : volatile unsigned char MasterBuff[23] = {0}; __irq void I2C_IRQHnadler(void) { ...................... ...................... MasterBuff[Index] = I21DAT ; } 2. Before the termination of ISR block , please clear the I2C Interrupt Flag and Acknowledge the Interrupt like shown below . eg : __irq void I2C_IRQHnadler(void) { ..................................... ..................................... I21CONCLR=0x08; /*Clear Interrupt Flag */ VICVectAddr = 0; /*Acknowledge Interrupt */ } 3. Always Clear the I2C Interrupt Registers before Initializing it to some desired value . 4. While Initializing I2C Interrupt follow this order, First Set the Priority of the ISR '1' is Highest Priority and '15' is lowest priority , then Enable the specific Vector Address bit for powering on the desired ISR(like UART,Timer,I2C,etc.,) block . 5.Considering the I2C IRQ , it is basically a state machine where we have unique states for generating repeated start , read/write operation etc.,So under each states we have to follow the desired protocol for setting values in I2C Interrupt Registers as in the data sheet . 6. Always make sure before using any registers that belong to I2C , clear everything in the main() routine.

7. Do not Call any function inside an IRQ , this will result in malfunctioning of the whole routine . Let the IRQ be as small as possible .

Please feel free to add comments and suggestions on the above issues of Interrupts .

Adidos !Regards,
Samjith.***************************************

No comments: