nRF52833 Nordic UART Service, sending multiple PDUs per Connection Interval

Hello

Here is an overview of an issue we are having with our BLE project right now. I am not familiar enough with it to be able to explain it very clearly right now, but I will follow up with more information soon.

We have a BLE application running on an nRF52833.

The project was initially created from an nRF example application, in Keil uVision (I don’t know which application is was example created from, but I will find out).

The nRF device uses the Nordic UART Service to send the data to the iOS app, specifically this function:

     ble_nus_data_send()

An iOS app connects to the nRF device, and the nRF device sends data to the iOS app.

The nRF device has one sample of approx. 230 bytes ready to send every 16 msec, which is enough to send in one PDU.

The connection was established using the 2Mbit PHY and, up to and including iOS 15, the device managed to stream all its data “live” to the iOS app. This is because the connection interval established between the iOS app and the nRF device was 10 or 15 ms (I am not sure which).

However, since iOS 16, when I look at the Connect Event parameters sent by the iOS app, the Connection Interval is 30 ms, with a Window Size of 3.75 ms.

So now the nRF device seems to have a backlog of data to send. Eventually all the data is transmitted, but, for example, what used to be sent “live” in 10 seconds, now takes 20+ seconds.

Theoretically, there should be time for the slave / nRF device to send multiple packets within that 3.75 ms window of time.

So, I have a few questions (if you have enough information):

Is there a mechanism within the Nordic UART Service to send multiple packets during the one Connection Interval? If so, is it dependent on some defines - e.g. a buffer/array size?

 

Also, looking at the logic of the code that is trying to send data to the iOS app, essentially it is this:

  • Call ble_nus_data_send() to send data.
  • If the return value is NRF_SUCCESS, all good.
  • If the return value is NRF_ERROR_RESOURCES or NRF_ERROR_BUSY, then try again when
  • nus_data_handler() indicates an BLE_NUS_EVT_TX_RDY event

In this way, the code keeps trying to stuff data in to the UART, whenever it has data, and whenever the BLE_NUS_EVT_TX_RDY event is indicated.

Something must be wrong with this logic, because if it was correct, then maybe the nRF device would manage to send more than one PDU within the 3.75 ms window that it has during each Connection Interval.

I don't know if I have given enough clear / correct information for you to offer an opinion, but please do if I have Slight smile

Regards

Garrett

 

 

 

  • Hello,

    • Call ble_nus_data_send() to send data.
    • If the return value is NRF_SUCCESS, all good.

    When it returns with SUCCESS, do you immediately call it again if you have more data to send? It is by queuing up multiple packets that you will be able to send more packets per connection event. 

    You can also increase the notification queue size in the Softdevice through the sd_ble_cfg_set() API. This will allow you to queue up more packets before getting the 'NRF_ERROR_RESOURCES' error. Here is an example of how you can increase the notification buffer in the ble_stack_init() function:

    diff --git a/examples/ble_peripheral/ble_app_uart/main.c b/examples/ble_peripheral/ble_app_uart/main.c
    index 36d1a82..1044acb 100644
    --- a/examples/ble_peripheral/ble_app_uart/main.c
    +++ b/examples/ble_peripheral/ble_app_uart/main.c
    @@ -427,6 +427,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
     static void ble_stack_init(void)
     {
         ret_code_t err_code;
    +    ble_cfg_t ble_cfg;
     
         err_code = nrf_sdh_enable_request();
         APP_ERROR_CHECK(err_code);
    @@ -437,6 +438,19 @@ static void ble_stack_init(void)
         err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
         APP_ERROR_CHECK(err_code);
     
    +        
    +    // Configure the minimum number of notification that can be queued with sd_ble_gatts_hvx().
    +    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 = 10;
    +    
    +    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));
    +    }
    +
         // Enable BLE stack.
         err_code = nrf_sdh_ble_enable(&ram_start);
         APP_ERROR_CHECK(err_code);

    Note: the Softdevice will require more RAM when you increase the packet buffer. If you get an error, check the debug out log, it will tell you if you need to increase the application RAM start address to leave more RAM to the Softdevice.

    Best regards,

    Vidar

Related