Hi All,
I have got a project running on an nRF51422 QFAC, using the lastest SDK.
I am having some problems with the app_timers, i am able to create and start them, and they work ok, but i cannot stop them.
I have a static timer declared globally, which is used by multiple functions, along with a flag to see if its running or not. they are declared as follows,
static app_timer_id_t messageTimer;
static bool messageTimerRunning = false;
I have tried two methods of starting the timer, only one works. I think i only need to create the timer once on startup and then it can be used normally, however this does not work, when i go to start it later in the app, i get error NRF_ERROR_INVALID_STATE, which appears to be because the timer id is null. Instead i find i have to create it and then start it straight away. I do this the same as i would if i was just initialising it once on startup.
if(!messageTimerRunning){
APP_TIMER_DEF(messageTimer);
uint32_t err_code = app_timer_create(&messageTimer, APP_TIMER_MODE_SINGLE_SHOT, onMessageTimeoutTimer);
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(messageTimer, APP_TIMER_TICKS( 30000, APP_TIMER_PRESCALER ),NULL);
APP_ERROR_CHECK(err_code);
messageTimerRunning = true;
}else{
uint32_t err_code = app_timer_stop(messageTimer);
APP_ERROR_CHECK(err_code);
APP_TIMER_DEF(messageTimer);
err_code = app_timer_create(&messageTimer, APP_TIMER_MODE_SINGLE_SHOT, onMessageTimeoutTimer);
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(messageTimer, APP_TIMER_TICKS( 30000, APP_TIMER_PRESCALER ),NULL);
APP_ERROR_CHECK(err_code);
messageTimerRunning = true;
}
Regardless of whether I create the timer once on startup, or re create every time i use it, i will get an invalid state error when i come to stop it.
Thanks in advance, Bill.