794 views|12 replies

155

Posts

3

Resources
The OP
 

【ACM32G103RCT6] + UART function evaluation [Copy link]

 
 

The ACM32G103RCT6 development board has three UARTs on board, namely UART1, UART2, UART3 and UART4. UART2 is used as debug mode and can use print to print logs.

The acm32g103_coreboard.h library file provides initialization for UART2, as shown in the figure below ( the brief of this comment is written incorrectly, it should be UART2 )

The correct UART is shown in the figure below (you can see it is UART2):

Just use the following code to initialize serial port 2 and print helloworld

int main(void)
{
    uint32_t count=0;
		//初始化HAL
    HAL_Init();
		//初始化系统时钟
    SystemClock_Config();	
		
		BSP_UART_Init();
	
		

    while(1)
    {
			printf("Hello world");
    };
}

I have taken out the serial port initialization code in the BSP (as shown in the figure below to initialize serial port 2)

int main(void)
{
		UART_HandleTypeDef BSP_UART_Handle;
		//初始化HAL
    HAL_Init();
		//初始化系统时钟
    SystemClock_Config();	
		
		BSP_UART_Handle.Instance        = UART2;
    BSP_UART_Handle.Init.BaudRate   = 115200;
    BSP_UART_Handle.Init.WordLength = UART_WORDLENGTH_8B;
    BSP_UART_Handle.Init.StopBits   = UART_STOPBITS_1;
    BSP_UART_Handle.Init.Parity     = UART_PARITY_NONE;
    BSP_UART_Handle.Init.Mode       = UART_MODE_TX_RX;
    BSP_UART_Handle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
	
		HAL_UART_Init(&BSP_UART_Handle);
		HAL_UART_SetDebugUart(BSP_UART_Handle.Instance);
			
    while(1)
    {
			printf("Hello world");
    };
}

The printed information is as follows (normal and correct):

The above is the output of UART 2, which is normal. However, I switched UART 2 to UART 3 or UART 1 and connected ch340 to the host computer. The data cannot be received. I don't know why ( UART3 TXD: PB10, RXD: PB11 ). The code is shown in the figure below.

int main(void)
{
		UART_HandleTypeDef BSP_UART_Handle;
		//初始化HAL
    HAL_Init();
		//初始化系统时钟
    SystemClock_Config();	
		
		BSP_UART_Handle.Instance        = UART3;
    BSP_UART_Handle.Init.BaudRate   = 115200;
    BSP_UART_Handle.Init.WordLength = UART_WORDLENGTH_8B;
    BSP_UART_Handle.Init.StopBits   = UART_STOPBITS_1;
    BSP_UART_Handle.Init.Parity     = UART_PARITY_NONE;
    BSP_UART_Handle.Init.Mode       = UART_MODE_TX_RX;
    BSP_UART_Handle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
	
		HAL_UART_Init(&BSP_UART_Handle);
		HAL_UART_SetDebugUart(BSP_UART_Handle.Instance);
			
    while(1)
    {
			printf("Hello world");
    };
}

This post is from Domestic Chip Exchange

Latest reply

Agree with this point of view!!!   Details Published on 2024-1-19 21:44
 
 

5213

Posts

239

Resources
2
 

Let me call other review partners to check:

@qiao---

@TL-LED

@qzc0927

@lugl4313820

@みずじ

@jinglixixi

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

410

Posts

3

Resources
3
 

Did you change UART2 to UART3 directly?

This post is from Domestic Chip Exchange

Comments

The code is fine, that is a macro definition, the code for initializing uart3 in the official demo is written like this. I now suspect that there may be something wrong with my usbttl tool. I will try again. The official demo does not output anything for me, only urat2 does.  Details Published on 2024-1-19 22:40
 
 
 

224

Posts

0

Resources
4
 
This post was last edited by qiao--- on 2024-1-19 16:32

There are three issues you need to pay attention to here.

For the first question, I don’t know whether you have used a USB to TTL module to connect to the corresponding pins. If not, you must use a serial port to serial port module to connect to the corresponding pins.

