2024-03-14 03:31 AM
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,
2024-03-14 04:08 AM
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?
2024-03-14 04:15 AM
Aside:
@YoussefElbattah wrote:i send "AT\r\n"
You don't need the \n - just a \r is required to terminate AT commands.
2024-03-14 06:43 AM
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.
2024-03-15 12:30 AM
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,
2024-03-15 12:45 AM
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,
2024-03-15 01:13 AM
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,
2024-03-15 03:21 AM
@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 ...