My application has two 580, a master and a slave
I want the two to have time synchronization ,and the time accuracy is 0.01s, better to be 0.001s.
Assuming that the synchronisation requirement applies only to a connected state, you should be able to rely on the timing of connection events ending (this event can be detected in rwble.c - look for the BLE_EVT_END in that file).
I studied your advice these days, I suppose the master and slave BLE_EVT_END happens synchronously, I can get the time immediately after BLE_EVT_END happens from both sides, then I can have the time synchronized.
while BLE_EVT_END happens so frequently, I can't find the corresponding events from the two sides, how to solve this problem?
Thanks a lot.
The BLE_EVT_END events on BLE master and slave should be as close to syncronous as you can get. If you want to limit when the synchronization takes place, you can implement a GATT characterisitic that you write to which then drives the logic to synchronize on the end of the following event. You can add your synchronization code in the rwble.c right after the event has been recorded (this line records the event: arch_rwble_last_event = BLE_EVT_END; - note that you will find this line twice in rwble.c. Which one of them that actually is executed depends on your power optimization setting). There may be a fixed time delay between the event triggering on the central and the event triggering on the peripheral, but it will be small, constant, and could therefore be compensated for.
One of the advantages of using the BLE_EVT_END is that you will have a lot of time available to manage the synchronization algorithm. No high priority IRQs will need processing until the next connection event.
You can use the function uint32_t lld_evt_time_get(void) to get the current time in increments of 625us. If you need better timing than that, you will have to disable sleep and use the systick timer which could provide as low as 1us accuracy.
Please let us know if you manage to implement the suggested solution. I imagine that this synchronization scheme would be really powerful in conjunction with ultra-sound in a ranging/distance application. Properly implemented, you could likely get to inch or even centimeter type precision.
Thanks a lot for you quick response.
My question centers around how to 'recognize' the corresponding BLE_EVT_END of the same connection from master and slave,because the event comes one after another very quickly,I can't distinguish different BLE_EVT_END events.
The application is distance application, but not ultra-sound ranging.
0.01s time synchronization accuracy can meet my application requirement,better synchronization is preferred as I don't need to reset the synchronization due to time drift for short time use,I will implement the suggested solution, but now I focus on how to 'recognize' the corresponding BLE_EVT_END from two sides.
Writing to a characteristic and knowing the connection interval should allow you to tag a connection. Transmission of the data will happen on the following connection event and so will reception on the server side (again, there could be an offset, but this offset should be constant). The client will receive a confirmation when the data has been transmitted, the server will receive an indication that data has arrived.
我的问题是两个580主从时间同步的问题，如何才能确定主从的BLE_EVT_END为相对应的Event呢？ 因为 BLE_EVT_END 是在不停快速地重复出现，我不知道如何确定主从对应的Event。
Thanks a lot for you answer.
To be frank, I'm a new hand in this field and though I feel your answer may be the right one to my question, after a lot study, still don't know how to do.
1.What is the confirmation and indication? BLE_EVT_END? or other event?
2.Still I don't know how to tag the connection, there should be some thing different to distinguish it, I think.
Hope you will not be impatient about my questions.