cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize 2 STM32 micro using UART and DMA

HDevi.1
Associate II

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!

13 REPLIES 13

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HDevi.1
Associate II

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.

The offset each has in ppm?​

Why not use a common clock source?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HDevi.1
Associate II

  1. Please see below screenshot from component datasheet.
  2. That's a good point. But, unfortunately I have a requirement that 2 chips need to be sourced with different source as one might fail.

0693W00000Ly89AQAR.png

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MM..1
Chief II

You dont describe, what you sync. UART is async protocol and crystal ppm on speeds 115200 is not relevant error.

Pavel A.
Evangelist III

>  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?

They have to Sync to each other with UART communication skew of 0 usec(ideally).

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.