Skip to main content
YoussefElbattah
Associate II
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,

 

 

3 replies

Danish1
Lead III
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?

YoussefElbattah
Associate II
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,

 

Andrew Neil
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.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
YoussefElbattah
Associate II
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,

TDK
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.

"If you feel a post has answered your question, please click ""Accept as Solution""."
YoussefElbattah
Associate II
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,

Andrew Neil
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 ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.