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
  • I use repeated mode, which i call once before the big while

    err_code = app_timer_create(&m_advertisement_indicator, APP_TIMER_MODE_REPEATED, advertisement_indicator);

    APP_ERROR_CHECK(err_code);

    I start the timer for the first time in on_adv_evt switch shown above, and I stop it in the p_ble_evt switc in the BLE_GAP_EVT_CONNECTED case:

    err_code = app_timer_stop(m_advertisement_indicator);

    APP_ERROR_CHECK(err_code);

    Sorry, I can't attach the full code

    I added a print to RTT in the advertisement_indicator event and noticed it seems to be a rubberband effekt going on, after a while the timer starts but the prints all came simultanously.. Could it be the soft device blocking the event from running, and when it finally runs it executes several times?

Reply
  • I use repeated mode, which i call once before the big while

    err_code = app_timer_create(&m_advertisement_indicator, APP_TIMER_MODE_REPEATED, advertisement_indicator);

    APP_ERROR_CHECK(err_code);

    I start the timer for the first time in on_adv_evt switch shown above, and I stop it in the p_ble_evt switc in the BLE_GAP_EVT_CONNECTED case:

    err_code = app_timer_stop(m_advertisement_indicator);

    APP_ERROR_CHECK(err_code);

    Sorry, I can't attach the full code

    I added a print to RTT in the advertisement_indicator event and noticed it seems to be a rubberband effekt going on, after a while the timer starts but the prints all came simultanously.. Could it be the soft device blocking the event from running, and when it finally runs it executes several times?

Children
No Data
Related