Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: External Interrupt

2004-06-07 by mjbcswitzerland

Hi

Did you solve your problem with ext. ints?

Below is an extract of code which works (assuming defines are 
understood).

Application calls fnEnableOneShotInterrupt() to enable the interrupt 
on a port (LPC2106 example for INT 0).

One thing to note is that the interrupt is level sensitive and so if 
it is being used to detect a button press or something like this, 
the interrupt will keep coming as long as the button is pressed. For 
this reason the interrupt routine in this case sets the normal port 
function so that the interrupt doesn't arrive anymore.
 
Cheers

Mark Butcher
www.mjbc.ch


/**********************************************/

static void fnEnableOneShotInterrupt(void)
{
  __disable_interrupt();      
    LPC210xInitExternalInterrupt0(fnEint0Interrupt);            /* 
prepare interrupt on EINT0 - level sensitive only */
    EXTINT_bit.EINT0 = 1;                                       // 
Try to reset external interrupt flag.    
    LPC210xInitEINT0();                                         /* 
enable the interrupt */
  __enable_interrupt(); 
}




/* ext. sub routines and defines */

#define VIC_EINT0_bit  (1 << VIC_EINT0)


static void (*eint0_function)();

void LPC210xInitExternalInterrupt0(void(*eint0_func)())
{
  // Setup eint0 callback function.
  eint0_function = eint0_func;

  VICIntSelect &= ~VIC_EINT0_bit;  // IRQ on external int 0.
  VICVectAddr2 = (unsigned int)&ExternalInterrupt0;
  VICVectCntl2 = 0x20 | VIC_EINT0; // Enable vector interrupt for 
EINT 0.
  VICIntEnable = VIC_EINT0_bit;    // Enable EINT 0 interrupt.
}



void LPC210xInitEINT0()
{
  PINSEL1_bit.P0_16=0x1; // Set pin function to EINT0
}



/* interrupt routine */
/* when a level 0 is detected on INT 0 - P0.16 this routine is 
called */
/* we disable the interrupt after detection otherwise the routine is 
reentered until a 1 is detected (level sensitive) */
static void ExternalInterrupt0()
{
  PINSEL1_bit.P0_16=0;    // Set pin function to normal 
  (*eint0_function)();    // Call external interrupt callback 
function.
  EXTINT_bit.EINT0 = 1;   // Reset external interrupt flag.   
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.