2024-09-29 10:56 AM - edited 2024-09-29 10:57 AM
I am using an stm32 timer calculator ( https://deepbluembedded.com/stm32-timer-calculator/ ) to get the settings for a 20ms timer and got the following values: https://imgur.com/a/oMHS17r which I set for my TIM16 timer.
I am using the following code:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim == &htim16)
{
int t = HAL_GetTick();
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, SET);
HAL_TIM_Base_Start_IT(&htim15);
char m[30];
sprintf(m, "1: %d\r\n", t);
HAL_UART_Transmit(&huart2, (uint8_t*)m, 30, HAL_MAX_DELAY);
}
}
to check if it works as expected every 20ms and it doesn't seem to work as intended, since it triggers every 17-18ms.
Does someone have an idea why its not working correctly?
PS: Here is an image of my clock tree: https://imgur.com/a/7bcML52 and I am using a STM32 Nucleo-32 L432KC
Solved! Go to Solution.
2024-09-29 11:19 AM
The UART transmission duration was accounting for the lost 2-3 ms
2024-09-29 11:19 AM
The UART transmission duration was accounting for the lost 2-3 ms
2024-09-29 04:06 PM
When you're in a interrupt, you want to set a flag and exit right away. Then in main while loop, you check the flag and send your UART data.