Page 1 of 1

Configuring External Interrupt in LPC2148

Posted: Sat Mar 03, 2018 7:38 am
by Athul
Hi,

As part of my project, I am using a metal detector, which is configured as an external interrupt in Slot0. when I run the program for the first time, the controller executes the code in the interrupt subroutine instead of the main program even though interrupt is not triggered, I guess it's because of the internal pull-up of EINT0. I have to make the input high and then low to return to the main function. After that interrupt works as it is supposed to (Only executing ISR when interrupt occurs).
What can I do about this?
Is there a way to disable internal pull up(like in Arduino?)
Controller : LPC2148
Keil4
Code: Select all
#define BUZZER (1<<18)

__irq void isr()
{
   IOSET1 |= BUZZER;
   delay_ms(1000);
   IOCLR1 |= BUZZER;
   EINT = 0X01;
   VICVectAddr = 0;
}

int main()
{
   PINSEL1 |= 0X01;
   PINSEL2 |= 0;
   IODIR1 |= BUZZER;

   VICIntSelect = (0 << 14);
   VICVectcntl0 = 0X2E;
   VICVectAddr0 = (unsigned)isr;
   VICIntEnable = (1 << 14);

   INTWAKE = 0;
   EXTMODE = 0X01;
   EXTPOLAR = 0X01;

   while(1)
   {
          /*main codes*/
   }
}

Re: Configuring External Interrupt in LPC2148

Posted: Sun Mar 04, 2018 7:18 am
by paulvha
I am not sure there is a pull-up as they call out those situations specifically in the datasheet, but there are important remarks around setting EXTMODE and EXTPOLAR

(page29)
Software should only change a bit in this register when its interrupt is disabled in the VICIntEnable register, and should write the corresponding 1 to the EXTINT register before enabling (initializing) or re-enabling the interrupt, to clear the EXTINT bit that could be set by changing the mode

Software should only change a bit in this register when its interrupt is disabled in the VICIntEnable register, and should write the corresponding 1 to the EXTINT register before enabling (initializing) or re-enabling the interrupt, to clear the EXTINT bit that could be set by changing the polarity

Maybe that can do the trick.

regards,
Paul

Re: Configuring External Interrupt in LPC2148

Posted: Sun Mar 04, 2018 11:50 pm
by Athul
Thanks for the reply
I have changed the values of EXTMODE and EXTPOLAR to trigger interrupt for rising edge falling edge and level sensitive triggering. But no matter what i do interrupt program executes first

Re: Configuring External Interrupt in LPC2148

Posted: Mon Mar 05, 2018 3:06 am
by paulvha
did you move them in your code to before the line VICIntEnable = (1 << 14); to something like this :
Code: Select all
#define BUZZER (1<<18)

__irq void isr()
{
   IOSET1 |= BUZZER;
   delay_ms(1000);
   IOCLR1 |= BUZZER;
   EINT = 0X01;
   VICVectAddr = 0;
}

int main()
{
   PINSEL1 |= 0X01;
   PINSEL2 |= 0;
   IODIR1 |= BUZZER;

   VICIntSelect = (0 << 14);
   VICVectcntl0 = 0X2E;
   VICVectAddr0 = (unsigned)isr;

   INTWAKE = 0;
   EXTMODE = 0X01;
   EXTPOLAR = 0X01;

   EINT = 0X01;    // clear any pending interrupt

   VICIntEnable = (1 << 14);

   while(1)
   {
          /*main codes*/
   }
}

Re: Configuring External Interrupt in LPC2148

Posted: Wed Mar 07, 2018 11:49 am
by Athul
There was some error in my code(register was EXTINT, not EINT).
Code: Select all
#include <LPC214X.H>


#define BUZZER (1<<18)

int i;

__irq void isr()
{
   IOSET1 |= BUZZER;
   for(i=0; i<1000000;i++);
   IOCLR1 |= BUZZER;
   EXTINT = 0X01;
   VICVectAddr = 0;
}

int main()
{
   PINSEL1 |= 0X01;
   PINSEL2 |= 0;
   IODIR1 |= BUZZER;

   VICIntSelect = (0 << 14);
   VICVectCntl0 = 0X2E;
   VICVectAddr0 = (unsigned)isr;
   VICIntEnable = (1 << 14);

   INTWAKE = 0;
   EXTMODE = 0X01;
   EXTPOLAR = 0X01;
   EXTINT = 0X01; //clear any pending interrupt

   while(1)
   {
          /*main codes*/
   }
}
TClering any prior interrupt would work for falling edge and rising edge (EXTMODe = 0X01), but not for level sensitive (EXTINT = 0X00);

In Keil debugger pins are HIGH initially, which would trigger Interrupt.