Time gap between each team sending data via BLE nrf52840

Good day support team, 

In my project, I save the packet of 60bytes then send it via BLE with ble_nus_data_send(). (20kHz sampling rate)

I set the timer = 50us.

uint16_t count;
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
        UNUSED_PARAMETER(event_type);
        count++;
}

I want to check the time gap between each time BLE send. Instead of saving data, I save the count timer value then send it via BLE. 

y-axis is count value with unit : 50us

x-axis is data number

I expect if ble_nus_data_send() process fast enough ( < 50us), I will see the linearity in the graph but there was delay between each packet.

The time gap I mentioned above happened random. 

I appreciate any suggestion and explanation.

Thank you very much.

Best,

 

Parents
  • Hi,

    I do not see the code snippet where you actually send the BLE packet.

    • Is it inside the timer handler?
    • what is the priority of the timer interrupt?
    • What is the processing time of the handler in which ble_nus_data_send is being called?
    • 50uS can be very ambitious speed if you have something other than the timer handler running in the background (for example you have other contexts where you get and process sensor data)
    • You need to add some GPIO toggles in the handler start and end where you call ble_nus_data_send to know the actual latencies of your handlers. You should do the same with another gpio for other contexts you have in the same/higher priority as the priority of the handler you can ble_nus_data_send.

    If you can share all your application handler contexts and the interrupt priorities and the GPIO toggle timing for each of this context, then we will have enough information to see if you can transmit 60Bytes of data with 20KHz frequency of incoming sampled data. 

    Also check your MTU size and see to it that it is bigger than 60 bytes so that every data is sent in one packet and not in multiple packets.

  • I just want to update some information. 

    I put GPIO before and after ble_nus_data_send() function.

    In the first 4 cycle, ble_nus_data_send() need around < 100us to complete.

    But after that the function need ~30ms to complete sending the packet of 243 bytes. Why is it too long? Is there any way to fasten it? 

    Best,

  • MinhDuc said:
    But after that the function need ~30ms to complete sending the packet of 243 bytes. Why is it too long? Is there any way to fasten it? 

    Hoang, There are a lot of variables that contributes to the delay in your send function. Most importantly, the priority of the timer handler function and if there are any other higher priority context running. I would suggest you to enable systemview debugging to get an overview of all the contexts that are running in your application so you get a clear picture as to why you see that 30ms delay.

  • Hello, 

    I increase the hvn_tx_queue_size, extend the connection event. I solve the problem.

    ble_cfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 50;

    opt.common_opt.conn_evt_ext.enable = 1;

    Thank you!

Reply Children
No Data
Related