2024-06-21 05:55 AM - edited 2024-06-21 05:56 AM
I just find my HAL_UART_Transmit() function cost 15ms. why does it cost so much time?
The UART speed is 19200, and I use GPIO set and reset function to check the time cost.
Total data length of send buffer is 29 bytes. and I use a 15ms polling loop to call this function, so it cost me over 30ms for every msg sending task, but for 19200 speed, it should only need 12.1ms for each 29 bytes.
I assume this reason may be caused by the HAL_UART_Transmit() function is a sync function, it needs to wait all the data tranferring finished. is it right? If yes, is it means I can reduce my robin task period?
Kind Regards
RichKnight
Solved! Go to Solution.
2024-06-21 07:11 AM
12.1ms are the pure data bits (29*8*(1/19200)), but you have to add the start and stop bits per byte. This results in (29*(8+1+1)*(1/19200)) ~ 15.1ms.
Hope it's a bit clearer now?
Regards
/Peter
2024-06-21 06:09 AM
Why don't you use interrupt based uart transmit? Please explain your constraints?
2024-06-21 06:13 AM
Yes, Interrupt based can be considered, I just want to test if I can use the simple way to trigger the transmit.And my question is if it is reasonable for so long time cost in this function.
Thanks
Richknight
2024-06-21 07:11 AM
12.1ms are the pure data bits (29*8*(1/19200)), but you have to add the start and stop bits per byte. This results in (29*(8+1+1)*(1/19200)) ~ 15.1ms.
Hope it's a bit clearer now?
Regards
/Peter
2024-06-21 07:14 AM
Thanks for your explanation!