Input Interrupts

-deleted-
15 Mar 2010

HI,

I was reading the GPIO section in the user manual (section 5.6 specifially) and there is mention of interrupting on any pin in any state (rise/fall).  I know that the library allow for this but I am more interested in where this handler is located.  In the file startup_LPC17xx.s I see the default handler for EINT0...3 but those seem to be only for certian pins.  Any help would be appreciated.  I would like to write my own handler that is not depentant on the mbed library.  Thanks!

15 Mar 2010

GPIO interrupt is shared with EINT3. Just declare your handler like this:

extern "C" EINT3_IRQHandler()
{
// code here
}

and it will take priority over the one in startup file (since that one is declared weak).

InterruptIn class uses NVIC_SetVector() to hook the interrupt dynamically.

15 Mar 2010

Could the same thing be done for EINT2 as I need two external interrupt sources in my application?

 

15 Mar 2010

If you mean declaring the interrupt handler for the EINT2 pin, yes, it will (please note that EINT2 is not connected on the mbed board; you'd have to solder your wire directly to the chip).

If you mean using EINT2 as a handler for another GPIO interrupt, it doesn't work like that. All GPIO interrupts will arrive to the GPIO (=EINT3) handler. You will need to check the interrupt status register to distinguish them. E.g. (stolen from John Robbins):

// check if we have rising edge interrupt on P0.24 
if ( LPC_GPIOINT->IO0IntStatR & (1 << 24) )
{
   // turn on P1.18 = LED1
   LPC_GPIO1->FIOSET = 1<<18;
   // clear P0.24 interrupt
   LPC_GPIOINT->IO0IntClr = (1<<24);
   // turn off LED1
   LPC_GPIO1->FIOCLR = 1<<18;
}
For details, see "GPIO Interrupt Registers" in the user manual (Chapter 9, 5.6).

15 Mar 2010

So near but so far!

I looked at the board again under a magnifier and there seems to be already a connection to pin51 (p2.12) but no connection to pin52 (P2.11).

If this is the case, could I reconfigure the pins as EINT1 and EINT2 at the startup of my application? I would have to make sure that my external pulses are not connected during downloading the program as I guess p2.12 is somehow involved with the mystery chip?

It would really help if there was a more complete circuit diagram.

 

 

15 Mar 2010

Going by the schematics, pin 50 (P2.13/EINT3) is used for "JTAG IRQ" and pin 53 (P2.10/EINT0) for "SBL ISP". Pins 51 and 52 don't seem to be connected.

-deleted-
16 Mar 2010

Igor,

Thanks for clearing that up.  The UM had very little documentatoion on that (I only found 1 line when I knew what I was looking for).  Can SetVector be used with the LPC1768?  I was looking over older posts and came across a USB host example and the LPC1768 is #ifdef to not use that method.

http://mbed.org/forum/mbed/topic/419/?page=1#reply

InterruptIn class uses NVIC_SetVector() to hook the interrupt dynamically.

If a class member will become the IRQ does it need to be declared static?  If it is static will it be able to access other member variables with out referencing "this"?

17 Mar 2010

USB host example declares its interrupt handler with the standard name (USB_IRQHandler), so on Cortex-M3 (such as LPC1768) it's put into the vector table at the linking time and there's no need to install it separately. The old code is still necessary for ARM7 (not that I can test it since LPC2368 doesn't have USB Host).

If you want a class method as an interrupt handler then yes, it has to be static. And you can't use "this" in static functions so you'll have to store the instance pointer in a global variable and use it to call other methods. See ADC driver from Simon Blandford for an example.