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

nRF51 wrong sequence in received packets

I'm using nRF51822_xxAA , with SDK12.3.0 and Softdevice S130 v2.0.1 on Keil V5.29.0.0. And as a central I use Redmi 7A phone with Android V10.
I want to sample ADC @ 200Hz, and send the sample as 2 bytes inside a packet of 20 bytes (10 ADC values) at real-time. To make sure all the packets have been successfully received, I've simulated the process to generate a sawtooth signal every time ADC interrupt has been triggered, then when a 20Bytes packet is full it'll be sent over BLE, then received on the phone then saved to a file.

The problem is when I drew the data I've saved, I found there was a wrong sequence in receiving packets, for example, when I send 3 packets of data, I send them as follow:
[Packet_1][Packet_2][Packet_3]...
but when when I receive them, sometimes, I receive them as follow:
[Packet_1][Packet_3][Packet_2]...
since :
1- I've added TX_COMPLETE_EVT to the characteristic I use, and check it before sending a new packet, and that didn't help.
2- I'm creating the data packet inside adc_event_handler() and when the packet is full I set a flag, then the packet will be sent inside the main function, for (;;) loop (not app_scheduler).
3- MIN_CONN_INTERVAL = MSEC_TO_UNITS(8, UNIT_1_25_MS) = 10ms.
4- MAX_CONN_INTERVAL = MSEC_TO_UNITS(10, UNIT_1_25_MS) = 12.5ms.
5- Other connection parameters are as default.
6- my for (;;) loop, doesn't have any delay function.
7- I'm using 3 ADC channels together, all of them is being sampled with the same frequency, but I'm sending only one channel's value.
8- The phone app I use I've written it on android studio 4.1

The question is where does the problem exist? in the peripheral or central side? and how to fix it?

Thanks in advance!

Parents
  • example, when I send 3 packets of data, I send them as follow:
    [Packet_1][Packet_2][Packet_3]...
    but when when I receive them, sometimes, I receive them as follow:
    [Packet_1][Packet_3][Packet_2]...

     I think this should not be possible to receive the swapped packets since BLE in its core have sequence numbers for packets so that the receiving controller layer will not accept a packet in wrong sequence order. It seems that there is something wrong in the way you are interpreting the data.

    It would help us if you show us some code snippets on how you are sending data on the TX side and how you are pulling data on the receiver side.

  • for central side:

    1-When using Bluetooth Low Energy on nRfconnect for pc, there were no problems, I can send my data over BLE @200hz, and get them as correct as I sent.

    2- When using nRFconnect for mobile phone (android), there was no wrong sequence order in data packets, but when my phone had no enough RAM (i.e. there are other APPs are working together at the same time), in this case there was missed BLE packets, when I checked the log file, I've found that packet is missed there too 

      

    where P1 and P2 are the received packets, but there must be another packet between them because the mcu is generating a sequence of numbers between 0 and 100.

Reply
  • for central side:

    1-When using Bluetooth Low Energy on nRfconnect for pc, there were no problems, I can send my data over BLE @200hz, and get them as correct as I sent.

    2- When using nRFconnect for mobile phone (android), there was no wrong sequence order in data packets, but when my phone had no enough RAM (i.e. there are other APPs are working together at the same time), in this case there was missed BLE packets, when I checked the log file, I've found that packet is missed there too 

      

    where P1 and P2 are the received packets, but there must be another packet between them because the mcu is generating a sequence of numbers between 0 and 100.

Children
No Data
Related