cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize multiple microcontrollers

Zedestrian
Associate II

I have multiple devices with stm32L5 mcu playing led animations and connected via RS-485. However, when I send a command via RS-485 to start led animations, they become asynchronous. I want to use an mcu clock as reference and send it to all others mcu via RS-485 then calibrate it based on the first one's clock, but don't know how to measure clock ticks and configure it. I don't know where to start.

Any suggestions or thoughts are welcomed.

2 REPLIES 2
Danish1
Lead II

Nothing is perfect. No matter how accurately you calibrate your clocks, they will drift apart. If at all possible, have one device send out periodic "frame" messages, and have the others resynchronise to those messages. You will need to think how to synchronise the ones that receive the frame messages; you don't want them to freeze waiting for a message, and also have to cope with them running more slowly than the reference.

As to how often those messages have to be, it depends how rapidly the clocks drift apart, and how far drifting is acceptable.

Internal oscillators e.g. HSI drift much worse than crystal-controlled oscillators e.g. HSE or LSE

Hope this helps,

Danish

Zedestrian
Associate II

Thanks for your answer Danish.

I'm using RTOS with mutilple Tasks, One task that is blocked most of time unless it's time to update led frames and other task that should be used to receive or send clock ticks. I just want the delay to become unnoticed. Is there any Hal function that give clocks ticks and some other hal function to callibrate or configure the mcu clock ?

Zed