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

    By moving BLE transmit to MAIN instead of UART_EVENT_HANDLE
    UART The problem of missing data was solved.

    UART_EVENT_HANDLE counts the number of UART receive bytes, and when the BLE packet size is reached, BLE transmit request flag is set.
    If Main is a BLE transmission request flag standing, BLE transmit is performed.
    If the UART received data does not come for a predetermined time, it transmits the received UART data even if the BLE packet size is not satisfied.
    By doing this, UART receive data could be prevented from being missing.

    Thank you for your response.

    main:

    for (;;)
    {
    if (nrf_sdh_is_enabled())
    {
    sd_app_evt_wait();
    while( 0 < uartToBleChkReq )
    {
    uartToBleChkReq--;
    result_app_uart_get = NRF_SUCCESS;
    i = 0;
    while(( result_app_uart_get == NRF_SUCCESS ) && ( i < m_ble_nus_max_data_len ))
    {
    result_app_uart_get = app_uart_get( &uartRxBuf[ i++ ]);
    }
    if( result_app_uart_get != NRF_SUCCESS )
    {
    i--;
    }
    if( ( result_app_uart_get == NRF_SUCCESS ) ||
    (( result_app_uart_get != NRF_SUCCESS ) && ( 0 < i ))
    )
    {
    SEGGER_RTT_printf( 0,"[INFO] main : Do BLE Tx(%hu).\n", i );
    do
    {
    err_code = ble_nus_data_send(&m_nus, uartRxBuf, &i, m_conn_handle);
    } while (err_code == NRF_ERROR_RESOURCES);
    }
    }
    }
    }


    uart event handler:

    void uart_event_handle(app_uart_evt_t * p_event)
    {
    switch (p_event->evt_type)
    {

    case APP_UART_DATA_READY:
    uartRxCnt++;
    nrfx_rtc_cc_disable( &rtc, RTC_CH_UART_TMOUT );
    if( m_ble_nus_max_data_len <= uartRxCnt )
    {
    uartToBleChkReq++;
    uartRxCnt = 0;
    }
    nrfx_rtc_cc_set( &rtc, RTC_CH_UART_TMOUT, ( nrfx_rtc_counter_get( &rtc ) + RTC_CNT_UART_TMOUT ) & 0x00ffffff, true );
    break;


    RTC event handler:(Use RTC2)

    static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
    {

    cntr = nrfx_rtc_counter_get( &rtc );
    if (int_type == NRF_DRV_RTC_INT_COMPARE0) // UART RX TIMEOUT
    {

    uartToBleChkReq++;
    nrfx_rtc_cc_disable( &rtc, RTC_CH_UART_TMOUT );

    }

    regards

    matsumiya

Related