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

What if device responds immediately?

Why wait 500ms?

Why try to get 20 characters into an array holding 10?

Does the AT command expect a CR/LF pair?​

Generally you want to allow for concurrent transmit and receive.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TPiri.1
Associate II

I texted with with on other MCU with MicroPython , needs small delay after sending "AT" command, I tried many options still the same result,

  • array [20]. it is mistake,
  • don't know about CR/LF pair

micro python code works fine, couldn't implement the same on sam HAL

TDK
Guru

> needs small delay after sending "AT" command

Why? Small delay for what reason?

As Tesla says, if the device responds within 500ms (which is likely), you are not listening during that period and miss the response.

If you feel a post has answered your question, please click "Accept as Solution".

I removed that delay line , still same

Okay, and did you look up if "\r\n" is required? Use a scope to see what happens on the lines. Look at the datasheet of "rf module" and understand how it works.
If you feel a post has answered your question, please click "Accept as Solution".

I did check, I used on other MCU with python code I am able to communicate , but when I moved to stm32 , I cannot get response from rf module. it doesn't require "\r\n" at the end of commands. when I connect rf module to Putty via FTDI , it works like fine like on screenshoot below . 0693W00000Hpfy2QAB.png

Dont seems be fine, input timeout say problem, but other.

Your putty dont have echo on then here isnt showed your send AT

with or without enter usw...

In normal stm use you need write background receiver IRQ callbacks

Your code dont need pause

HAL_UART_Transmit (&huart1, tx_data, sizeof(rx_data) , 250);
// HAL_Delay(500);
 HAL_UART_Receive(&huart1,rx_data, 20,1000+500);

this two commands say send tx_data but size from rx your code is more mistakes as ... 250 ms is wait time to send over peripheral , here if speed is slow can code fail

second receive next 1000ms data, if data isnt arived in time nothing is received

simply write

HAL_UART_Transmit (&huart1, "AT", 2 , 250);
HAL_UART_Receive(&huart1,rx_data, 20,1500);

I just tried your code, same result , cannot get receive nay data from UART,

same RF module works with this simple python code,

I am new to stm32 HAL programming, I am thinking maybe something wrong on rx-data declaration ?0693W00000HpgS7QAJ.png

Test post: "\r\n"

If you feel a post has answered your question, please click "Accept as Solution".