The second question is that you must know how printf implements sending data through the serial port. It actually redirects the underlying fputc function of printf. Here, printf is redirected to serial port 2, so no data will be displayed when you initialize serial port 3 and serial port 1 using printf. If you want to redirect to other serial ports, you must implement the redirection of other serial ports, that is, implement the fputc method.

If the first two are all right, then the third one must be wrong. You need to initialize the pins of uart1 or uart3. This pin initialization is usually in the msp.c file. I hope my answer can solve your problem.

This post is from Domestic Chip Exchange

Comments

Agree with this point of view!!!  Details Published on 2024-1-19 22:37
Agree with this point of view!!!  Details Published on 2024-1-19 21:44
 
 
 

410

Posts

3

Resources
5
 

It seems that there is no problem in writing the code like this. You can look at the hardware connection, the connection between UART3 pins PB10 and PB11 and CH340.

This post is from Domestic Chip Exchange

Comments

Yes, there is nothing wrong with the code, the official code is also written like this, I will try another USB-ttl tool later  Details Published on 2024-1-19 22:39
 
 
 

224

Posts

0

Resources
6
 

I tried it and it was able to receive data normally when I changed to serial port 1.

The following wiring is required:

This post is from Domestic Chip Exchange

Comments

Thank you, I'll try again  Details Published on 2024-1-19 22:38
 
 
 

6820

Posts

11

Resources
7
 

In addition to initializing the serial port, you also need to modify the corresponding serial port for redirection.

It is recommended that you test it by directly inputting into the serial port first. If successful, the printf value has not been modified.

This post is from Domestic Chip Exchange

Comments

Yes, it is the serial port output directly. I see that the initialization of the serial port in the bsp code only modifies UART1 or UART2 or three, and the others are not changed. I will check again. Thank you  Details Published on 2024-1-19 22:38
 
 
 

1452

Posts

1

Resources
8
 
qiao--- posted on 2024-1-19 16:11 You have three issues to pay attention to. The first issue is that I don't know if you have connected the USB to TTL module to the corresponding pin. If not, you must...

Agree with this point of view!!!

This post is from Domestic Chip Exchange
 
 
 

155

Posts

3

Resources
9
 
qiao--- posted on 2024-1-19 16:11 You have three issues to pay attention to. The first issue is that I don't know if you have connected the USB to TTL module to the corresponding pin. If not, you must...

Thank you, I'll watch it tonight.

This post is from Domestic Chip Exchange
 
 
 

155

Posts

3

Resources
10
 
lugl4313820 posted on 2024-1-19 18:03 In addition to initializing the serial port, you also need to modify the corresponding serial port for redirection. It is recommended that you first test it by directly inputting the serial port. If the result is ...

Yes, it is the serial port output directly. I see that the initialization of the serial port in the bsp code only modifies UART1 or UART2 or three, and the others are not changed. I will check again. Thank you

This post is from Domestic Chip Exchange
 
 
 

155

Posts

3

Resources
11
 
qiao--- posted on 2024-1-19 17:11 I tried it and changed it to serial port 1 to receive data normally. The following wiring is required:

Thank you, I'll try again

This post is from Domestic Chip Exchange
 
 
 

155

Posts

3

Resources
12
 
TL-LED posted on 2024-1-19 16:41 It should be no problem to write the code like this. You can look at the hardware connection, the connection between UART3 pins PB10 and PB11 and CH340.

Yes, there is nothing wrong with the code, the official code is also written like this, I will try another USB-ttl tool later

This post is from Domestic Chip Exchange
 
 
 

155

Posts

3

Resources
13
 
TL-LED posted on 2024-1-19 16:08 Did you directly change UART2 to UART3?

The code is fine, that is a macro definition, the code for initializing uart3 in the official demo is written like this. I now suspect that there may be something wrong with my usbttl tool. I will try again. The official demo does not output anything for me, only urat2 does.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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