cancel
Showing results for 
Search instead for 
Did you mean: 

When is HAL_UART_RxCpltCallback called?

arduo
Senior

Hi there,

I am new with UART and want to use my own UART Functions and i found the function

HAL_UART_RxCpltCallback and HAL_UART_TxCpltCallback.

When are this Functions called? I found them in the documentation of stm but that didn't explain well when they will be called.

Thanks in advance

6 REPLIES 6
Bob S
Principal

You have the HAL source code. Go look for it.

MNapi
Senior II

it is rather simple you setup UART as global interrupt in Cube MX

the best way is to setup for example

 HAL_UART_Receive_DMA in you main() loop, not while(), it will listen all the time and jump there to execute whatever you want

and you use for example in Keil

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

 UNUSED(huart);

}

for example in /* USER CODE BEGIN 4 */ and put inside whatever you want to execute.

the explanation there isn't very helpful

"Give a person a fish, you feed him for a day. Teach a person to fish and you feed them for a lifetime".

I'm not going to spoon feed you the answer. Show us that you've done a little bit of work first. Have you tried looking at the HAL UART source? If you can't find where or when the function is called, or have trouble understanding the circumstances when it is called, I'll be glad to help. The HAL code can be a bit difficult to follow some times, though at least in the L4xx HAL library this particular function usage looks pretty straight forward.

The problem is in the HAL UART source it's only described as follows: When data reception is finished, it will be called by interrupt handle function.

This give me the information that this function is called every time a byte is received in the UART Interface isn't it?

Reading comments is a good start, but to know what REALLY happens, and when and why, search for every place that calls this function. THAT will tell you the exact circumstances when it gets called. A hint: it is called from multiple functions, depending on how you are receiving data (polled, interrupt or DMA). FInd the one(s) that pertain to how you intend to use the UART in your own code.