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

NRF51822 got odd behavior when calling app_timer_start before mainloop

Hi,

  • I am using SDK 12.02 with softdevice 130 and having a odd issue here.

  • In my application, I want to advertise ADC value via beacon and to report the ADC value via serial. In this design, I intend to periodically arm the APP_TIMER very 2 seconds which to toogle the FLAG to arm ADC conversion in mainloop.

  • However, when calling app_timer_start() before going into mainloop to trigger the REPEATED TIMER then NRF51822 also got CRASHED and sometimes it works as EXPECTED.

My timer init as below:

#define APP_TIMER_OP_QUEUE_SIZE         4  
#define OUR_CHAR_TIMER_INTERVAL     		APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER) // 1000 ms intervals
APP_TIMER_DEF(m_our_char_timer_id);

APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
err_code = app_timer_create(&m_our_char_timer_id, APP_TIMER_MODE_REPEATED, timer_timeout_handler);
        		APP_ERROR_CHECK(err_code);
err_code = app_timer_start(m_our_char_timer_id, OUR_CHAR_TIMER_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);

So my questions are:

  1. Is this a right approach or am I missing anything during the initialization?
  2. Is there anyway better than this?
  3. I intend to use SCHEDULER for the app_timer. I try to look up other examples but I am not quite sure how to define the SCHED_MAX_EVENT_DATA_SIZE and SCHED_QUEUE_SIZE macro?

Attached is a small project, which I modified from ble_app_template example, where I tried to get the timers working - maybe somebody can look at it and tell me what's wrong.

Thanks

ble_app_uart.zip

Related