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

Indicating advertisement with a timer

I have a custom design buildt on ble_app_uart peripheral example from SDK 12.2.0. I use a timer that I start from case BLE_ADV_FAST in on_adv_evt to send a message to a display instead of the bsp led indicator (i use no leds to save power)

This is my on_adv_evt function:

static void on_adv_evt(ble_adv_evt_t ble_adv_evt){
   uint32_t err_code;
   switch (ble_adv_evt)
   {
       case BLE_ADV_EVT_FAST:
           dispClear();
           err_code = app_timer_start(m_advertisement_indicator, APP_TIMER_TICKS(ADVERTISEMENT_INDICATOR, APP_TIMER_PRESCALER), NULL);
           APP_ERROR_CHECK(err_code);
           display_print(STATUS,DEVICE_NAME,12);
           // Grab a sample from ADC 
           saadc_init();
           nrf_drv_saadc_sample();
           break;
       case BLE_ADV_EVT_IDLE:
           sleep_mode_enter();
           break;
       default:
           break;
   }
}

It works well when booting the application, but if I disconnect, the code in the BLE_ADV_FAST case are executed (text in display is updated), but for some reason the code in the timer is not called within the time given, and it seems to be different length of time, every time it fires from a disconnect.

It is strange that the other commands; displClear(); display_print(...) and adc init/sample is called and executed but the timer is not started..

Any idea what might cause this? Perhaps I should go for a different approach?

Edit: updated question with regards to Hung Bui's comment

Parents
  • Hi Erltot,

    Just an update, it's most likely a but with the app timer. We are still investigating it. It must be an issue of starting and stopping the app timer inside an interrupt handler. There are some is a quick workaround to only start/stop a flag (variable) inside the Connected / Disconnected event and then in your main loop in main() you actually start/stop the timer accordingly to the flag. Using app scheduler with the app timer should also fix the issue.

    I will keep you updated when we find the root cause.

Reply
  • Hi Erltot,

    Just an update, it's most likely a but with the app timer. We are still investigating it. It must be an issue of starting and stopping the app timer inside an interrupt handler. There are some is a quick workaround to only start/stop a flag (variable) inside the Connected / Disconnected event and then in your main loop in main() you actually start/stop the timer accordingly to the flag. Using app scheduler with the app timer should also fix the issue.

    I will keep you updated when we find the root cause.

Children
Related