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

BLE UART losing packets

Hi all,

I am using PCA10040 with nRF5_SDK_13.0.0 and using the ble_perpheral -> ble_app_uart example.

I am trying to stream data from UART to an android phone and the data is coming from an external MCU with its TX/RX pin connected to the RX/TX pin on the NRF52DK. Every 40ms, I am sending a line of characters up to 49 bytes (max), terminating with a new line character.

Somehow, the android app is not able to receive the data and it only able to receive 1 out of every 3 lines of characters, and this is very consistent. Here is the log file from the app:

10:12:52.531 "4 111 222 333 211564 212372 212076 999999 0" received I 10:12:52.550 Notification received from 6e400003-b5a3-f393-e0a9-e50e24dcca9e, value: (0x) 37-09-31-31-31-09-32-32-32-09-33-33-33-09-32-31-31-35-30-37-09-32-31-32-34-30-33-09-32-31-32-30-36-34-09-33-32-36-34-35-09-30-0D-0A

10:12:52.572 "7 111 222 333 211507 212403 212064 32645 0" received I 10:12:52.596 Notification received from 6e400003-b5a3-f393-e0a9-e50e24dcca9e, value: (0x) 31-30-09-31-31-31-09-32-32-32-09-33-33-33-09-32-31-31-35-31-35-09-32-31-32-33-33-31-09-32-31-32-30-38-31-09-33-32-33-30-30-09-30-0D-0A

10:12:52.621 "10 111 222 333 211515 212331 212081 32300 0" received I 10:12:52.643 Notification received from 6e400003-b5a3-f393-e0a9-e50e24dcca9e, value: (0x) 31-33-09-31-31-31-09-32-32-32-09-33-33-33-09-32-31-31-35-32-30-09-32-31-32-33-36-36-09-32-31-32-30-34-34-09-33-32-33-31-31-09-30-0D-0A
A 10:12:52.662 "13 111 222 333 211520 212366 212044 32311 0

It basically receiving the 4th, 7th, 10th line etc, and losing the 5th, 6th, 8th, 9th etc lines. Can anyone advise on how this problem can be solved?

Thanks in advance!

Parents
  • Are you checking the returned error code of ble_nus_string_send()? Is it always NRF_SUCCESS (0x00000000)?

  • Hi Petter,

    The default codes does the following:

            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ((data_array[index - 1] == '\n') || (index >= (m_ble_nus_max_data_len)))
                {
                    NRF_LOG_DEBUG("Ready to send data over BLE NUS\r\n");
                    NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                    do
                    {
                        err_code = ble_nus_string_send(&m_nus, data_array, index);
                        if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
                        {
                            APP_ERROR_CHECK(err_code);
                        }
                    } while (err_code == NRF_ERROR_BUSY);
    								
    							
                    index = 0;
                }
                break;

    The do-while loop is constantly checking for NRF_ERROR_BUSY. I presume its constantly trying to send the string until successful then it breaks out of the do-while loop. Perhaps this is taking too much time and hence its losing packets inbetween?

    If so, is there anyway to rectify the problem? I think it should be able to transfer much faster than that!

Reply
  • Hi Petter,

    The default codes does the following:

            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ((data_array[index - 1] == '\n') || (index >= (m_ble_nus_max_data_len)))
                {
                    NRF_LOG_DEBUG("Ready to send data over BLE NUS\r\n");
                    NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                    do
                    {
                        err_code = ble_nus_string_send(&m_nus, data_array, index);
                        if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
                        {
                            APP_ERROR_CHECK(err_code);
                        }
                    } while (err_code == NRF_ERROR_BUSY);
    								
    							
                    index = 0;
                }
                break;

    The do-while loop is constantly checking for NRF_ERROR_BUSY. I presume its constantly trying to send the string until successful then it breaks out of the do-while loop. Perhaps this is taking too much time and hence its losing packets inbetween?

    If so, is there anyway to rectify the problem? I think it should be able to transfer much faster than that!

Children
No Data
Related