This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Exiting Sleep mode via GPIO interrupt

I've been playing around with the v1.9.1\zephyr\samples\boards\nrf\system_off\ example code, as I want to implement something similar in my own code.  But I want to be able to detect which GPIO caused the system to exit from system off, update a counter, then send it back to sleep.
In the sample code, they make a call to the following API to set up the GPIO pin to cause the interrupt and bring the device out of sleep mode
	nrf_gpio_cfg_sense_set(DT_GPIO_PIN(DT_NODELABEL(button0), gpios),
			       NRF_GPIO_PIN_SENSE_LOW);
In my code, without any of the system off functionality, I set up a GPIO to trigger an interrupt and update my counter.  That all works OK.  This is how I have it set up:
#define STRIKE_S_NODE DT_ALIAS(sw0)
    
#if DT_NODE_HAS_STATUS(STRIKE_S_NODE, okay)
#define STRIKE_SML	        DT_GPIO_LABEL(STRIKE_S_NODE, gpios)
#define STRIKE_SML_PIN	    DT_GPIO_PIN(STRIKE_S_NODE, gpios)
#define STRIKE_SML_FLAGS	DT_GPIO_FLAGS(STRIKE_S_NODE, gpios)
#else
#error "Unsupported board: button0 devicetree alias is not defined"
#define STRIKE_S_NODE    DT_INVALID_NODE
#define STRIKE_SML	""
#define STRIKE_SML_PIN	0
#define STRIKE_SML_FLAGS	0
#endif
    
const struct gpio_dt_spec sml_strike = GPIO_DT_SPEC_GET_OR(STRIKE_S_NODE, gpios,{0});

gpio_pin_configure_dt(&sml_strike, GPIO_INPUT);

gpio_pin_interrupt_configure_dt(&sml_strike,GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&strike_sml_cb_data, sml_strike_detected, BIT(sml_strike.pin));
gpio_add_callback(sml_strike.port, &strike_sml_cb_data);
But if I put the system into sleep mode, this doesn't bring the system out of sleep mode when I activate the appropriate GPIO.  In order to achieve this, I have to include the following (essentially a modification of what was in the example code)
    nrf_gpio_cfg_sense_input(sml_strike.pin, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
Is that the correct way of going about it?  Or is there a more appropriate Zephyr API for configuring a GPIO to trigger the device out of sleep mode?
And how come setting up the GPIO to trigger an interrupt as I did originally (without the nrf_gpio_cfg_sense_input API call) doesn't trigger the system out of sleep mode?
Thanks and regards,
Mike
Parents
  • Hi Amanda,

    Thanks, but if you read my original post, you'll see I have been using that example, and that API.  My question pertains to why I need to essentially configure the GPIO for "normal" interrupts using one API, and then reconfigure it again for "exit sleep mode" interrupts using a different API.

    Can I configure the API to trigger both types of interrupts with one API?  Or do I have to call the:

    nrf_gpio_cfg_sense_set(DT_GPIO_PIN(DT_NODELABEL(button0), gpios), NRF_GPIO_PIN_SENSE_LOW);

    API just prior to going into sleep mode so that the GPIO will trigger it out of sleep mode, then call the:

    gpio_pin_interrupt_configure_dt(&sml_strike,GPIO_INT_EDGE_TO_ACTIVE);

    API to configure the GPIO to trigger my ISR within my code when its operating normally?

    Thanks and regards,

    Mike

  • Hi Mike, 

    GPIO wakeup from system OFF uses the GPIO SENSE event. While normally in system ON idle, the gpio interrupt is generated by GPIOTE IN event which does not work in system OFF. Therefore, the function gpio_pin_interrupt_configure_dt will not work in the sleep mode because that uses the GPIOTE IN event. 

    -Amanda

  • Hi Amanda,

    Great, that makes sense.  Thanks for the explanation

    Regards,

    Mike

Reply Children
No Data
Related