Skip to main content
Explorer
March 14, 2024
Question

HAL_UART_Receive stuck

  • March 14, 2024
  • 3 replies
  • 2848 views

Hello everyone,

 

I am trying to communicate with lora e5 using usart1, when i send "AT\r\n" command and i try to receive data from the same uart(lora) the function while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status) blocks the execution because RXNE after receiving goes automatically to 0.

 

Best Regards,

 

 

    This topic has been closed for replies.

    3 replies

    Graduate
    March 14, 2024

    RXNE is automatically cleared when RXD is read.

    A complication happens if you have set your debugger to look at the UART, the debugger will read RXD. Thereby clearing RXNE. Might this be your problem?

    Explorer
    March 15, 2024

    Hi Danish1,

    Do you mean by RXD the register which contains data of the buffer RX "RDR" or something else ?

    If you mean the buffer, it already contains the '+' equivalent to 0x2b in hex data which is the first caracter if the response "+AT : OK", and i haven't yet read the buffer RXD for RXNE to switch back to zero.

    Best Regards,

     

    Super User
    March 14, 2024

    Aside:

     


    @YoussefElbattah wrote:

    i send "AT\r\n"

     


    You don't need the \n - just a \r is required to terminate AT commands.

    Explorer
    March 15, 2024

    Hi Andrew,

    I think that the "AT\r\n" command works because i have tried the "AT\r" and just now it sends back only "+A" i dont know why it sends back only "+A" instead of "+AT : OK" i have changed the timeout to 1000 instead of HAL_MAX_DELAY, and the size of the buffer where i receive the data is 50 bytes

    Best regards,

    Super User
    March 14, 2024

    If you don't know how many characters are coming in, use HAL_UARTEx_ReceiveToIdle instead. Probably the issue is you're trying to receive more characters than are coming in.

    Explorer
    March 15, 2024

    Hi TDK,

    i have tried this API and it doesn't work it sends back "\r\n", and now it works the problem was the sizeof the buffer, the parameter size of the buffer that i send to uart_receive was strlen but my buffer doesn't contains data. So, it was empty and the API stores nothing, now i have changed strlen with sizeof and it works :)

    Best Regards,

    Super User
    March 15, 2024

    @YoussefElbattah wrote:

    i have tried this API and it doesn't work it sends back "\r\n", 


    What are you referring to as "it" here?

    As the name suggests, HAL_UARTEx_ReceiveToIdle()  is at the receiving end - not the sending end - so it doesn't "send" anything.

    But I would expect the response to "AT" to be a "\r\n" (for formatting) followed by the "OK" response ...