This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GPIOTE interrupt

I'm trying to use the GPIOTE to generate an interrupt when a pin makes a transition. It appears everything is working except the interrupt never gets triggered. NRF_GPIOTE->EVENTS_IN[0] and NRF_GPIOTE->EVENTS_port both get set to 0x1 when I press button4 on the nrf52840-PDK. So I think the GPIOTE module is detecting the change but the interrupt signal never gets raised.

I've looked thru the SDK code, Zypher RTOS, and Adafruit's Bluefruit implementations but I can't figure out what they're doing differently than me. (I've even checked the PDK's errata!) It's probably something obvious but I've been staring at the code long enough that I'm not seeing it.

So if anyone has any ideas what I might be doing wrong or how I might narrow it down, I'd love to hear about it.

Mike

Here's my code that is supposed to be setting the pin up:

        gpio_handlers[slot].handler = handler;
        gpio_handlers[slot].data = data;
        gpio_handlers[slot].pin = pin;
        gpio_handlers[slot].set = true;

        NRF_GPIOTE->INTENCLR = 1 << 31;
        port->PIN_CNF[index] &= ~GPIO_PIN_CNF_SENSE_Msk;
        if (rising == true)
            port->PIN_CNF[index] |= (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos);
        else
            port->PIN_CNF[index] |= (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);

        NRF_GPIOTE->CONFIG[slot] =
            (index << GPIOTE_CONFIG_PSEL_Pos) |
#ifdef GPIOTE_CONFIG_PORT_Pos
            (pnum << GPIOTE_CONFIG_PORT_Pos) |
#endif
            (polarity << GPIOTE_CONFIG_POLARITY_Pos) |
            (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);

        NRF_GPIOTE->EVENTS_IN[slot] = 0;
        dummy = NRF_GPIOTE->EVENTS_IN[slot];

        NRF_GPIOTE->EVENTS_PORT = 0;
        dummy = NRF_GPIOTE->EVENTS_PORT;

        NRF_GPIOTE->INTENSET = (1 << 31) | (1 << slot);

Parents
  • Turbo J was close. The GPIO init function which enabled the GPIOTE interrupt was being called early in the boot process. In fact, too early! Like before the IRQ init function was being called. So when the IRQ init function ran, it cleared out the handlers and disabled all of the interrupts in the NVIC, undoing the GPIOTE interrupt! So I modified the code to do the GPIO init the first time one of my GPIO routines is called. And now everything works as expected!

Reply
  • Turbo J was close. The GPIO init function which enabled the GPIOTE interrupt was being called early in the boot process. In fact, too early! Like before the IRQ init function was being called. So when the IRQ init function ran, it cleared out the handlers and disabled all of the interrupts in the NVIC, undoing the GPIOTE interrupt! So I modified the code to do the GPIO init the first time one of my GPIO routines is called. And now everything works as expected!

Children
No Data
Related