2771 views|4 replies

1452

Posts

1

Resources
The OP
 

【AT32F421 Review】+Serial Communication Test [Copy link]

 This post was last edited by jinglixixi on 2021-5-3 17:00

In the routine program of AT32F421, a variety of serial communication examples are provided, which brings great convenience to the various needs of users.

Here are just two examples for testing, one is to carry out data communication between the two serial ports in the chip, and the other is to send information outward and receive and display it by the computer.

1. On-chip serial communication

The pins used by the serial port 1 of the development board are:

Tx--- PA.9

Rx---PA.10

The pins used by serial port 2 are:

Tx--- PA. 2

Rx---PA. 3

Since the serial communication is carried out within the chip, the connection between the two serial ports should be cross-connected. After the program is downloaded, its running effect is shown in Figure 1 (3 LED lights are lit). If the test connection is disconnected, it will be shown in Figure 2 (3 LEDs are off).

Figure 1 Normal effect

Figure 2 Abnormal effect

The main program to implement this function is:

while(TxCounter < TxBufferSize)

{

USART_SendData(USART1, TxBuffer[TxCounter++]);

while(USART_GetFlagStatus(USART1, USART_FLAG_TDE) == RESET);

while(USART_GetFlagStatus(USART2, USART_FLAG_RDNE) == RESET);

RxBuffer[RxCounter++] = (USART_ReceiveData(USART2) & 0x7F);

}

TransferStatus = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);

if(TransferStatus == PASSED)

{

AT32_LEDn_ON(LED2);

AT32_LEDn_ON(LED3);

AT32_LEDn_ON(LED4);

}

That is, the content stored in the array TxBuffer is sent from serial port 1 to serial port 2. If the sending and receiving are consistent, the three LED lights will be lit.

uint8_t TxBuffer[] = "Buffer Send from USART1 to USART2 using Flags";

It is worth mentioning that the baud rate of communication is as high as 230400bps. If you use a general serial port assistant, you may not be able to find this value.

USART_InitStructure.USART_BaudRate = 230400;

2. Send data outward

When performing this test, you need to use a USB-to-serial port module and cross-connect it with the pins of serial port 1, as shown in Figure 3.

Figure 3 Test connection

The communication baud rate this time is different from the on-chip communication, but it is not low either, which is 115200bps. The execution effect is shown in Figure 4.

Figure 4 Test results

The main program is extremely simple, with only a few lines of statements.

int main(void)

{

UART_Print_Init(115200);

printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");

while (1);

}

This post is from Domestic Chip Exchange

Latest reply

Thanks for sharing, looking forward to the follow-up!   Details Published on 2021-5-7 10:26

赞赏

1

查看全部赞赏

 
 

6555

Posts

0

Resources
2
 

There are not many main programs for serial port testing.

The serial port test was successfully completed.

This post is from Domestic Chip Exchange
 
 
 

7422

Posts

2

Resources
3
 

Thanks for sharing, looking forward to the follow-up!

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

71

Posts

2

Resources
4
 

Thank you for sharing, looking forward to the subsequent updates,,,,,,,

This post is from Domestic Chip Exchange
 
 
 

1942

Posts

2

Resources
5
 

Thanks for sharing, looking forward to the follow-up!

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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