Skip to main content
Explorer II
November 28, 2023
Question

Receving a string from terminal via UART

  • November 28, 2023
  • 5 replies
  • 3232 views

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. 

    This topic has been closed for replies.

    5 replies

    ST Employee
    November 28, 2023

    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? 

    akoluacikAuthor
    Explorer II
    December 2, 2023

    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.

    Super User
    November 28, 2023

    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.

    akoluacikAuthor
    Explorer II
    December 2, 2023

    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.

    Super User
    December 2, 2023

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

    Super User
    December 2, 2023

    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.

    Graduate II
    December 2, 2023

    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.