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

Reply
  • 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

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

  • Hi Edvin,

    Good news and bad news. The good news are that the values now make

    Bad news are that, after the first update event with the agreed connection interval value (30) which is inside the min max limits I have set , a second update event takes place automatically with another value (12) outside the defined limits,  as displayed next

    <info> app: BLE GAP Connected
    <info> app: Conn.Interval is 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: Request Bytes = 5
    <info> app: Conn.Interval in function. Max: 0x20, Min: 0x18, Max: 32, Min: 24
    <info> app: Conn.Interval is updated. Max: 0x1E, Min: 0x1E, Max: 30, Min: 30
    <info> app: Conn.Interval is updated. Max: 0xC, Min: 0xC, Max: 12, Min: 12

    How is it possible a second connection interval  update event to take place and change the value by its own?

    By repeating the process with different min max values for the connection interval, the first update event takes the values correctly and the agreed value is within the set limits and the second update that occurs automatically returns the set value back to 12.

  • The application that wrote these logs, is that a peripheral or a central?

    It is always the central that has the final saying on the connection parameters. I guess that this is the peripheral. Are you developing the central as well? Or do you have access to the central source code? What is the preferred connection parameters on the central? I suspect it is maximum 12. If the central is another nRF, can you try to change the preferred connection interval to something else?

    BR,
    Edvin

  • 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

Related