【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);
}
|