5464 views|4 replies

18

Posts

0

Resources
The OP
 

STM32 MCU realizes serial port 1 (115200) to receive/send data to serial port 2 (9600) at the same time [Copy link]

stm32g030 chip

Implement the function of sending data from serial port 1 to serial port 2 and receiving data from serial port 2 at the same time

Serial port 2 sends data to serial port 1 and receives data from serial port 1 at the same time

It is possible to send data from 9600 (serial port 2) to serial port 1 (115200), and serial port 1 can receive the data completely.

Serial port 1 (115200) sends data to serial port 2 (9600), but the data is not received correctly. Is there any incorrect configuration or

main.c

while (1)
{
/* USER CODE END WHILE */

if(HAL_UART_Receive_IT(&huart2,USART2_RX_BUF,1) == HAL_OK)
{

HAL_UART_Transmit(&huart1,USART2_RX_BUF,sizeof(USART2_RX_BUF),100);
}

if(HAL_UART_Receive_IT(&huart1,USART1_RX_BUF,1) == HAL_OK)
{

HAL_UART_Transmit (&huart2,USART1_RX_BUF ,sizeof(USART1_RX_BUF),100);
}

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

Callback Function

void HAL_UART_RXCpltCallback(UART_HandleTypeDef *huart)
{
if(huart ->Instance == USART2)
{
HAL_UART_Transmit(&huart1,USART2_RX_BUF,1,100);
HAL_UART_Receive_IT(&huart2,USART2_RX_BUF,1);

}

if(huart ->Instance == USART1)
{
HAL_UART_ Transmit (&huart2,USART1_RX_BUF,1,100);
HAL_UART_Receive_IT(&huart1,USART1_RX_BUF,1);
}
}

usart.c

Add enable in usart initialization

/*Enable the uart data register not empty interrupt*/
__HAL_UART_ENABLE_IT(&huart2,UART_IT_RXNE);
//__HAL_UART_ENABLE_IT(&huart2,UART_IT_TXE);
/*Enable the uart parity error interrupt*/
__HAL_UART_ENABLE_IT(&huart2,UART_IT_PE);
/*Enable the uart error interrtupt:(Frame error,noise error,overrun error)*/
__HAL_UART_ENABLE_IT(&huart2,UART_IT_ERR);

This post is from stm32/stm8

Latest reply

This is so strange! Why is the baud rate different?   Details Published on 2022-7-18 18:08
 

6788

Posts

2

Resources
2
 

In what scenario is this used? Is it transparent?

This post is from stm32/stm8

Comments

Yes  Details Published on 2022-7-2 09:23
 
 

18

Posts

0

Resources
3
 
wangerxian posted on 2022-7-1 16:53 In what scenario is this applied? Is it transparent?

Yes

This post is from stm32/stm8
 
 

9720

Posts

24

Resources
4
 

I don't understand your question. Do you want to realize that two serial ports of a microcontroller can send and receive messages to each other? And the communication is between different resolutions?

This post is from stm32/stm8
 
 
 

104

Posts

0

Resources
5
 

This is so strange! Why is the baud rate different?

This post is from stm32/stm8
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
The Surrender of Bandits at Birdcage Mountain

Hu Ge's new work http://www.6rooms.com/nlsdwatch.php?v=2755 is really funny. Hu Ge almost went bankrupt to make this fil ...

Homemade STEVAL-IPM05F 3Sh board: FOC motor control 400V/8A non-sensing/sensing Hall/sensing encoder and other reference programs...

This post was last edited by music_586 on 2019-4-4 19:06 This content was originally created by EEWORLD forum user musi ...

Wuhan plague, the possibility of third, fourth, fifth and sixth generation infection cases

I heard that it has already appeared in the third and fourth generations. Does this mean that it has been transmitted se ...

CAN IAP Example

This content is originally created by EEWORLD forum user Xueshan Feihu11 . If you want to reprint or use it for comm ...

GPIO pin multiplexing in C6455

In addition, when using GPIO, you also need to consider the pin reuse of the corresponding chip. Taking 6455 as an examp ...

31 "Millions of Miles" Raspberry Pi Car——Ubuntu MATE System Installation

Next, I was going to start learning ROS, but it was particularly difficult to install it on the Raspberry Pi operating ...

[Sipeed LicheeRV 86 Panel Review] Developing RISCV Bare Metal Programming Using the Emerging Programming Language Rust

This post was last edited by mars4zhu on 2022-4-20 16:29 Developing RISCV bare metal programming using the emerging pro ...

【Tuya BK7231N】Unboxing Experience

Tuya IoT provides a series of simple and fast development platforms, providing a simple and easy development method for ...

CUK circuit combined with SEPIC circuit

Dear seniors: It feels like domestic power supply manufacturers are springing up like mushrooms after rain, but most of ...

There are really more and more digital people, and it is hard to tell the real from the fake

Some of Meituan’s live broadcasts now are all digital people, and they will also answer your questions. If you don’t l ...

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list