2020-05-20 02:15 AM
Hi,
I am using STM32L0 MCU
I am using HAL_USART_TRANSMIT function to send data to a computer
I am using Timer interrupt to ensure that UART transmits data every second
But when i see log on computer ,its not exactly 1 sec, and this change also varies with baudrate ,so if Baud rate is 115200 ,getting data on uart every 1.3 sec (approx.) and it is not same everytime,whereas with 9600 it is slower .
How to ensure that uart sends data at every 1sec ( with HAL API or LL API or any other way) ?
timer code(using systick timer)
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
if(flag_uart_delay == 0)
{
counter_uart ++ ;
if(counter_uart >= 1000)
{
flag_uart_delay = 1 ;
counter_uart = 0;
}
}
}
Main Code
if(flag_uart_delay == 1)
{
//HAL_TRANSMIT_DATA ( ... )
flag_uart_delay = 0 ;
}
Solved! Go to Solution.
2020-05-20 03:39 AM
@Guenael Cadier is right.
So, just throw away the
> if(flag_uart_delay == 0)
from the systick interrupt, and leave the rest, and you should be good.
JW