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

Sending data continuously via NUS with the ble_app_uart example

Hi all,

in my project I have a nRF52DK and a nRF52840DK. I will use the nRF52DK as peripheral and the nRF52840DK as central. For this I flashed ble_app_uart on to the peripheral and ble_app_uart_c on the central. This works like a charm :) . I am very happy with these examples.

For my project I want to send some data continuously from the peripheral to the central. So I need a continuous data transfer from the peripheral to the central. I need to achieve a data rate of ~50 kBit/s (~6,25 kByte/s). To achieve this data rate, I want to send for example 200 Bytes every 32 ms. The ble_app_uart example seems like a great starting point for this. In the ble_app_uart example the send function (ble_nus_data_send()) gets called by "enter" as input. So maybe I need to call this function in a loop or with a timer. But I am not quite sure how to implement this correct.

I am familiar with the basics of BLE (Connection Interval, MTU, DLE,..) and have a few experience with the programming of microcontrollers, but I am pretty new to the nRF environment.

So I want to ask you kindly, if you can give me some proper guidance on how to modify the ble_app_uart example to get this continuous data transfer via NUS?

I am looking forward to hearing from you. Thank you so much in advance.

Kind regards,

Maria

Parents
  • Hi Maria,

    Please take a look at the example attached below. It's a modified version of the ble_app_uart sample which I've been using to test throughput. It includes a timer instance to measure throughput that you can re-purpose to initiate the packet transfer. You may also want to increase the hvx queue size to allow you to queue more packets before getting the NRF_ERROR_RESOURCE error from sd_ble_gatts_hvx().

    Code to increase hvx queue

    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        ble_cfg_t ble_cfg;
    
        memset(&ble_cfg, 0, sizeof(ble_cfg));
        ble_cfg.conn_cfg.conn_cfg_tag = APP_BLE_CONN_CFG_TAG;
        ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 30; // Number of packets in queue

    7534.nrf5_sdk_17.0.2 - ble_app_uart_throughput.zip

    Kind regards,

    Vidar

  • Thank you very much for your reply and your throughput example.

    Is 30 the maximum size of hvn_tx_queue_size?

    Thank you in advance.

    Kind regards,

    Maria

  • It's only limited by how much RAM you have available. But 30 packets is probably already way more than what you will need. 200 bytes will fit into one packet when you have long MTU support enabled.

    Kind regards,

    Vidar

  • Hello,

    thank you for your quick response.

    in order to achieve my required data rate of 50 kBit/s, I call the ble_nus_data_send() function every 32ms with 200 Bytes of data. I set NRF_SDH_BLE_GAP_EVENT_LENGTH to 10 and hvn_tx_queue_size to 30.

    I set the connection interval on central and peripheral to 31,25 ms (for min. and max). 

    But I am receiving ERROR 19  [NRF_ERROR_RESOURCES] after I called the ble_nus_data_send() function for about 10 to 30 times. 

    Here are my questions:

    1. Do I miss something here?

    2. Can you please help me to achieve this 50 kBit/s data-rate?

    3. What are the ideal connection parameters to achieve this?

    Thank you very much in advance. I hope you can help me again.

    Kind regards,

    Maria

  • Hello Maria,

    Could you try with the example I sent and see what throughput you get then? Also, how many packets are you attempting to send per timer event? 

    Kind regards,

    Vidar

Reply Children
  • Hello Vidar Berg,

    I had to add the following to the ble_stack_init:

        err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_cfg, ram_start);
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_CONN_CFG_GATTS.",
                          nrf_strerror_get(err_code));
        }

    It looks like the queue size was not applied before. I have to do further testing, but I it looks promising at the moment. It seems that it works now.

    Thank you very much.

    Kind regards,

    Maria

Related