Dear sir/madame
I have a problem I hope you can help me with.
SoC is nRF52840
SDK is SDK 17.1.0
Problem description:
In my app I have two buttons defined; Button1 and Button2.
Before I force the nRF52840 into deep sleep I define Button1 as wake up pin. That work well.
After wakeup I configure the buttons and interrupts among lot of other things.
Problem:
After waking up the board by pushing and releasing Button1 and when peripheral (board) is connected to the central, I push button2.
Interrupt (event) for button 2 is fired as expected, but in in additional I got an interrupt for Button1.
This only happens once; If I push Button2 or Button1 once more, everything work as expected.
I have been reading pages up and down, searching dev forum, but not been able to find a solution.
My question is: How can I prevent interrupt on Button1 when pushing Button2 first time after wakeup from deep sleep?
Best regards
Svein
Code snippets:
/*
Definition of Buttons and interrupt handling:
*/
static void my_app_button_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
//Config settings
nrfx_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
in_config.pull = NRF_GPIO_PIN_NOPULL;
//Inits PINs
err_code = nrfx_gpiote_in_init(SW1, &in_config, in_pin_handler); //SW1 = P0.19
APP_ERROR_CHECK(err_code);
err_code = nrfx_gpiote_in_init(SW2, &in_config, in_pin_handler); //SW2 = P0.20
APP_ERROR_CHECK(err_code);
//Enable event
nrfx_gpiote_in_event_enable(SW1, true);
nrfx_gpiote_in_event_enable(SW2, true);
}
/*
Interupt.
Button is pushed. Start correct timer and at timeout check if PIN is high or LOW
*/
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
NRF_LOG_INFO("Button interupt from pin %d and action is %d. Button/GPIO state is %d", pin, action, nrf_gpio_pin_read(pin));
switch(pin)
{
case SW1:
if(debounce_timer1_started)
{
//Do nothing
}
else
{
debounce_timer1_started = true;
uint32_t err_code = app_timer_start(debounce_timer1_id, APP_TIMER_TICKS(debounce_time), NULL);
APP_ERROR_CHECK(err_code);
}
break;
case SW2:
if(debounce_timer2_started)
{
//Do nothing
}
else
{
debounce_timer2_started = true;
uint32_t err_code = app_timer_start(debounce_timer2_id,APP_TIMER_TICKS(debounce_time), NULL);
APP_ERROR_CHECK(err_code);
}
break;
}
}
/*
Sleep and wakeup routine
*/
void init_wakeup_pin_and_deepsleep()
{
//Turn off LEDs
nrf_gpio_pin_clear(GREEN_LED);
nrf_gpio_pin_clear(BLUE_LED);
nrf_gpio_pin_clear(YELLOW_LED);
nrf_gpio_pin_clear(RED_LED);
nrfx_gpiote_in_uninit(SW1);
nrfx_gpiote_in_uninit(SW2);
nrf_gpio_cfg_input(SW1, NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_sense_set(SW1, NRF_GPIO_PIN_SENSE_LOW);
sd_power_system_off();
}