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

Connection Interval update issue

Hi I am trying to update the connection interval of a peripheral device (nRF52840 ) and I have followed the steps mentioned here.

After Enabling the ble on the device I read the connection interval at initialization by doing this

              uint16_t max =  p_ble_evt->evt.gap_evt.params.connected.conn_params.max_conn_interval;
              uint16_t min =  p_ble_evt->evt.gap_evt.params.connected.conn_params.min_conn_interval;
              NRF_LOG_INFO("Conn.Interval Initialized. Max: 0x%X, Min: 0x%X, Max: %d, Min: %d", max, min, max, min);

Then I used the following code part  to update the connection interval dynamically

 memset(&m_gap_conn_params, 0, sizeof(m_gap_conn_params));

    m_gap_conn_params.min_conn_interval =  30; //MSEC_TO_UNITS(30, UNIT_1_25_MS);
    m_gap_conn_params.max_conn_interval =  40; //MSEC_TO_UNITS(40, UNIT_1_25_MS);
    m_gap_conn_params.slave_latency     = 0;    // as init
    m_gap_conn_params.conn_sup_timeout  = MSEC_TO_UNITS(4000, UNIT_10_MS); // as init
    
    err_code = sd_ble_gap_conn_param_update(*m_conn_handle_gen, &m_gap_conn_params);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Conn.Interval in function. Max: 0x%X, Min: 0x%X, Max: %d, Min: %d", 
                  m_gap_conn_params.max_conn_interval, m_gap_conn_params.min_conn_interval, 
                  m_gap_conn_params.max_conn_interval, m_gap_conn_params.min_conn_interval);
   // NRF_LOG_INFO("Conn.Interval in function. Max: %d, Min: %d", m_gap_conn_params.max_conn_interval, m_gap_conn_params.min_conn_interval);

   while(conn_params_updated == false && timeoutCnt > 0)
   {
      timeoutCnt--;
      nrf_delay_ms(1);
      NRF_WDT->RR[0] = WDT_RR_RR_Reload;
   }
   conn_params_updated = false;
   if(timeoutCnt > 0) { result = COMM_RESPONSE_SUCCESS; }
   
   *lenPtr++ = COMM_RESPONSE_START;
   *lenPtr++ = COMM_CIUPDT;
   *lenPtr++ = result;
   *lenPtr++ = COMM_RESPONSE_END;
   size = lenPtr - buffer;
   err_code = ble_nus_data_send(m_nus_gen, buffer, &size , *m_conn_handle_gen);
   APP_ERROR_CHECK(err_code);

in the BLE_GAP_EVT_CONN_PARAM_UPDATE event I read back the values like this 

case BLE_GAP_EVT_CONN_PARAM_UPDATE:
            if(userRequest == UR_CONNINUPDT)
            {
              uint16_t max =  p_ble_evt->evt.gap_evt.params.connected.conn_params.max_conn_interval;
              uint16_t min =  p_ble_evt->evt.gap_evt.params.connected.conn_params.min_conn_interval;
              NRF_LOG_INFO("Conn.Interval is updated. Max: 0x%X, Min: 0x%X, Max: %d, Min: %d", max, min, max, min);
              conn_params_updated = true;
            }
            break;

But I get the following resulting values.36 is correct in initialization then the numbers don't make sense

<info> app: BLE GAP Connected
<info> app: Conn.Interval Initialized. Max: 0x24, Min: 0x24, Max: 36, Min: 36
<info> app: Data len is set to 0xF4(244)
<info> app: Data len is set to 0xF4(244)
<info> app: Conn.Interval in function. Max: 0x28, Min: 0x1E, Max: 40, Min: 30
<info> app: Conn.Interval is updated. Max: 0x2000, Min: 0xAF9, Max: 8192, Min: 2809
<info> app: Conn.Interval is updated. Max: 0x0, Min: 0x0, Max: 0, Min: 0

So I am doing something wrong but I cannot find out what

Parents
  • Hello,

    In your last snippet (before the log snippet), you use the parameters from the connected event, while the event type is actually BLE_GAP_EVT_CONN_PARAM_UPDATE, so they will not be correctly populated. 

    Try replacing:

    case BLE_GAP_EVT_CONN_PARAM_UPDATE:
                if(userRequest == UR_CONNINUPDT)
                {
                  uint16_t max =  p_ble_evt->evt.gap_evt.params.connected.conn_params.max_conn_interval;
                  uint16_t min =  p_ble_evt->evt.gap_evt.params.connected.conn_params.min_conn_interval;
                  NRF_LOG_INFO("Conn.Interval is updated. Max: 0x%X, Min: 0x%X, Max: %d, Min: %d", max, min, max, min);
                  conn_params_updated = true;
                }
                break;

    with:

    case BLE_GAP_EVT_CONN_PARAM_UPDATE:
                if(userRequest == UR_CONNINUPDT)
                {
                  uint16_t max =  p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params.max_conn_interval;
                  uint16_t min =  p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params.min_conn_interval;
                  NRF_LOG_INFO("Conn.Interval is updated. Max: 0x%X, Min: 0x%X, Max: %d, Min: %d", max, min, max, min);
                  conn_params_updated = true;
                }
                break;

    And see if that solves it.

    Best regards,

    Edvin

  • Hi Edvin, I will try it out first thing tomorrow morning and I will come back.
    Thank you for your time!

  • Hi,

    The application that wrote the logs comes from the peripheral device (nRF52840) debugger.

    The central is not nRF device. It is a custom windows 10 desktop application  with an external BLE 5.0 usb adapter.

    I have already contacted the app developer and he is trying to find the configuration for the connection parameters.

  • If the  central is a mobile phone or a computer, it may not be that easy to actually change the connection interval. Although I am not exactly sure how it is set on computers. It may be adjustable in some app for peripherals with custom BLE Services, but I think that with e.g. HID over BLE, the computer want to keep the connection interval low, to reduce latency. In this case slave_latency can be applied in order to reduce current consumption. Perhaps you can look into that.

    Best regards,

    Edvin

  • It seems that I will need an adapter between the windows application and the peripheral devices where I can modify the connection Interval the way I want. Maybe an nRF52840 as central would be the solution here

  • Hi, is there some way to check if the connection interval request from the peripheral to the mobile is accepted or not? Like a flag or something? 

  • You have to look for the BLE_GAP_EVT_CONN_PARAM_UPDATE events on the peripheral. 

Reply Children
Related