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

Missing UART received data with ble_app_uart

nRF52832
nRF5 SDK V17.0.2
SoftDevice S132 V7.2.0

I am running the sample program ble_app_uart in the above environment, but sometimes I miss UART received data.
Teraterm is used for data transmission to UART of nRF52832, and self-made software (C #, Windows 10) is used for BLE communication reception.
No problem occurs when sending data by keyboard input of Teraterm, but when a text file is sent by sending a file of TeraTerm, it is missed.
The text file used contains only ASCII characters from 0 to 9 and CR.
The position where the omission occurs often occurs near the 9th to 11th lines of the text file.
The shorter the length of one line, the more frequently it occurred, but even if it was made longer, it could not be resolved.
If you set 20msec for the wait after sending one line in Teraterm settings, the omission will be resolved.
It was improved by reducing the values of MIN_CONN_INTERVAL and MAX_CONN_INTERVAL in main.c, but it could not be solved.
I changed UART_TX_BUF_SIZE and UART_RX_BUF_SIZE in main.c from 256 to 1024, but I couldn't solve it.

Please let me know if there is a good way to eliminate the omission of UART received data.

Communication log example
Received data was missed on the 10th, 11th, and 13th lines, and the number of characters in one line is no longer 80 characters.

'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(37byte) = '234569012345678901234567890123456789
'LE RxData(15byte) = '23456123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(60byte) = '23456678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789
'LE RxData(80byte) = '1234567890123456789012345678901234567890123456789012345678901234567890123456789

Parents Reply Children
  • Hi,Jared

    sorry for the late reply.
    Thank you for your response.
    I tried to set UART_TX_BUF_SIZE and UART_RX_BUF_SIZE 4096 but did not get better.
    The IRQ priority set by UART_INIT did not want to change the priority.
    (APP_IRQ_PRIORITY_HIGHEST, APP_IRQ_PRIORITY_HIGH, APP_IRQ_PRIORITY_MID did not work:Hanged)

    Eliminate CR / LF reception from the condition that sends to BLE, add it
    By setting MIN_CONN_INTERVAL to 8 and MAX_CONN_INTERVAL
    UART The missing data missing is not zero but improved.

    It is likely to reply because it works on this work,
    I will try if I can improve a little more.


    Before correction:

    void uart_event_handle(app_uart_evt_t * p_event)
    {
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;

    switch (p_event->evt_type)
    {
    case APP_UART_DATA_READY:
    UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    index++;

    if ((data_array[index - 1] == '\n') || // <- Remove
    (data_array[index - 1] == '\r') || // <- Remove
    (index >= m_ble_nus_max_data_len))
    {
    if (index > 1)
    {
    NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    NRF_LOG_HEXDUMP_DEBUG(data_array, index);

    do
    {
    uint16_t length = (uint16_t)index;
    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);


    Revised:

    void uart_event_handle(app_uart_evt_t * p_event)
    {
    uint32_t err_code;

    switch (p_event->evt_type)
    {

    case APP_UART_DATA_READY:
    if( uartEventRxBlockIf0 != 0 )
    {
    UNUSED_VARIABLE(app_uart_get( &uartRxBuf[ uartRxBufIndex ]));
    uartRxBufIndex++;

    regards
    Matsumiya
  • Hi,

    Have you disabled APP_UART_COMMUNICATION_ERROR and APP_UART_FIFO_ERROR in uart_event_handle()? The application should assert if the FIFO gets full. On a second thought, can you use uart flow control in your project?

    regards

    Jared 

  • Hi,Jared

    APP_UART_COMMUNICATION_ERROR

    APP_UART_FIFO_ERROR

    These events are currently ignored.
    Do I need to add processing to clear the error?
    UART flow control can not be used because the communication partner does not support.

    void uart_event_handle(app_uart_evt_t * p_event)
    {
    uint32_t err_code;

    switch (p_event->evt_type)
    {

    case APP_UART_DATA_READY:
    if( uartEventRxBlockIf0 != 0 )
    {
    UNUSED_VARIABLE(app_uart_get( &uartRxBuf[ uartRxBufIndex ]));
    uartRxBufIndex++;
    if (( uartToBleBlockIf0 != 0 ) && ( uartRxBufIndex >= m_ble_nus_max_data_len))
    {
    nrfx_rtc_cc_disable( &rtc, RTC_CH_UART_TMOUT );
    if ( 0 < uartRxBufIndex )
    {
    do
    {
    err_code = ble_nus_data_send(&m_nus, uartRxBuf, &uartRxBufIndex, m_conn_handle);
    } while (err_code == NRF_ERROR_RESOURCES);
    }
    uartRxBufIndex = 0;
    }
    else
    {
    nrfx_rtc_cc_set( &rtc, RTC_CH_UART_TMOUT, ( nrfx_rtc_counter_get( &rtc ) + RTC_CNT_UART_TMOUT ) & 0x00ffffff, true );
    }
    }
    break;

    case APP_UART_COMMUNICATION_ERROR:
    // modified from sample   APP_ERROR_HANDLER(p_event->data.error_communication);
    break;

    case APP_UART_FIFO_ERROR:
    // modified from sample    APP_ERROR_HANDLER(p_event->data.error_code);
    break;

    default:
    break;
    }
    }

    regards

    matsumiya

  • Hi,

    Most likely you are getting an error because the FIFO fills up. The application is not able to process the data in the FIFO before new data arrives. I think you have to rewrite this application for it work as you intend. You could:

    1. Define a buffer that you can use to store the data from the FIFO while it's processed. 

    2. The ble_app_uart example sends the data as soon as it receives a newline. This is not good for maximum throughput as it causes the application to send multiple ble packets without filling them completely up. The sending of data has some overhead, so preferably you would only want to do it when the ble packet is full. Try removing this check:

  • Thank you for telling me.
    The second measures have already been decided to make sure it is effective.
    I will try the first measures from now on.

Related