cancel
Showing results for 
Search instead for 
Did you mean: 

Receving a string from terminal via UART

akoluacik
Senior

Hey, I would like to a string from terminal via UART in order to complete a challange given by Digi-Key YouTube channel in FreeRTOS tutorial playlist. Anyway, I want to take the whole string given by user in terminal, but I couldn't so far. I tried

 

 

HAL_UART_Receive(&huart2, (uint8_t*)rcvd_msg, MSG_LEN, 100);

 

 

however it didn't work. It can take only the first letter and nothing else. btw, I don't want to use interrupts in this case, so it is better to suggest something without interrupt.
Thanks for your answers. 

7 REPLIES 7
Sarra.S
ST Employee

Hello @akoluacik 

I would say consider using HAL_UART_Receive_IT or HAL_UART_Receive_DMA instead, but since you don't want to use interrupts (despite the fact that it is a convenient option), set UART reception in circular DMA mode

Also which STM32? 

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.

TDK
Guru

Perhaps wait longer than 100ms for the message to come through. Unclear how it's being sent from the terminal program, but it sounds like it's one letter at a time, as you type them.

Or read them in one character at a time into a buffer.

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

I don't wanna make complex the program since it is just a homework, but will consider it if cannot find a solution.
BTW, I didn't think it is important but my board is STM32F411RE.

Actually, I am using RealTerm, what I want to do is it gets all characters till it sees a \r character, but it does is only one character and it assigns to all indexes of a buffer.

TDK
Guru

You can also try HAL_UARTEx_ReceiveToIdle which is better than the regular HAL implementation.

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

It can take only the first letter and nothing else

Candidate #1: Receiver overflow. Check and clear the overflow OR disable the overflow detection if your STM32 has this feature.

Karl Yamashita
Lead II

It depends on your terminal program. If it sends each character as you type then you may only get 1 or 2 at most characters before it times out in 100ms. If it's one character at a time, then HAL_UART_Receive is not what you want to use.