STM32f405 clock synchronize
Hello,
I'm trying to use two identical stm32f4 boards to synchronize tick of one with respect to other.
I'm using can to using can protocol for communication in Interrupt mode.
So the Master is supposed to be always running and the slave when powers up send a sync request to master, the master receives the message in interrupt and send the current tick to the slave from the callback. The slave receives the tick which is used as an offset to the current slave tick for delay purposes .
NOW after this transaction both the MCU start to toggle the LED at the same time. (I have verified the waveform on oscilloscope).
But after some time(30 min) a lag starts to appear between them(80ms) which keeps on increasing. For both MCU i'm using 24Mhz external oscillator and the MCU are running at 80Mhz.
Does anybody has any Idea what's the cause between this increasing lag. I know these kind of things occur due to clock drift but that's why i'm using an external crystal.
Thanks,
Altamash Abdul Rahim
while(1)
{
uint32_t currentTick = 0;
currentTick = HAL_GetTick();
#if SLAVE
currentTick += tick;
#endif
if(blinkLed)
/* Enabled in callback of both MASTER{when sending value to SLAVE} & SLAVE{when receiving tick from MASTER}*/
{
if(currentTick - lastTick >= 2000)
/*For MASTER lastTick = HAL_GetTick() when sending tick
For SLAVE lastTick = tick received from master
*/
{
print_string("Tick %u\n", (unsigned int)currentTick);
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_12);
lastTick = currentTick;
}
}
}