Change polarity of an EINT inside it irq routine

cancel
Showing results for 
Search instead for 
Did you mean: 

Change polarity of an EINT inside it irq routine

289 Views
alessandromelin
Contributor II

Hello.

As you can read in the title, I am trying to change the polarity of the edge which causes the external interrupt. I am using an LPC2129.

Firstly I configure it as rising edge sensitive and the VIC vectors registers:

PINSEL1 |= (0<<1) | (1<<0);                  //Pin P0.16 as EINT0
EXTMODE |= (1<<0) |;                          //Edge sensitive
EXTPOLAR |= (1<<0) ;                         //Rising edge

VICVectCntl1 = 0x20 |14;                     
VICVectAddr1 =(unsigned)EINT0_isr; 
VICIntEnable |= (1<<14); 
EXTINT |= (1<<0);

Then, in the irq routine I want to change to falling edge sensitive, as the following code:

void EINT0_isr (void) __irq { 

EXTINT |= (1<<0);           //Clear flag
...
EXTPOLAR &= ~(1<<0); //Change to falling edge

...}

This does not work and the program crash.

Then I read this in the manual but I do not understand how to do it:

Note: 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.

So I tried to change the code like this but did not work:

VICIntEnClr |= (1<<14);     
EXTINT |= (1<<0);
EXTPOLAR &= ~(1<<0);
VICIntEnable |= (1<<14); 

Which is the correct way to change edge polarity inside the irq routine of an EINT?

Best regards,

Alessandro

P.S.: sorry for my english.

Labels (2)
0 Kudos
1 Reply

171 Views
soledad
NXP Employee
NXP Employee

Hi, 

Please check the following code as reference: 

/************************************************************/
/* PROJECT NAME: EXTERNAL INTERRUPT */
/* Device: LPC2148 */
/* Filename: ExtInt.c */
/* Language: C */
/* Compiler: Keil ARM */
/* For more detail visit www.binaryupdates.com */
/************************************************************/

#include <LPC214x.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() //Initialize Interrupt
{
EXTMODE = 0x4; //Edge sensitive mode on EINT2

EXTPOLAR &= ~(0x4); //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 int)Ext_ISR; // address of the ISR
VICVectCntl5 = (1<<5) | 16; //
VICIntEnable = (1<<16); // EINT2 interrupt enabled

EXTINT &= ~(0x4);
}

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

EXTINT |= 0x4; //clear interrupt
VICVectAddr = 0; // End of interrupt execution
}

void delay(int count)
{
int j=0,i=0;

for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}

Please check more details in the following link: 

https://binaryupdates.com/external-interrupt-in-lpc2148-arm7/

Regards

Soledad

0 Kudos