We are developing our code based on the peripheral UART (NUS) example and are currently testing the baseline before applying our own changes. I have 2x nrf52840-DK boards, one for peripheral and another for central. We are using nrfConnect SDK 2.5.0. My application needs to transfer between 10 and 250 bytes approximately 4 times second. In addition to throughput, we do also care about latency.
The changes so far compared to the example are:
- increase in stack size which was needed for it to run with debugging;
- reduced the UART Rx timeout from 50ms to 1ms
- added some debug prints in the background thread.
I'm having issues (and these are present even if I undo the changes 2 and 3 listed above). I'm sending a data packet of 7 characters (terminated with \r \n) into both Peripheral and Central at roughly 100ms intervals and checking what was received at the peer. I wait for the data to be received before I send the next packet. Specifically the issues seen:
- Sometime there are missing bytes Peripheral to Central. Logging shows the ble_write_thread did not receive all bytes ... they must have been missed by the UART driver. So far the missing byte(s) are at the end of each 7 byte packet.
- If I increase the data packet size to 250 bytes I get much more data loss.
- Central to UART direction works for a while and then lose much more data.
Questions:
- Are there known data loss issues with the peripheral UART driver?
- Do I need to increase buffers somewhere else in order to send 250 byte data; presumably I should to increase the MTU, please provide a link on how to do that.
- Should I switch to indications? If I use indications I understand I cannot send more data until I get the peer acknowledgement. But what happens if that acknowledgment never comes? Should I resend after a timeout?