2022-04-15 02:11 PM
Hello,
I am trying to synchronize 2 STM32 microcontroller's using UART and DMA. System clock is 80MHz. Timer1 is set to interrupt at 1ms with 1us resolution. Synchronization logic is executed every 1ms, Serial Transmission at master/slave side is every 1ms. In-order to synchronize perfectly reception at both the ends should be at the same time (1ms). Ideal skew should be 0. If Skew is more the Timer period tries to adjust according to skew.....this is intended sync logic I am trying to implement. Please let me know if you have any suggestions or questions as Sync is achieved sometimes but not always.
Thanks!
2022-04-15 02:41 PM
What's the accuracy of the clocks in each of the systems?
How far apart are the systems?
If they sync to a common pulse you should be way sub-ms at this point.
Latch the value of a free running 32-bit timer on each system, use that as your timebase.
2022-04-15 03:30 PM
Hello Thanks for the reply.
1.I am not sure what you mean by accuracy of clocks.......The 2 microcontroller have separate clock source which is 8MHz crystal.....
2. Both microcontroller chips are approx 1 cm apart.
2022-04-15 04:36 PM
The offset each has in ppm?
Why not use a common clock source?
2022-04-15 05:30 PM
2022-04-15 07:17 PM
Do they have to synchronize to an external source of time, or just each other?
I'd probably have each generate a 1PPS based on their own crystal/PLL clock, and then measure the clock cycles locally, and use that timebase/reference as a means to place 1ms period interactions. Should be able to trigger thing at better than us level.
Probably use 32-bit TIM2/TIM5
2022-04-16 05:06 AM
You dont describe, what you sync. UART is async protocol and crystal ppm on speeds 115200 is not relevant error.
2022-04-16 09:19 AM
> But, unfortunately I have a requirement that 2 chips need to be sourced with different source as one
might fail.
This doesn't seem to make much sense. If clock source of one MCU can fail, then it won't be able to communicate as well.
Every STM32 has internal clock and can detect failure of external clock.
Make common redundant external clocks, or run each MCU on its internal clock (more reliable without external oscillator) and use SPI for communication?
2022-04-16 09:29 AM
They have to Sync to each other with UART communication skew of 0 usec(ideally).
2022-04-16 09:34 AM
I want to sync both MCU's in-order to Tx/Rx message at same time. It's async protocol, but I want to sync it based on skew of Tx and Rx of slave device.