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

Disconnection between "ble_app_hrs" example in SDK 15.2.0 and "heart_rate_collector" example with pc-ble-driver (c/c++)

Hello, this is Kwonjoon Lee, beginner of BLE development.

I successfully installed pc-ble-driver (c/c++) in accordance with Git-Hub guide
(https://github.com/NordicSemiconductor/pc-ble-driver), and

I would like to ask about disconnection between "ble_app_hrs" example in SDK 15.2.0 and 
"heart_rate_collector" example with pc-ble-driver (c/c++).

The following is my development environment and procedure, which I faced disconnection. 

(Development Environment)

- Windows 10, 64bit
- Visual Studio 2015 Pro
- PC-BLE-DRIVER (C/C++)
- nRF5 SDK v15.2.0_9412b96

- nRF Connect v2.6.0
- SEGGER Embedded Studio for ARM V4.12 (x86)

- BLE Peripheral : nRF52840 DK with "ble_app_hrs" example of nRF5 SDK 15.2.0_9412b96
  1) Example Path : C:\Nordic\nRF5_SDK_15.2.0_9412b96\examples\ble_peripheral\ble_app_hrs\pca10056\s140\ses

- BLE Master : nRF52840 Dongle with "heart_rate_collector_v6" example of pc-ble-driver
  1) Connectivity Hex File : "connectivity_1.0.0_usb_with_s140_6.1.0.hex" in pc-ble-driver connectivity hex file
  2) Baud Rate : 1 Mbps @ COM6

