This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Change advertisement interval after first connection

Using SD130 v2.0.1 on nRF51822, I would like to be able to change the advertisment interval after first connection.

My app is based on the HRS sample, with a modified avertising_init:

static void advertising_init_interval(uint32_t advertInterval)
{

  static bool inited = false;

  uint32_t err_code;
  ble_advdata_t advdata;
  ble_adv_modes_config_t options;

  // Build advertising data struct to pass into @ref ble_advertising_init.
  memset(&advdata, 0, sizeof(advdata));

  advdata.name_type = BLE_ADVDATA_FULL_NAME;
  advdata.include_appearance = true;
  advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
  advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
  advdata.uuids_complete.p_uuids = m_adv_uuids;

  memset(&options, 0, sizeof(options));
  options.ble_adv_fast_enabled = true;
  options.ble_adv_fast_interval = advertInterval == 0 ? APP_ADV_INTERVAL : advertInterval;
  options.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS;

  LOGVA("Setting adv interval to %d units", options.ble_adv_fast_interval);

  if (!inited)
  {
    inited = true;
    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
  }
  else
  {
    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);
  }
}

When receiving BLE_GAP_EVT_DISCONNECTED, I call avertising_init_interval with 200 units as parameters. Log is ok, no error happens, however when I measure the timing using oscilloscope, I get my initial interval (~320 ms) instead of the expected ~125 ms. What am I doing wrong?