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

Switching from BLE_ADV_EVT_SLOW to BLE_ADV_EVT_FAST not working

Hi,

I use S130 with SDK 12.3.0.

I have an application that permanently advertise with an interval of 10s but when the user push a button I switch to BLE_ADV_EVT_FAST . I use the ble_advertising module.

To switch to fast mode I call ble_advertising_start(BLE_ADV_MODE_FAST) when the button is pressed but I never receive the BLE_ADV_EVT_FAST on the _OnAdvEvt function.

My configuration is:

#define APP_ADV_FAST_INTERVAL           64                                         // Fast advertising interval (multiple of 0.625 ms) = 40 ms
#define APP_ADV_FAST_TIMEOUT_IN_SECONDS 2                                          // Fast advertising timeout = 2s
#define APP_ADV_SLOW_INTERVAL           16000                                      // Slow advertising interval (multiple of 0.625 ms) = 10s
#define APP_ADV_SLOW_TIMEOUT_IN_SECONDS 0                                          // Slow advertising timeout = 1mn

static void _AdvertisingInit(void)
{
    uint32_t u32_ErrCode;
    ble_advdata_t s_AdvData;
    ble_adv_modes_config_t s_Options;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&s_AdvData, 0, sizeof(s_AdvData));
    s_AdvData.name_type               = BLE_ADVDATA_FULL_NAME;
    s_AdvData.include_appearance      = true;
    s_AdvData.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;        //BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    memset(&s_Options, 0, sizeof(s_Options));
    s_Options.ble_adv_fast_enabled  = true;
    s_Options.ble_adv_fast_interval = APP_ADV_FAST_INTERVAL;
    s_Options.ble_adv_fast_timeout  = APP_ADV_FAST_TIMEOUT_IN_SECONDS;
    s_Options.ble_adv_slow_enabled  = true;
    s_Options.ble_adv_slow_interval = APP_ADV_SLOW_INTERVAL;
    s_Options.ble_adv_slow_timeout  = APP_ADV_SLOW_TIMEOUT_IN_SECONDS;

    u32_ErrCode = ble_advertising_init(&s_AdvData, NULL, &s_Options, _OnAdvEvt, NULL);
    APP_ERROR_CHECK(u32_ErrCode);
}


I did another try with a APP_ADV_SLOW_TIMOUT_IN_SECONDS set to 60. I have the sequence FAST->SLOW->IDLE and when I receive the BLE_ADV_EVT_IDLE I do a ble_advertising_start(BLE_ADV_MODE_SLOW), it restart in slow mode. But when the user push the button it's not possible to switch to fast mode.

Best regards.
  • FormerMember
    0 FormerMember

    When you push the button to start fast advertising, is the advertising interval changed? (You can check it using nRF Connect (Android, maybe iOS as well) )

    Could you do the following:

    1. Set a breakpoint at ble_advertising_start(BLE_ADV_MODE_FAST).
    2. Run the chip in debug mode.
    3. Press the button to switch to fast advertsing:  step through the code in ble_advertising_start(), and check if the "behavior" is as expected.
  • Scanning with nRFConnect (android) show me strange thing on interval timing:

    Advertising type: Legacy (Adv Interval N/A)
    16:36:18.541
    10000ms
    Advertising type: Legacy (Adv Interval 41ms)
    16:36:08.540
    20005ms
    16:35:48.534
    9999ms
    16:35:38.535
    60026ms
    16:34:38.508
    92ms
    + 21 more
    249ms
    16:34:36.573

    Step through code when pushing the button give me a return=8 (invalide state?) from the function sd_ble_gap_adv_start() in ble_advertising_start().

    Remark: it's not easy to step by step because frequently I'm finish to the app_error_save_and_stop() function with an id=1 and pc=0x104AE, info=0

  • FormerMember
    0 FormerMember in reply to jtredez
    jtredez said:
    Remark: it's not easy to step by step because frequently I'm finish to the app_error_save_and_stop() function with an id=1 and pc=0x104AE, info=0

    This means that a function returns an error. Which function returns an error? sd_ble_gap_adv_start() or some other function as well?

    When stepping through ble_advertising_start() all until sd_ble_gap_adv_start(), are the advertising parameters set correctly/are the correct parameters supplied to sd_ble_gap_adv_start()?

    To check if sd_ble_gap_adv_start() returns an error, run the code and set a breakpoint at APP_ERROR_CHECK() right after the function.

  • I did two tests:

    1) first with APP_ADV_SLOW_TIMEOUT_IN_SECONDS=0 to advertise in slow mode infinitely. In this case in ble_advertising_start(), the call to sd_ble_gap_adv_start() return 8 (invalide state) and I doesn't return in fast advertising.

    2) with APP_ADV_SLOW_TIMEOUT_IN_SECONDS=60 to advertise in slow mode for 1mn. In this case if I wait the BLE_ADV_EVT_IDLE, the call to sd_ble_gap_adv_start() return 0 and I can restart the fast advertising.

    So it seem I can do FAST->SLOW->IDLE->FAST but I can't do FAST->SLOW->FAST.

Related