cancel
Showing results for 
Search instead for 
Did you mean: 

How can I invoke UART_Receive_IT() automatically when I receive a data?

VR
Associate II

I am new to STM32 and CubeMX. I need to write a program to send and receive data from a module via UART port. I have to send(Transmit) a data to that module(for eg. M66). Then I would return to do some other tasks. once the M66 send a response to that, my seial-port-receive-function(HAL_UART_Receive_IT) has to be invoked and receive that response. How can I achieve this? or Shall I call HAL_UART_Receive in interrupt mode and let it check for the data from module?

I need to complete this ASAP...Thanks in Advance

2 REPLIES 2
e-zeki
Associate III

"my seial-port-receive-function(HAL_UART_Receive_IT) has to be invoked and receive that response. "

That's pretty much HAL_UART_Receive_IT() does.

you can initialize uart interrupt to receive data with HAL_UART_Receive_IT() so it only goes to check when reception occurs.

UART_Receive_IT() starts the process, and then you use it in your callback function to reinvoke it next time.

You'd probably want to use it in one byte mode, be also be conscious that the callback happens in interrupt context, and you must complete within a single byte time, and not block.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..