This experiment uses the serial port UART0 inside CH549 and uses timer T2 to generate the baud rate. The data is sent to the PC through the Qinheng USB to serial port module and displayed using the serial port debugging assistant.
1. Experimental resources
1. CH549EVT learning development board;
2. Keil v5.28.0.0;
3. CH549 development data summary.rar;
4. WCHISPTool v2.70;
5. Other relevant documents of CH549EVT;
6. Qinheng USB to serial port module;
7. Serial port debugging assistant SSCOM51 v5.13.1;
2. Experimental Preparation
1. CH549 serial port resources. CH549 has 4 full-duplex asynchronous serial ports UART0~UART3, among which UART0 is the standard MCS51 serial port; UART1 is the simplified MCS51 serial port; UART2 is based on UART1, with an interrupt enable bit added to replace the ADC interrupt; UART3 is the same as UART2, and is also based on UART1, with an interrupt enable bit added to replace the PWMX interrupt.
2. Registers related to the serial port. It can be seen that there are many serial ports and many related registers. This experiment only uses UART0.
The following is an introduction to the relevant registers of UART0:
UART0 Application:
The manual provides a detailed description of the use of UART0. You can complete the corresponding configuration of UART0 by referring to the manual.
3. T2 baud rate generator. When T2 is used as a baud rate generator, the "RCLK" and "TCLK" bits of the T2 control register "T2CON" must be set high to determine that UART0 selects the timer T2 overflow pulse to generate the baud rate. Here, the clock frequency of timer T2 as a baud rate generator must be considered, and different baud rate calculation formulas must be used according to the different configurations of the T2 mode register "T2MOD", mainly the "bTMR_CLK" and "bT2_CLK" bits.
3. This experiment
According to the previous introduction, UART0 was configured. The default 12MHz clock Fsys was selected. The baud rate was calculated using "RCAP2 = 65536 - Fsys / 16 / baud rate". The deviation was found to be too large during the test, so Fsys was increased to 48MHz in the subsequent test. The actual baud rate was calculated to be 48000000/16/26=115384, with an error of 0.16%. In fact, when Fsys = 24MHz, the error is also only 0.16%.
In addition, to configure "CLOCK_CFG", you must first enter safe mode:
The chip ID code was also read during the experiment.
The test code refers to the official DEMO program. The test code is as follows:
#define Fsys 48000000
#define UART0_BAUD 115200
void UART0_Config(void)
{
SAFE_MOD = 0x55;
SAFE_MOD = 0xAA; //进入安全模式
CLOCK_CFG = 0X87; //使能内部晶振,Fsys=48MHz
SM0 = 0;
SM1 = 1; //UART0使用模式1
SM2 = 0;
RCLK = 1; //UART0接收时钟选择T2溢出脉冲产生波特率
TCLK = 1; //UART0发送时钟选择T2溢出脉冲产生波特率
//T2CON = 0X34;
PCON |= 0X80; //SMOD=1
T2MOD = 0XC0; //bTMR_CLK=1、bT2_CLK=1
RCAP2 = 65536 - (Fsys / 16 / UART0_BAUD); //
TR2 = 1; //启动T2定时器
TI = 1;
REN = 1; //UART0接收使能
}
void main()
{
UINT16 ID;
UART0_Config();
ID = CHIP_ID; //读芯片ID识别码,CH549为0X49
printf("\nWCH CH549EVT UART0 TEST\n");
printf("CHIP_ID = %#2X\n",ID);
while(1)
{
}
}
IV. Experimental Results
5. Experimental Summary
Through this experiment, we have a better understanding of the CH549 serial port module UART0. The debugging of the serial port program will bring a lot of convenience to the subsequent experimental tests.
This content is originally created by lising , a user on the EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source