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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 4: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);
}
- Labels:
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 5: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.​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 5: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,
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 6: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 7:18 AM
I removed that delay line , still same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 7:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 8: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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 9: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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 9: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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-23 10:00 AM
Test post: "\r\n"