(Development Procedure & Disconnection Phenomenon)

  1. Programming "connectivity_1.0.0_usb_with_s140_6.1.0.hex" into nRF52840 Dongle with nRF Connect Programmer App.
    in accordance with (https://devzone.nordicsemi.com/tutorials/b/getting-started/posts/nrf52840-dongle-programming-tutorial)
  2. Building, downloading, executing "ble_app_hrs" example on nRF52840 DK with SEGGER Embedded Studio for ARM V4.12 (x86)
    in accordance with (https://www.nordicsemi.com/DocLib/Content/User_Guides/gsg_ses/latest/UG/gsg/intro
  3. Build & run "heart_rate_collector_v6" example of pc-ble-driver
  4. Disconnection after connection establishing & receiving 5 heart rate samples

(Question)

  1. I am a beginner of BLE development and I would like to ask 
    whether above disconnection after connection establishing & receiving 5 heart rate samples is normal and expected phenomenon.
  2. Additionally, I want to ask what is the meaning of "un-handled event with ID : 18" and "disconnected reason : 0x22"
    and also, I want to know where can I check the "un-handled event with ID : 18" and "disconnected reason : 0x22"
  3. Is there any documentation including operation of "ble_app_hrs" example for beginner?
    Currently, I am just checking the "ble_app_hrs" example codes in SES, but code line is too long so that I cannot easily understand the operation.

If anyone give me some comments,
it will be huge help for me.

Best regards,
Kwonjoon Lee

 

  • Hello, Sigurd, this is Kwonjoon Lee.
    I always appreciate your kind answer, and I would like to get some more comments on my work.

    Actually, I am trying to implement Bluetooth5 communication with maximum throughput.
    (between the heart_rate_collector_v6 of "pc-ble-driver" and the ble_app_hrs of "nRF5 sdk 15.2.0") 

    For that, I am attempting following three methods:
    1) Using uncoded 2M PHY (in my opinion, this is successful)
    2) Increasing LL data channel PDU payload length (is it so-called data length extension, DLE??)
    3) Increasing maximum transmission unit (MTU) of 247 (Max)

    My major problem and question are about 2) (increasing data length), and
    please see the following figures and my working history.

    Figures and Working History : 

    First, in my the ble_app_hrs example, sdk_config.h defines NRF_SDH_BLE_GAP_DATA_LENGTH
    as following code so that ble_app_hrs example (BLE peri) sends heart_rate_collector_v6 example
    (BLE master) data_length_update_request of TX/RX bytes == 251/251 bytes.

    // <o> NRF_SDH_BLE_GAP_DATA_LENGTH   <27-251> 
    
    // <i> Requested BLE GAP data length to be negotiated.
    
    #ifndef NRF_SDH_BLE_GAP_DATA_LENGTH
    #define NRF_SDH_BLE_GAP_DATA_LENGTH 251
    #endif

    After that, heart_rate_collector_v6 example (BLE master) responds with following  
    the function call, sd_ble_gap_data_length_update (m_adapter, m_connection_handle, &dlp, &dll)
    as shown in the attached code. But, it makes NRF_ERROR_RESOURCE.
    So, currently, I changed the function call to  
    sd_ble_gap_data_length_update (m_adapter, m_connection_handle, NULL, NULL)
    according to the link (third case and picture), and the result is TX/RX bytes == 157/157 bytes.

    // Added by Kwonjoon @ 20190228 in accordance with Sigurd's Guide (Below)
    static void on_conn_data_length_update_request(const ble_gap_evt_t * const p_ble_gap_evt)
    {
    	printf("BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST : TX/RX bytes == %d/%d bytes and TX/RX us == %d/%d us \n",
    		p_ble_gap_evt->params.data_length_update_request.peer_params.max_tx_octets,
    		p_ble_gap_evt->params.data_length_update_request.peer_params.max_rx_octets,
    		p_ble_gap_evt->params.data_length_update_request.peer_params.max_tx_time_us,
    		p_ble_gap_evt->params.data_length_update_request.peer_params.max_rx_time_us);
    
    	ble_gap_data_length_params_t const dlp =
    	{
    		.max_rx_octets = 251, // Previous Value : 27
    		.max_tx_octets = 251, // Previous Value : 27
    		.max_rx_time_us = 2704, // BLE_GAP_DATA_LENGTH_AUTO
    		.max_tx_time_us = 2704, // BLE_GAP_DATA_LENGTH_AUTO
    	};
    
    	ble_gap_data_length_limitation_t dll = { 0 };
    	//uint32_t err_code = sd_ble_gap_data_length_update(m_adapter, m_connection_handle, &dlp, &dll);
    	uint32_t err_code = sd_ble_gap_data_length_update(m_adapter, m_connection_handle, NULL, NULL);
    	if (err_code != NRF_SUCCESS)
    	{
    		printf("sd_ble_gap_data_length_update failed, err_code %d\n", err_code);
    	}
    
    }
    // Added by Kwonjoon @ 20190228 in accordance with Sigurd's Guide (Above)

    To resolve the NRF_ERROR_RESOURCE, and increase data length up to 251 bytes,
    I found some comments about data length update procedure in the
    ble_gap.h of the heart_rate_collector_v6 example (BLE master) as following text.

    @retval ::NRF_ERROR_RESOURCES 
    The connection event length configured for this link is not sufficient for the requested parameters.
    Use @ref sd_ble_cfg_set with @ref BLE_CONN_CFG_GAP to increase the connection event length.
    Inspect p_dl_limitation to see where the limitation is.

    Accordingly, to increase connection event length, I changed ble_cfg_set() function 
    in the heart_rate_collector (BLE master), but I got the error message that
    sd_ble_cfg_set() is failed due to invalid parameter, which is expressed the first figure.
    (my connection interval is 7.5ms in both BLE master and BLE peri)

    static uint32_t ble_cfg_set(uint8_t conn_cfg_tag)
    {
        const uint32_t ram_start = 0; // Value is not used by ble-driver
        uint32_t error_code;
        ble_cfg_t ble_cfg;
    
        // Configure the connection roles.
        memset(&ble_cfg, 0, sizeof(ble_cfg));
    
    #if NRF_SD_BLE_API >= 6
        ble_cfg.gap_cfg.role_count_cfg.adv_set_count        = BLE_GAP_ADV_SET_COUNT_DEFAULT;
    #endif
        ble_cfg.gap_cfg.role_count_cfg.periph_role_count    = 0;
        ble_cfg.gap_cfg.role_count_cfg.central_role_count   = 1;
        ble_cfg.gap_cfg.role_count_cfg.central_sec_count    = 0;
    
        error_code = sd_ble_cfg_set(m_adapter, BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, ram_start);
        if (error_code != NRF_SUCCESS)
        {
            printf("sd_ble_cfg_set() failed when attempting to set BLE_GAP_CFG_ROLE_COUNT. Error code: 0x%02X\n", error_code);
            fflush(stdout);
            return error_code;
        }
    
        memset(&ble_cfg, 0x00, sizeof(ble_cfg));
        ble_cfg.conn_cfg.conn_cfg_tag                 = conn_cfg_tag;
        ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = 247; // Changed by Kwonjoon @ 20190306, Previous Value : 150
    	
        error_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GATT, &ble_cfg, ram_start);
        if (error_code != NRF_SUCCESS)
        {
            printf("sd_ble_cfg_set() failed when attempting to set BLE_CONN_CFG_GATT. Error code: 0x%02X\n", error_code);
            fflush(stdout);
            return error_code;
        }
    
    	// Added by Kwonjoon @ 20190306 for Increasing Connection Event Length & Increasing LL Payload (Below)
    	memset(&ble_cfg, 0x00, sizeof(ble_cfg));
    	ble_cfg.conn_cfg.params.gap_conn_cfg.event_length = MSEC_TO_UNITS(6.25, UNIT_1_25_MS); // 3
    	
    	error_code = sd_ble_cfg_set(m_adapter, BLE_CONN_CFG_GAP, &ble_cfg, ram_start);
    	if (error_code != NRF_SUCCESS)
    	{
    		printf("sd_ble_cfg_set() failed when attempting to set BLE_CONN_CFG_GAP. Error code: 0x%02X\n", error_code);
    		fflush(stdout);
    		return error_code;
    	}
    	// Added by Kwonjoon @ 20190306 for Increasing Connection Event Length & Increasing LL Payload (Above)
        
    	return NRF_SUCCESS;
    }

    Questions :

    (1) How can I increase connection event length & LL data channel PDU payload length (data length)??
    (2) Where can I set the MTU of 247 bytes?? in both BLE master and BLE peri

    I really appreciate for reading of long questions,
    If you give me some comments, it will be huge help for me.

    Best regards,
    Kwonjoon Lee

Related