cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to use HAL UART Receiver IT Function?

rajpaged
Associate II
Posted on July 18, 2014 at 01:52

I'm trying to understand how the interrupt handlers works for the HAL UART module. I have the UART1 set with global interrupts using stm32cubeMX generated code, and am able to send and receive data into buffers.

Using the HAL_UART_Receive_IT() function, I see the application enter the HAL_UART_RxCpltCallback function once the buffer is full. How do I ready the module for another receive interrupt when I'm done in this callback handler? If I issue the HAL_UART_Receive_IT() function again at the end of the handler, my application gets stuck after a few receive interrupts.

I essentially want to use the UART to receive various console like commands (each different in length) so plan to use the callback handler to house a table of possible commands and act on them. As the interrupt only triggers on a full buffer, would I need to read single characters at a time, or is there a better way of doing this?

#stm32-hal-uart #hal #stm32f4 #uart #discovery
14 REPLIES 14
14545714
Associate II
Posted on May 30, 2015 at 07:28

Hi,

 I think you can use 

  __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);

  __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);

 to flush Rx and clear overrun flag.

  Recently I am using STM32L051xx, and I also need UART. I also think the HAL Uart code is somewhat foolish (Or maybe it would be impossible to write a function to fulfill the whole world, because different application needs different ways to handle the received buffer). Finally what I did is:

1. Use CubeMX to generate the code.

2. Keep the initialization code for UART.

3. Modify code to use my own function for starting Rx and UART IRQ handler, where I could handle my buffer freely. Of course, I could refer to the provided HAL code on how to access UART registers. Actually you have to add ''USART1_IRQHandler'' in your code to use interrupt mode. In this function, call you own IRQ handler, rather than ''HAL_UART_IRQHandler(...)'', which is provided by HAL.

  

  Thanks

vinayakrjoshi
Associate II
Posted on June 03, 2015 at 10:34

Hi Heisenberg,

I am trying to transmit the data using 

HAL_UART_Transmit_IT(&huart1, (uint8_t*)aTxEndMessage, len);

but if i define aTxEndMessage buffer locally, I am getting garbage data. but when i define it Globally i am getting right data. Don't know why? 

What's the problem in my case?

sammy_346
Associate
Posted on June 12, 2015 at 13:53

Its extremely disappointing to start out building an application, then find out that the code supplied by the manufacturer is not fit for purpose =(

dree86
Associate II
Posted on January 26, 2016 at 03:46

hei heisenberg

__HAL_UART_FLUSH_DRREGISTER()  seems no more. What is the replace function of it?

 

And I face problem with TX RX STM32. Its not stable. This function HAL_UART_ErrorCallback sometime called. I am using non blocking mode (IT).

I am using STM32L053 Discovery. What points to taken to init UART and to send and receive UART?
abdulhakeem
Associate
Posted on February 11, 2016 at 12:36

Hi Adri 

I am also using same STM32L0538 DISCO.

I am also facing same problem related UART .If resolved your problem please kindly share the source code of UART TX and RX.

Thank in advance