init External Interrupt on LPC213x/4x

1

Hi I write code below for initial External Interrupt for LPC2138 in KEIL 4.7 Compiler and when run code in proteus software , code dosent Work. I double check VIC and EXTINT registers seems correct. thanks

Project Picture on Proteus

one Switch on EXTINT2 (P0.15) and one LED on P1.25

#include <LPC213x.h>  

void delay(int count);
void init_ext_interrupt(void);
__irq void Ext_ISR(void);

int main (void) 
{
  init_ext_interrupt();   // initialize the external interrupt

  while (1)  
  {     
    }
}

void init_ext_interrupt(void)  //Initialize Interrupt
{
  EXTMODE = (1<<2);     //Edge sensitive mode on EINT2 
  EXTPOLAR &= ~(1<<2);  //Falling Edge Sensitive
  PINSEL0 = 0x80000000; //Select Pin function P0.15 as EINT2 
  /* initialize the interrupt vector */
  VICIntSelect &= ~(1<<16);        // EINT2 selected as IRQ 16
  VICVectAddr5 = (unsigned)Ext_ISR; // address of the ISR
  VICVectCntl5 = (1<<5) | 16;            
  VICIntEnable = (1<<16);           // EINT2 interrupt enabled

  EXTINT &= ~(1<<2);    //Set interrupt
}

__irq void Ext_ISR(void) // Interrupt Service Routine-ISR 
{
 IO1DIR |= (1<<25);
 IO1SET |= (1<<25); // Turn ON LED
 delay(100000);
 IO1CLR |= (1<<25); // Turn OFF LED

 EXTINT |= (1<<2);  //clear interrupt
 VICVectAddr = 0;   // End of interrupt execution
}

void delay(int count)
{
  int j=0,i=0;
  for(j=0;j<count;j++)
  {
    for(i=0;i<35;i++);
  }
}
arm
interrupt
asked on Stack Overflow May 6, 2016 by Hosain Shoja

1 Answer

0

You should correct the line:

(VICVectCntl5 = (1<<5) | 16;)

to:

(VICVectCntl5 = 0x20 | 16;) 

as datasheet said.

answered on Stack Overflow Aug 17, 2018 by Nikoo • edited Aug 17, 2018 by Stephen Rauch

User contributions licensed under CC BY-SA 3.0