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
  • In the breakpoint I get in ble_advertising_start() is BLE_ADV_MODE_DIRECTED as you suggested.

    I tried adding both (not at the same time)

    case BLE_ADV_MODE_DIRECTED:

    case BLE_ADV_EVT_DIRECTED:

    just above the other case in my on_adv_evt, it didn't do much...

    When I checked the ble_adv_evt in the event when I disconnect it shows BLE_ADV_EVT_FAST.. I don't understand why does the other parts under the case for BLE_ADV_EVT_FAST get executed and not the timer?

Reply
  • In the breakpoint I get in ble_advertising_start() is BLE_ADV_MODE_DIRECTED as you suggested.

    I tried adding both (not at the same time)

    case BLE_ADV_MODE_DIRECTED:

    case BLE_ADV_EVT_DIRECTED:

    just above the other case in my on_adv_evt, it didn't do much...

    When I checked the ble_adv_evt in the event when I disconnect it shows BLE_ADV_EVT_FAST.. I don't understand why does the other parts under the case for BLE_ADV_EVT_FAST get executed and not the timer?

Children
No Data
Related