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

Stop and restart APP_TIMER doesn't work with SDK12

I use an app_timer to periodically update sensor reading in my application. There is a characteristic used to change updating rate by stopping and restarting the app_timer:

app_timer_stop(m_our_char_timer_id);
app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER), NULL); //1000ms
			

It works fine with SDK11. But with SDK12, I couldn't receive any data package after stopping and restarting the app_timer. Weird thing is, usually after 5 to 6 minutes, it resumes updating again.

Any help is appreciated. Thanks.

  • Hi,

    Did you assign a timeout handler when you created the app timer with app_timer_create(...)? Does the timeout-handler trigger?

  • Yes in the handler I read the sensor value and send it out. With SDK12, the timer works fine until I change its interval through that characteristic using the code in my post. It stops sending data after stopping and restarting, but resumes in 5 to 6 minutes. Everything works fine with SDK11.

  • How have you done the porting from SDK 11 to SDK 12?

    Have you tried debugging, to see if you run into the error-handler?

  • What do you mean of porting? I used debugging from this tutorial in Eclipse. I placed a breakpoint in the timeout handler, it is not triggered after I writing to the data rate characteristic to stop and restart timer with a new interval. After a few minutes, it resumes as I mentioned above. That means app_timer_start doesn't start the timer immediately?

  • Is this a project that was originally written with SDK 11? and you are now porting it to SDK 12?

    If that is the case, you need to check the app_timer migration note here.


    the timer works fine until I change its interval through that characteristic using the code in my post

    Could you post some code that shows how you do this?

    Q: That means app_timer_start doesn't start the timer immediately?

    A: Yes, that is correct, but it should not take minutes.

    From infocenter:

    When calling app_timer_start() or app_timer_stop(), the timer operation is just queued, and the software interrupt is triggered. The actual timer start/stop operation is executed by the SWI0 interrupt handler. Since the SWI0 interrupt is running in APP_LOW, if the application code calling the timer function is running in APP_LOW or APP_HIGH, the timer operation will not be performed until the application handler has returned. This will be the case, for example, when stopping a timer from a time-out handler when not using the scheduler.

Related