Question

Is there a simple GPIO Interrupt example for the ARM Cortex-M3?

I have written some code, however somehow the interrupt does not seem to fire:

#include "LPC17xx.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_gpio.h"

void EINT3_IRQHandler(void) {
    NVIC_ClearPendingIRQ(EINT3_IRQn);
    puts("triggered");  // fired
}

int main() {
    /** ... **/
    /** ... **/

    // listen for input on INPUT pin @ GPIO port 1, pin 31
    PINSEL_CFG_Type PinCfg;
    PinCfg.Funcnum = 0;
    PinCfg.OpenDrain = 0;
    PinCfg.Pinmode = 0;
    PinCfg.Portnum = 1;
    PinCfg.Pinnum = 31;
    PINSEL_ConfigPin(&PinCfg);

    GPIO_SetDir(port, 1 << pin, 0);

    NVIC_EnableIRQ(EINT3_IRQn);

    while(1);       // wait

    /** ... **/
    /** ... **/

    return 0;
}

I have been searching online / GitHub for a simple GPIO interrupt example for the LPC1769 Cortex M3, but it yields no results. It appears however that:

  1. the GPIO interrupt of interest is EINT_3.
  2. the IRQ handler EINT3_IRQHandler gets overwritten, when defined in user code.

What is wrong?

Was it helpful?

Solution

On the LPC17xx, you have interrupt enable registers for Port 0 and 2, see UM10360.pdf chapter 9.5.6 for reference. You have no GPIO interrupts on Port 1, 3 and 4 - you code appears to use Port 1.31, which cannot have GPIO interrupts.

In the exception handler you must not forget to clear the intterupt flags in IO0IntClear and IO2IntClear. Failing to do so would re-trigger the handler function otherwise, even when using NVIC_ClearPendingIRQ().

The "correct" name for the handler function may depend on your toolchain.

OTHER TIPS

the IRQ handler EINT3_IRQHandler gets overwritten, when defined in user code.

I do not know that specific device, but I suppose you need to call these instructions from priviledged mode. My guess is these instructions don't do anything if called from user mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top