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

Approach for synchronize two devices

Hello,

in our project we have a nRF52840DK as central (s140) and a custom board with nRF52832 chip as peripheral (s132). The software on the nRF52840DK is based on the ble_app_uart_c example and the software on the nRF52832 chip is based on the ble_app_uart example. The nRF52832 sends data to the nRF52840DK via NUS. This works fine. 

We want to roughly know, how "old" our data is, when it is received by the nRF52840DK. For this the data get timestamped. The idea is that the real-time clocks on the two devices are roughly in sync. The nRF52840DK will then know how "late" the data is. After some research, this should be achievable by implementing the following:

  • Device 1 enables the NUS notification and starts the real-time clock with the right prescaler.
  • Device 1 makes use of the ble_radio_notification to know exactly when to start the RTC.
  • Device 2 receives the "enable of the NUS notification" and starts the real-time clock as well with the same prescaler.

For implementing this correctly, we have a few questions:

  1. Where gets the NUS notification enabled in the ble_app_uart and ble_app_uart_c example?
  2. How to use the ble_radio_notification right?
  3. Where gets the "NUS notification enabled" received by ble_app_uart and ble_app_uart_c example on the other device?
  4. How to start the real-time clock with the right pre-scaler?

Thank you so much in advance.

Parents Reply Children
  • Hello,

    thank you awneil, haakonsh, and Dmitry for your help.

    At the moment I am trying to implement my "synchronization" with a simple "sync" message over NUS, as awneil mentioned: 

    Just send a "sync" message over NUS, and put that, with local timestamp, into your log.

    I send my "sync" message every 10s to reduce timer drift. I am using radio notifications for accurate timings of the "sync" message.

    Dmitry´s suggestions look very interesting. Unfortunaly I am not allowed to stop any activity for some time, as Dmitry mentioned (high data rate): 

    ensure that no packets are in hvn queue (stop any activity for some time)

    I already took a look to this blog post, haakonsh. I was able to run the code on two evaluation boards with nRF52832 chips. I visualized the timers of both boards and they were perfect synchronous. But I have two problems with this type of synchronization. First, it seems that it only works fine with two equal nRF chips on either side (maybe hardware timings?), which is not the case with my nRF52840DK and my custom nRF52832 board in my project. Second, the timers were synchronous, but didn´t contain the same values or maybe I was not able to read them out properly.

    So at the moment I will try it with the simple "sync" message over NUS as awneil mentioned and work with timestampes and offsets.

    Thank you again for you amazing support.

Related