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

Why the button port interrupt can not be triggered when I set another external interrupt from GPIOTE_CONFIG_IN_SENSE_LOTOHI to GPIOTE_CONFIG_IN_SENSE_HITOLO?

I have four button and one external interrupt from GSensor on my demo board, and I use GPIOTE_CONFIG_IN_SENSE_TOG for button and GPIOTE_CONFIG_IN_SENSE_LOTOH  for GSensor interrupt, they are all set to low accuracy for low power consumption, they function flawlessly, but now I need to replace the GSensor, and the interrupt pulse from new GSensor get short, this cause the GSensor interrupt callback can not be called, So I replace the external interrupt sense level to GPIOTE_CONFIG_IN_SENSE_HITOLO, yes, the GSensor interrupt function get called, but the button callback can not be called now. I do not know how this happen?

Another question: does the Pin interrupt using high accuracy get high power when the pulse is active or it get high power always.

  • When low accuracy is enabled, port events are used. Ports event works in the following manner:

    • Correct sense signal occurs (PINx_CNF.SENSE, see figure below)
    • DETECT signal will be set high
    • If the DETECT signal goes from low to high, a port event happens and the appropriate callback function is called (e.g. GSensor callback)

    There are unfortunately some limitations when using high to low sensing (not PINx_CNF.SENSE) on a pin, initially when the pin signal goes from low to high, the DETECT signal will be set high and a port event occurs. At this moment, the DETECT signal is high, and no more port events will occur (which is your problem), since only a low-to-high DETECT transition will generate port events. When the pin goes low again, the DETECT signal will also go low, and new port event can occur. 

    Hopefully this was understandable, otherwise you can read more about this problem herehere and here.

    Best regards, Simon

  • Thank you, Simon. Now I know that how the GPIOTE work. So what should I do to meet my requirement: low power means port sense. I want to change some code in GPIOTE_IRQHandler, but seems it is difficult for me.

  • My suggestion would be to use the nrfx gptiote driver provided as part of the nRF5 SDK, and configure all low accuracy inputs with sense set to NRF_GPIOTE_POLARITY_TOGGLE.

    The nrfx gpiote driver takes care of reconfiguring each input sense buffer as interrupts occur so that one input going active does not mask other inputs.  See nrfx_gpiote.c nrfx_gpiote_irq_handler for details.

    Using NRF_GPIOTE_POLARITY_TOGGLE does mean that you will receive handler events for both edges of your input, however you can simply ignore the edge for which you have no interest.

    e.g.

    handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { 
      // GPIOTE driver produces an interrupt on each /INT edge. Only interested 
      // in falling edge which indicates an interrupt going active. 
    
      if (pin == MY_INPUT_PIN_NUMBER && !nrfx_gpiote_in_is_set(MY_INPUT_PIN_NUMBER)) {
        // Handle input edge
      }
    }

Related