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

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

Children
Related