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

UART FIFO Missing bytes when BLE transmission is going on

Hello, 

I am using Nordic nRF52840 (nRF5SDK v16.0.0) and softdevice : s140.

Nordic MCU is connected to Host MCU over UART interface (baudrate = 115200). I have below observation:

When we send byte stream from Host MCU to Nordic and Nordic is transmitting over Bluetooth, then sometime UART Rx fifo misses one byte in reception.

Does anyone knows about this behavior ?

I tried sending 6 uart packets (each of 178 bytes) back to back over uart and same packet is being transmitted over Bluetooth using the UART test code.


} while (err_code == NRF_ERROR_RESOURCES);

code snippet from void uart_event_handle(app_uart_evt_t * p_event)
                      uint16_t length = (uint16_t)(index-4);// removing datalen (starting2 bytes [0] [1]) + cmdID([2])  and  '\n'(EOF) from the data which is being sent over BLE
                      err_code = ble_nus_data_send(&m_nus, &data_array[3], &length, 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);
                    

Parents
  • Are you using HW flowcontrol for the uart? if not, that could explain the missing rx bytes as there could be overrun errors when used with high baudrate and in the combination of bLE.

    The workarounds/solutions for these can be

    1. use uart hw flow control
    2. increase the uart interrupt priority while initializing uart (increase priority in ARM is reducing the priority numberm lower the value in NVIC, higher the priority.)
    3. handle the overrun error in when you get the APP_UART_COMMUNICATION_ERROR and figure out a way to tell the peer uart to retransmit the whole transaction or just ignore the lost packet and reset your communication.
Reply
  • Are you using HW flowcontrol for the uart? if not, that could explain the missing rx bytes as there could be overrun errors when used with high baudrate and in the combination of bLE.

    The workarounds/solutions for these can be

    1. use uart hw flow control
    2. increase the uart interrupt priority while initializing uart (increase priority in ARM is reducing the priority numberm lower the value in NVIC, higher the priority.)
    3. handle the overrun error in when you get the APP_UART_COMMUNICATION_ERROR and figure out a way to tell the peer uart to retransmit the whole transaction or just ignore the lost packet and reset your communication.
Children
  • Hello Susheel, 

    No i am not using HW flow control BUT i did checked for overrun error and i am not getting any error for overrun. 

    Currently priority used is : APP_IRQ_PRIORITY_LOWEST (default configuration in test example). If try to make is high : APP_IRQ_PRIORITY_HIGH, Bluetooth transmission doesnt work correctly).

    It appears that in some flow of Softdevices transmission, either UART interrupt is disabled OR bluetooth transmission time is high and we need to add delay in transmission from host controller, not sure for this and need your help.

    If i keep on receiving 178 bytes over UART but only send 10 bytes over Bluetooth, byte reception works fine. If i make this Bluetooth send count to 50 , again i miss bytes during reception. 

    Triggering of bluetooth transmission is same as in example : from void uart_event_handle(app_uart_evt_t * p_event) ->  err_code = ble_nus_data_send(&m_nus, &data_array[3], &length, m_conn_handle);

  • I think you need to understand the time it takes for receiving/transmitting your uart data and sending that on BLE. 178 bytes should not be a problem if you have a larger MTU size. You also have to fine tune your connection interval/MTU size/UART priority and analyze how much overhead (pre and post processing) time is spent for UART tx/rx and also BLE TX/RX. 

    It looks to me that the baudrate is too high for the overhead you have for processing your data for rx and tx. Either optimize your data processing time to reduce it to a bare minimal in ISR or reduce the baudrate.

  • Thanks for your reply, i did tried moving the send routing to main loop (out of interrupt) and implement an application layer FIFO to handle data from interrupt to main loop.

    Still issue happens : when Bluetooth send API is called (ble_nus_data_send (..)) and during this transmission, if host controller is sending any data over uart, we are missing bytes at times.

  • onishant82 said:
    Still issue happens : when Bluetooth send API is called (ble_nus_data_send (..)) and during this transmission, if host controller is sending any data over uart, we are missing bytes at times.

     The bytes cannot go missing without any error in the receiving side. Can you please add some logs in the uart_event_handle like below to see if there is ANY error at all.

            case APP_UART_COMMUNICATION_ERROR:
                NRF_LOG_ERROR("Communication error occurred while handling UART.");
    If not, then I have to understand more on what you mean exactly by missing bytes. With FIFO in place and no RX errors, i have not heard of any missing bytes in UART. 
     
    One other thing you can check is to temporarily enable flow control in nRF and also peer uart and connect the two pins (RTS/CTS to peer). Check if this improves the situation. What i am trying to get at is that it is hard for me to understand missing bytes without UART RX throwing some error. I am trying to exclude HW errors, so that we can purely focus on software.
  • Hello Susheel, 

    I just observed that at times i do get APP_UART_COMMUNICATION_ERROR. Since we already have hardware and we did not planned for RTS/CTS , so these hardware options are not there. 

    Any suggestion for APP_UART_COMMUNICATION_ERROR root cause ?

Related