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

BLE Transmission Latency

Hello, 

I have two nRF52832 (BL652) modules setup and connected through an RF cable. I am feeding the peripheral radio (2x) 174 byte packets every 5 ms. On the central, I am monitoring the receiving of these packets using the RTC clock and tracking the elapsed time between receiving these two packets from the peripheral. I have noticed that often times my latency climbs up to 15 ms, but most of the time it is around 5 ms. Is there a reason for this? I would expect to see some latency due to re-transmission, but not if I am connected through a RF cable.

I am using HVX notification transmissions from the peripheral, and occasionally sending packets from the central using a WRITE_CMD. My connection interval is set to be 7.5 ms, I have my CONN_SUP_TIMEOUT set to 1 second, and my SLAVE_LATENCY set to 0.

I modified the NUS example to where the main routine calls a new HVX transmission if the previous one ended with NRF_ERROR_RESOURCES. Should I move that to an APP_TIMER to give higher priority?

I confused as to why the latency would drift that far. Do I need to have all of the HVX packets loaded with the outgoing data before the beginning of the connection interval? Am I not able to load  the HVX buffers with new data after the connection interval is underway? I was hoping that every other CI would have 4 packets of 174 bytes (10ms), and therefore maintain the rate. Should I increase my CI to 15 ms?

As an odd side note, it seemed like I needed to increase NRF_SDH_BLE_GAP_EVENT_LENGTH to a large value (300) as opposed to using 6 like the CI would require. That is the only way to get better latency, otherwise it was around ~30ms.

I would really appreciate some guidance.

Thanks,

Chris

  • I was waiting on BLE_GATTS_EVT_HVN_TX_COMPLETE, but what I discovered was that sometimes I would get that interrupt and not have any data ready to send. I would then get in a state where I could call sd_ble_gatts_hvx() twice. The timing was a little difficult to work out, but with checking every 100us it seems to work well.

    My apologies, the 6 meters was using antennas. My initial question was why I was having latencies over an RF cable. I had latencies of around 15 ms on an RF cable, but I think I have since discovered that they are due to loading data every 5 ms, and using a connection interval of 7.5ms. Eventually, I would have a connection interval with no data ready for transmission.

    You mentioned that it would be better for me to lower the size of the payloads and that might help with latency? I am trying to transmit (2) 174 byte packets every 7.5ms. Should I break that up? Does that improve the latency? What would you recommend for optimal transmission size?

    So if the packet is interfered with, then the retransmission does not happen until the next connection interval? Does that also mean that all other packets behind it are halted until the next connection interval?

  • You are correct. If a packet get corrupted, re-transmission will only happen on the next connection interval. 

    The reason for it is that there is a MD bit in each of the head of packet from the central to the peripheral, telling there is More Data to come. When seeing the MD bit, the peripheral will expect a (next) packet in the same connection interval. But when the pakket is corrupted, it will not stay listen mode and consider the connection event is finished. 

    If you need to transmit lots of data that smaller packets (meaning lower throughput) can't handle then you would need to use longer MTU. But if throughput is as important as the latency requirement you can consider using smaller packet size. Says 4 packets/event, each packet 23 bytes, 7.5ms interval, you can have 98kbps. 

  • I would like to transmit approx. 560 Kbps with the minimal latency. What would you recommend as a good packet size? I have about 348 bytes / 5 ms. Is there some optimal recommendation to minimize latency and still allow the throughput?

    Thank you,

  • We unfortunately haven't got any test to find the optimal packet length for different throughputs (and it's varied, depends on the environment, interference, range). 

    But one improvement you can think of is to use 2Mbps to transmit the data packet 2x faster hence reduce the risk of interference to half.

    Since you have 2 nRF52832 on both ends, and if you don't require a good range (2Mbps has shorter range compare to 1Mbps) it should be quite simple to switch the communication to 2Mbps. 

  • I appreciate the help. I have been running at 2Mbps, and verified using the nRFSniffer. I still see the latency at those speeds.

    Any other ideas? Is it possible to lower the CI in BLE if I am running two nRF devices? Sort of a custom version?

     Thanks 

Related