2021-12-23 04:58 AM
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);
}
2021-12-23 05:04 AM
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.
2021-12-23 05:12 AM
I texted with with on other MCU with MicroPython , needs small delay after sending "AT" command, I tried many options still the same result,
micro python code works fine, couldn't implement the same on sam HAL
2021-12-23 06:55 AM
> 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.
2021-12-23 07:18 AM
I removed that delay line , still same
2021-12-23 07:36 AM
2021-12-23 08:28 AM
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 .
2021-12-23 09:45 AM
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);
2021-12-23 09:54 AM
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 ?
2021-12-23 10:00 AM
Test post: "\r\n"