cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to read UART and to hold on rx_data array. when I send "AT" to rf module it returns "OK" , but on my code I cannot receive anything from UART. and help appreciated

TPiri.1
Associate II

uint8_t tx_data[2] = "AT";

 uint8_t rx_data[10];

 HAL_Delay(1000);

 while (1)

 {

 HAL_UART_Transmit (&huart1, tx_data, sizeof(rx_data) , 250);

 HAL_Delay(500);

 HAL_UART_Receive(&huart1,rx_data, 20,1000);

 HAL_GPIO_TogglePin (GPIOA, LED_Pin);

 HAL_Delay(500);

}

37 REPLIES 37

I tried "AT\r\n" as well , same result , no data from uart

MM..1
Chief II

Togles your LED ?

have you initialised UART properly parity num bits speed ?

I think so, only changed baud rate to 9600

0693W00000HpgXWQAZ.png

note: I use Nucleo L476Lgr. board

on NVIC Settings have you enabled IRQ USART?

no, I haven't . I don't use interrupt, I am using POLL method

This need too be enabled

Bob S
Principal

Your python code works because python has the UART RX always receiving data and storing it in a buffer. The sleep() call just waits long enough for the radio to respond. The lora.read() simply reads whatever is ALREADY in the buffer. I would also bet that the Lora.write() function appends "\r\n", because every radio/modem I've used that supports the AT command set requires the "\r\n" to terminate the command line (as @TDK​ suggested).

In your original STM32 code you are actually sending 3 bytes: 'A', 'T' and NULL, because you are using sizeof(). "C" appends a trailing NULL to all string literals. Maybe that is confusing the radio?????? Use strlen() instead of sizeof(), and add the trailing "\r\n" to the AT command. And remove the delay between Tx and Rx as mentioned above.

even though I use simple uart POLL method still I have to enable this?

with debugger I can see what is inside rx_data and tx_data , I tried both method with/without "\r\n". same , screenshot below0693W00000Hpgf1QAB.png0693W00000HpgfQQAR.png