cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit cost 15ms?

RichKnight
Associate II

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.

RichKnight_0-1718974064446.png

RichKnight_1-1718974149729.png

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
Techn
Senior III

Why don't you use interrupt based uart transmit? Please explain your constraints?

If you feel a post has answered your question, please click "Accept as Solution".

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

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks for your explanation!