I am trying to use a button to put the nRF9160 to sleep and to wake it back up.
I configure my button as follows:
gpio_pin_configure(dev, PIN, GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL);
gpio_init_callback(&button_cb, button_pressed, BIT(PIN));
gpio_add_callback(dev, &button_cb);
gpio_pin_enable_callback(dev, PIN);
and the callback button_pressed looks like this:
void button_pressed(struct device *dev, struct gpio_callback *cb, u32_t pin)
{
sleep = !sleep;
if ( sleep )
{
__WFI();
}
else
{
printk("Waking\n");
}
}
When the system is awake and the button is pressed it goes to sleep properly, but when I press the button again it doesn't wake up.
It will wake up on its own after a few seconds, from some other interrupt.
The button callback will also be run when it does wake up, as "Waking" is printed immediately after it wakes, but the button isn't whats waking it up.
Any idea why it's not working?