Skip to main content
stm32lover
Associate
Feb 27, 2019 11:05 AM UTC
Solved

STM32F103C8 UART cannot receive correct data by another same MCU

Thank you in advance.

I am trying use two stm32f103c8t6 to do communication stuff. One is used to be transmitter and another is receiver. The code is simple but it doesn't work.

Source code as follows:

Transmitter:

while (1)

{

uint8_t tran[4] = {0x21, 0x48, 0x59, 0x00};

  HAL_UART_Transmit(&huart1, tran, 4, 10);

HAL_Delay(100);

}

Receiver:

while (1)

{

HAL_UART_Receive(&huart1, tran, 4, 10);

HAL_Delay(100);

 }

The baud rate is set to 115200 bits/s. I use usb-to-ttl to check the situation. The transmitter is working normally, but the receiver cannot receive the normal data as expected.

Please help!!!

This topic has been closed for replies.
mh_stm
mh_stmBest answer
Associate II
Feb 27, 2019 11:14 AM UTC

Hi,

please check if both MCUs have common ground.

Regards,

4 replies

After Forever
Senior III
Feb 27, 2019 11:14 AM UTC

The sending and receiving aren't synchronized. Transmitter sends the 4 bytes (it takes very little time) while most likely (~90%) the receiver is in HAL_Delay(100).

stm32lover
Associate
Feb 27, 2019 11:17 AM UTC

Thank you for replying. I just try this. Although I can receive some data, those data are some strange/ wrong data.

mh_stm
mh_stmBest answer
Associate II
Feb 27, 2019 11:14 AM UTC

Hi,

please check if both MCUs have common ground.

Regards,

stm32lover
Associate
Feb 27, 2019 11:53 AM UTC

Thank a lot. This helps me to finish my whole day work