This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART over BLE: A few of first 100 bytes getting corrupted

Hello lovely Nordic Semiconductor staff (and everyone else reading this),

I have recently been working on exploring the use of BLE via Nordic chips in my employer's products. We're hoping to be able to switch to using BLE with the UART service Nordic provides to transmit data from the company's devices to a smartphone app we have developed, but we expect that there will usually be tens of kB of data to transmit each time, and because we want the process to be quick and easy for the user, we need to have a reasonably high throughput. I have been able to consistently achieve rates of about 8-10 kB per second, which should be enough for our purposes. The problem is that when I have tested this by transmitting some sample files I created, the files are regularly becoming corrupted on the way (approximately 50-70% of the time I think). This is a problem because we need all the data to be totally correct. The apparent corruption seems to be somewhat unpredictable however (but see further below).

For the exploratory testing, I have been using an nRFR52 DK, running a slightly customised version of the ble_uart_app sample program provided in the SDK, incorporating modifications put forward by Petter Myhre in this thread to send the data, to stand in for one of the company's devices. Data is pumped into the DK using a Python script, originally based on one Adafruit made for their Bluefruit LE Friend - though the script I am using now is very heavily modified from that one. I have tested the Python script's reliability using a serial cable to connect two computers, and that appears to be totally rock-solid, so I don't think the problem is there.

For the receiving side of things I have adapted the UART part of the nRF Toolbox iOS and Android apps. Basically, the apps receive data, then store it in a file. That file is compared to a reference file stored on the phone, and I can check whether for each transmission the file was corrupted or not. I have repeated these tests numerous times, sending anywhere from 5 files, to 1000 of each of five different sized text files, using an iPhone 7, a Samsung Galaxy S4, and an ASUS Nexus 7 tablet. In every instance, a very significant number of the total received files (pretty much always 50%+) have come up as corrupted, regardless of file size.

I have used command line commands like cmp and FC (for Windows command prompt) to compare the files, and I have noticed that in every single file comparison I have made, it appears that the corrupted file only has a few bytes corrupted. Usually 1 or 2, and I haven't seen more than 5 at once. The other weird thing is that it is always within the first 100 bytes of the file, regardless of whether the file is 200 or so bytes, or about 70 kB, or anything in between. I looked at the size of the packets coming in to the phones from the DK, and I noticed that seemingly every time I send a file, the first 100 or so packets are always 1 byte each (never less than 100 for some reason), but later packets are usually the full mtu size that the phone and DK have agreed upon. I am honestly not sure why that should be happening, but I do wonder if that is connected to the errors I'm seeing.

In an effort to try to isolate where the problems appear to be occurring, I used the data logging capability of the J-Link RTT Viewer to check the data that is being provided to the softdevice in the app running on the DK. Immediately after each packet of data has been successfully passed to the softdevice (i.e. immediately after the function ble_nus_string_send() has returned with error code NRF_SUCCESS), the data_array is written out to the data logging channel with a SEGGER_RTT_Write() call. This technique has been a little finicky, but I have managed to get a repeated number of files of different sizes back out of the DK using it, and in every instance the file is uncorrupted as compared to the reference file that was being fed into the DK via the Python script. This leads me to think that the problem is occurring somewhere between the data being loaded into the softdevice buffer, and it's eventual receipt by the smartphone/tablet on the other end.

I'm honestly not sure what the problem could be. I have tried playing around with different parameters, such as setting the connection interval really high or really low, e.g. 7.5ms to 500+ms, and that doesn't seem to have made any difference. I have also used the default mtu size, as well as upping the mtu size to the maximum each phone will accept. I have used Data Length Extension on the iPhone (the Android devices I have to test on are a little old and don't seem to be advanced enough to do DLE). I increased the size of the Rx and Tx buffers for the application. Again, none of that seems to have made any difference. I did stumble across this other DevZone question today, which I thought might be having the same issue as me, but I'm not sure.

I'm reasonably confident it isn't the receiving devices (or at least, not totally them), because I was able to transmit files fine when using the Adafruit Bluefruit LE Friend - that was just much too slow for my purposes. The files are sometimes received fine with the nRF52 DK, just not nearly often enough for it to be considered reliable enough for us to progress to trying to put nRF BLE chips into some versions of our devices. At this point I am stumped about the problem, and I can't think of what else I can try to avoid it. Could you please advise? Thanks for your time and efforts.

  • Thank you for the detailed problem explaination. I'm not sure what the issue could be, but we should first try to narrow it down a bit. Have you done a sniffer trace? With for example the nRF Sniffer? Then you can check if the actual packet on the air is correct, it would tell us if the problem is on the nRF5 or on the other side of the link.

  • Hi Petter. Thanks for your response. I have now done a sniffer trace using an Adafruit Bluefruit LE Sniffer we had on hand (which I think uses Nordic components). I have checked the sniffing on one of the files that was corrupted, and the sniffed packets appear to be correct. I would be happy to send the relevant files through to your team if that would be helpful. I had thought that since we were seeing very similar results on both iOS and Android, it was likely some issue with the DK, but this appears to suggest it might be a problem on the receiving devices' end. I hopefully will be able to try a nRF52 DK to DK test tomorrow. Do you have any further suggestions or ideas? Thanks.

  • I agree that similar results on Android and iOS would point to an issue with the nRF5, but if the sniffed packets are correct, the issue is probably on the other side of the link. Testing DK to DK is a good idea. If that works, I guess you need to look into the app, and try to figure out if the problem is with the app or the underlying Android/iOS system.

  • Hi Petter. I have been able to do some testing between two development kits. I ran into an issue with the receiving one (running a slightly modified version of the ble_uart_c example program) getting stuck, and so my tests halting, but from the results I could get, it looks like the transmission of the files is working very solidly between DKs. My apologies to you and the team for suggesting that it might be your product at fault! We've still got a couple of ideas on more things to test (e.g. disconnect-reconnect after each file transmission), but we're now thinking that we'll be making a bug report to Apple and Google about it in the near future. Thanks for your time.

  • No problem :) Hope you get it to work/find a workaround. If there isn't anything else, maybe you could close this?

Related