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

Starting timer disables gpiote button

Hi,

I am developing a code in which, among other things, when a button is pressed, a led turns on. In the same button handler, a timer is started to turn the led off a bit later. 

It works perfectly well in the beginning, but after pushing the button some times (between 3 and 10) it responds no more. The rest of the application will continue acting normally, even its timers.

I've already checked that  APP_TIMER_CONFIG_OP_QUEUE_SIZE is big enough, and also changing the button handler for a flag and handle the event in the main loop. It solved nothing. The only way it works is by changing the timer by a delay, but it is useless if I want the led to be on for some seconds. 

Button initialization and handler:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void button_handler(nrf_drv_gpiote_pin_t pin_no, nrf_gpiote_polarity_t button_action)
{
app_timer_stop(led_off_timer);
nrf_gpio_pin_clear(LED_G);
nrf_gpio_pin_clear(LED_B);
uint32_t err_code = app_timer_start(led_off_timer, APP_TIMER_TICKS(1000), NULL);
APP_ERROR_CHECK(err_code);
}
static void init_button(void)
{
uint32_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
in_config.pull = NRF_GPIO_PIN_NOPULL;
err_code = nrf_drv_gpiote_in_init(BUTTON1, &in_config, button_handler);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Timer handler:

Fullscreen
1
2
3
4
5
void led_off_handler(void * p_context)
{
nrf_gpio_pin_set(LED_G);
nrf_gpio_pin_set(LED_B);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I am using a nrf52832 with SDK 14.2.0 and softdevice s132 v5.1.

Any clue of why it is happening or how can be solved will be very welcome. Thanks.