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

BLE UART send bytes

I'm using ble_nus_string_send() to send 15 bytes over BLE UART.

As expected it sends 15 bytes, however on occasion 14 bytes are sent instead of 15 bytes.

Would there be a particular reason for this to occur?

void uart_event_handle(app_uart_evt_t * p_event){
#define LEN15 15
static uint8_t data_array[LEN15];
static uint8_t index = 0;
uint32_t       err_code;

switch (p_event->evt_type)
{
    case APP_UART_DATA_READY:

        app_uart_get(&data_array[index]);
        index++;

        if ( index >= (LEN15) )
        {
            err_code = ble_nus_string_send(m_nus, data_array, index);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }

            index = 0;
        }
        break;

    case APP_UART_COMMUNICATION_ERROR:
        //APP_ERROR_HANDLER(p_event->data.error_communication); // this resets nRF51
        if(m_handler)
        {
            m_handler();
        }

        break;

    case APP_UART_FIFO_ERROR:
        APP_ERROR_HANDLER(p_event->data.error_code);
        break;

    default:
        break;
}

}

Parents
  • Hi

    Are you surely calling ble_nus_sting_send function with index = 15 every time? Any error code returned from ble_nus_sting_send function? Are you perhaps only sending one byte every time? To maximize throughput, you should set 20 bytes in each packet, i.e. call ble_nus_sting_send first when you have accumulated 20 bytes for transmission. One call to ble_nus_sting_send will transmit one data packet over BLE.

    Are you using the standard ble_app_uart example from nRF51 SDK 11.0.0? nRF51 or nRF52? What softdevice?

    Perhaps the softdevice buffer is full. In that case, you will receive error BLE_ERROR_NO_TX_BUFFERS. See also these threads (1) (2) and the documentation for sd_ble_gatts_hvx which is the function used to send notification packets.

Reply
  • Hi

    Are you surely calling ble_nus_sting_send function with index = 15 every time? Any error code returned from ble_nus_sting_send function? Are you perhaps only sending one byte every time? To maximize throughput, you should set 20 bytes in each packet, i.e. call ble_nus_sting_send first when you have accumulated 20 bytes for transmission. One call to ble_nus_sting_send will transmit one data packet over BLE.

    Are you using the standard ble_app_uart example from nRF51 SDK 11.0.0? nRF51 or nRF52? What softdevice?

    Perhaps the softdevice buffer is full. In that case, you will receive error BLE_ERROR_NO_TX_BUFFERS. See also these threads (1) (2) and the documentation for sd_ble_gatts_hvx which is the function used to send notification packets.

Children
No Data
Related