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

How to reconnect faster after a disconnection

Hello there,

I am working on a project in which two devices(one is central and other is peripheral ) uses Nordic bluetooth controller  for connection and data exchange. nrf51822 for peripheral and nrf51422 for the central. We are using SDK 12.3 and S130.
As in our product, there are high chances of peripheral going out of range and reconnecting back quite frequently. Now the reconnection takes alonger time.
I wanted to understand how the reconnection can be made faster.
Currently in our code, at the time disconnection
    case BLE_GAP_EVT_DISCONNECTED:  
   err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
  sd_ble_gap_scan_stop();
  scan_start();    
  sd_ble_gap_adv_stop ();
  sd_softdevice_disable()
  nrf_drv_clock_on_sd_disable()
  nrf_drv_rng_on_sd_disable();
  NVIC_DisableIRQ(TIMER2_IRQn);
  NRF_TIMER2->TASKS_STOP = 1; 
  NRF_TIMER2->POWER = 0; 
  nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V27);

case BLE_GAP_EVT_CONNECTED:
 conn_handle=p_ble_evt->evt.gattc_evt.conn_handle;
 err_code = ble_db_discovery_start(&m_ble_db_discovery, p_ble_evt->evt.gap_evt.conn_handle);
Please suggest if this is the correct way of implementing connection and disconnection, so that we have a faster reconnection.
Thanks,
Thomas
Parents
  • What role is your device, Central or Peripheral?

    Also
     : 

    case BLE_GAP_EVT_DISCONNECTED:  
      /*    Why are you asking the SoftDevice to disconnect the link when 
            you just got told that the link is disconnected? */
      err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
      /*    Why do you not catch your error codes? An APP_ERROR_CHECK(err_code)
            would have raised an error and you would have been told by the log
            module that your previous SD call returned an error. The error code
            is defined in the SoftDevice API documentation for any given API call*/
      
      /* Why do you stop scanning? */
      sd_ble_gap_scan_stop();
      
      /* Why do you start scanning? */
      scan_start();    
      
      /* Why do you stop advertising? */
      sd_ble_gap_adv_stop (); 
      
      /* Why do you disable the SoftDevice? */
      sd_softdevice_disable()
      
      /* Why do you turn off clocks and a timer? */
      nrf_drv_clock_on_sd_disable()
      nrf_drv_rng_on_sd_disable();
      NVIC_DisableIRQ(TIMER2_IRQn);
      NRF_TIMER2->TASKS_STOP = 1; 
      NRF_TIMER2->POWER = 0; 
      
      /* Why do you turn on the POFW? */
      nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V27);

  • The code snippet shared above is from central. The earlier code snippet is from one of our products.

    We wanted to improve the connection/reconnection behaviour for this product.

    I think calling sd_ble_gap_disconnect() when it is disconnected is unnecessary.

    Also, the below code is not needed at the time of disconnection

    /* Why do you disable the SoftDevice? */
      sd_softdevice_disable()
     
      /* Why do you turn off clocks and a timer? */
      nrf_drv_clock_on_sd_disable()
      nrf_drv_rng_on_sd_disable();
      NVIC_DisableIRQ(TIMER2_IRQn);
      NRF_TIMER2->TASKS_STOP = 1;
      NRF_TIMER2->POWER = 0;
     
      /* Why do you turn on the POFW? */
      nrf_power_pofcon_set(true, NRF_POWER_POFTHR_V27);

    So currently my disconnection event handling code looks like

    case BLE_GAP_EVT_DISCONNECTED: 
      
      /* start scanning to connect with the peripheral */
      scan_start();   

    Is this the correct method.

Reply Children
No Data
Related