cancel
Showing results for 
Search instead for 
Did you mean: 

Time Drift Between 2 Identical Black Pill boards

TTT
Associate II

STM32F401 (Blackpill) – 2.4s Drift in 30 Minutes Between Two Identical Boards Using TIM2 (HSI Clock)

I am working on time synchronization between two identical Blackpill STM32F401CCU6 boards.

Both boards:

  • Use internal HSI oscillator

  • Same firmware

  • Same clock configuration

  • TIM2 configured as 1 MHz free-running counter (1 µs resolution)

  • 32-bit counter (auto-reload = 0xFFFFFFFF)

Clock configuration:

  • HSI ON

  • PLL enabled (HSI → PLL → SYSCLK)

  • SYSCLK = 32 MHz

  • TIM2 prescaler = 31 → 1 MHz timer tick

Initialization

  • Both boards started in STANDALONE mode
  • Both boards waited for button interrupt
  • The board which gets interrupt became MASTER

Synchronization Method

  • One board acts as MASTER

  • Other board acts as SLAVE

  • Communication via UART (115200 baud)

  • Master sends a 5-byte sync packet:

    • 0xAA + 4-byte counter value

  • Slave receives and sets:

    htim2.Instance->CNT = received_counter; 
  • UART disabled and connection removed

Initial sync works correctly.

Problem

After synchronization:

  • Drift increases over time

  • After 30 minutes → ~2400 ms difference

  • After 50 minutes → ~3200 ms difference

This corresponds to approximately:

~1300 ppm difference between the two boards.

Both boards are identical and running the same firmware.

Questions

  1. Is this drift expected when using HSI?

  2. What is the typical HSI accuracy (ppm) for STM32F401?

  3. Would switching to:

    • External crystal (HSE)

    • LSE
      significantly reduce drift?

  4. Is there a recommended method for long-term time synchronization between two STM32s without external clock sharing?

Additional Notes

  • No hardware clock sharing between boards

  • No external crystal currently used

  • Only UART connection between boards, and removed after sync

I would appreciate any guidance on improving long-term timing stability.

Thank you.

5d2c9cdb-8dc7-422e-b9cc-81b2d7b0c9cd.jpg
512df020-aea1-461d-8c5f-6a1cc51f3b32.jpg1f60dc85-8974-4544-8f67-6971d84baa8d.jpg

 

14 REPLIES 14

Unfortunately, not applicable. The screens will be placed stationary place and cameras mounted on a vehicle.

Do you have any suggestions for XO or TCXO?

Any crystal oscillator with MCU power supply range.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Even with a low drift clock source I would calibrate the clocks. As the error of both clocks can be opposite so the differential error can be higher. Connect the boards to let them sync (let one board output a square wave and the other capture it). You can do this once and then save the calibration to non volatile memory. Since both modules likely have the same ambient temperature I think their differential drift will be minimal.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
CTapp.1
Senior III

Another option could be to use a GPS module with a sync pulse output - this will pulse once per second with an accuracy of 1uS (I think, but it's been a while since I've done this!).

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)