cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Receive stuck

YoussefElbattah
Associate III

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,

 

 

7 REPLIES 7
Danish1
Lead II

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?

Andrew Neil
Evangelist III

Aside:

 


@YoussefElbattah wrote:

i send "AT\r\n"

 


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

TDK
Guru

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

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,

 

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,

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,


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