What cause the empty PDU

Dear Support Team

I use the nRF5 SDK's ble_app_uart_c sample and ble_app_uart sample to test peripheral send data to central. On the application layer, I called ble_nus_data_send() founction to send one packet which 10bytes per 20ms and the BLE connection interval I set is 20ms. Below is my 20ms callback function implementation.

static void Test_20ms_founction(void * p_context) 
{
  ret_code_t err_code;
  if((SEND_RDY == 1) && (CONN_RDY == 1))
  {  
     call_counter_start = 1;
     do
        {
            uint8_t Test_array[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0xaa, 0xbb};
            uint16_t Test_lenght = sizeof(Test_array);
            err_code = ble_nus_data_send(&m_nus, Test_array, &Test_lenght, m_conn_handle);
            if ((err_code != NRF_ERROR_INVALID_STATE) &&
                (err_code != NRF_ERROR_RESOURCES) &&
                (err_code != NRF_ERROR_NOT_FOUND))
            {
                APP_ERROR_CHECK(err_code);
            }
        } while (err_code == NRF_ERROR_RESOURCES);
        SEND_RDY = 0;
        packet_counter++;
        NRF_LOG_INFO("packet_counter = %d, SEND_RDY = %d", packet_counter, CONN_RDY);
        if(packet_counter == 0xffff) packet_counter = 0;
  }
  if(call_counter_start == 1)
  {
    call_counter++;
    if(call_counter == 0xffff) call_counter = 0;
    NRF_LOG_INFO("Test_20ms_founction call time:%d",call_counter)
  }
}

But I used the Sniffer to catch the packet on the air, But there are empty PDUs in some connection event like picture below, I would like to know what cause this and how to void these empty packet. Because l would like to send one packet per 20ms on the air but in fact it send one packet per 40ms .

The enclosed file is my code. many thanks.

4466.ble_app_uart_c.7z

Parents
  • Hi,

     

    Unfortunately, it seems that the peripheral code was not uploaded properly. Could you please re-upload this?

     

    Without having tested or looked deeper into the implementation, I would recommend that you use deferred logging, as logging in the handler will delay the function.

    Either set sdk_config.h::NRF_LOG_DEFERRED to 1, or try to limit log printing in your callback handler to see if this has an impact on the behavior.

     

    Kind regards,

    Håkon

  • Hi Håkon 

    Sorry for that, I upload the peripheral code again.

    But I found that the NRF_LOG_DEFERRED has been set to 1 both in these two sample by default.

    Many thanks.

    1067.ble_app_uart.7z

  • Hi,

     

    Thanks for sharing. 

    I think you want the do-while to be checked with this:

    do {
    ...
    } while (err_code != NRF_ERROR_RESOURCES);

     

    You should also set sdk_config.h::NRF_SDH_BLE_GAP_DATA_LENGTH to 27 or higher. It was set to 23 by default.

    To send more packets per connection interval, you can also consider adjusting sdk_config.h::NRF_SDH_BLE_GAP_EVENT_LENGTH to a higher number.

    The 40 ms comes from the RTC prescaler. You should set the sdk_config.h::APP_TIMER_CONFIG_RTC_FREQUENCY to '0' to fix this.

     

    Here's a small screenshot from the sniffer after making the adjustments above:

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Thanks for sharing. 

    I think you want the do-while to be checked with this:

    do {
    ...
    } while (err_code != NRF_ERROR_RESOURCES);

     

    You should also set sdk_config.h::NRF_SDH_BLE_GAP_DATA_LENGTH to 27 or higher. It was set to 23 by default.

    To send more packets per connection interval, you can also consider adjusting sdk_config.h::NRF_SDH_BLE_GAP_EVENT_LENGTH to a higher number.

    The 40 ms comes from the RTC prescaler. You should set the sdk_config.h::APP_TIMER_CONFIG_RTC_FREQUENCY to '0' to fix this.

     

    Here's a small screenshot from the sniffer after making the adjustments above:

     

    Kind regards,

    Håkon

Children
Related