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

Using timer with sd_app_evt_wait()

I am trying to run my program once per second using timer. The timer is initialized as follows:

APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);

err_code = app_timer_create(&m_timer_id, APP_TIMER_MODE_REPEATED, timeout_handler);

err_code = app_timer_start(m_timer_id, TIMER_INTERVAL, NULL);

The main loop is then simply:

while (1) { sd_app_evt_wait(); do_my_things(); }

However, now that timer triggers first time, the loop starts to run at full speed. Should I somehow acknowledge the timer event in order to be able to wait again?

Parents Reply Children
  • Yeah, that was a bit stripped code. I have a boolean flag 'timeout' in the timeout_handler and now I am checking that flag in the main loop. It seems that it is almost working, but instead of one second interval, the flag seems to be set once per two seconds. But when I connect via BT-LE, it starts to run correctly once per second. Strange behaviour, any ideas what could cause that?

Related