STM32F103 UART2 not Receiving data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-14 1:59 AM
Hi all,
I am facing one issue with STM32F103 UART2 receiving side, it is transmitting data but not receiving. i just configured MCU with CUBEMX and changed only main.c file.
Configuration and main.c are attached here.
I just made a very simple program "UART2 have to send MSGY if it receives 'a' or send MSGN if receives anything else.
but when i send 'a' from connected terminal it sends MSGN instead of MSGY i.e. every time it sends MSGN.
the same thing when i am trying exact same thing with UART1 it is not having any problem, it works fine.
@TDK​ @Community member​ @Community member​
- Labels:
-
STM32F1 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-14 5:26 AM
Then send back what you receive, or check in some other way (observe in debugger) what you receive.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-01-14 5:29 AM
There is a lot of initialization code missing (from other files), but I suspect there is other stuff going on.
I'd use something more like this in the loop
while (1)
{
if (HAL_UART_Receive(&huart2, &receivedData, sizeof(receivedData), 2000) == HAL_OK)
{
if (receivedData == 'a')
{
HAL_UART_Transmit(&huart2, (uint8_t*)MSGY, sizeof(MSGY), 100);
}
else
{
HAL_UART_Transmit(&huart2, (uint8_t*)MSGN, sizeof(MSGN), 100);
}
}
}
Double check the peripherals, clocks and pins via the register views in the debugger.
Check you're using the right pins externally. Scope an output stream to check it outputs, at the right bit rate, and expected pin, etc.
Check the schematic for the board, and connectivity to other components.
Up vote any posts that you find helpful, it shows what's working..
