2026-05-26 9:57 AM - last edited on 2026-05-26 10:10 AM by Andrew Neil
Hi,
Am using blackpill with F411 mcu at 100MHz, with Timer1 configuration:
Clock source: internal clock
Prescaler: 9999
Counter period: 9999
So Timer1 ticks every 1 second (1Hz)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
secEllapsed++; // volatile uint16_t variable
}
In main body
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
sprintf(strLCD, "%6d seconds", secEllapsed);
i2c_lcd_SetCursor(0, 0);
i2c_lcd_PrintStr(strLCD);
}
But the result is about 24 seconds less every 10 minutes.
So what is the problem?
Edited to apply source code formatting - please see How to insert source code for future reference.
2026-05-26 10:05 AM - edited 2026-05-26 10:14 AM
24 s / 10 min is just 4%. That's ok for internal clock...
But could be better. Maybe your I2C delays the Timer 1 interrupts
2026-05-26 10:11 AM
welcome to the forum
Please see How to write your question to maximize your chances to find a solution for best results.
Note that Black (and other coloured) Pill boards are not ST products, and likely do not contain a genuine STM32.