Use virtual serial port in the Keil MDK to debug the serial port

Source: Internet
Author: User

I read a lotArticleAnd writes are very simple (actually very simple :)). A detailed tutorial is provided.

 

1. Use vspd to connect two virtual serial ports on the PC. I connect com2 and com3. Click ADDR pair.

 

2. We can see that two virtual serial ports are connected together on virtual ports.

 

3. The virtual serial port is ready. First, you can directly enter the command for debugging. We open the Keil MDK and set it to the simulation mode. Click Debug. Enter mode com2 38400, 0, 8, 1 in the Command serial port.

 

 

 

Note:

The mode command is used to set parameters for the serial port of the bound computer. Basic usage:

Mode comx baudrate, parity, databits, stopbits

Where:

Comx (x = 1, 2 ,...) Indicates the serial port number of the computer;

Baudrate indicates the baud rate of the serial port; Parity indicates the verification method;

Databits indicates the data bit length;

Stopbits indicates the length of the stop bit.

Example: Mode COM1 9600, N, 8, 1

Set Serial Port 1. The baud rate is 9 600, with no check bit. The data is 8 bits and the stop bit is 1 bits.

Mode com219200, 1, 8, 1

Set Serial Port 2. The baud rate is 19 200. It is used for odd verification, 8-bit data, and 1-bit stop bit.

4. Press enter and enter assign com2 <s1in> s1out.

 

 

 

Note:

Comx indicates the serial port of the computer, which can be COM1, com2, com3 or other;

Inreg and outreg represent the serial port of the microcontroller. Common single-chip microcomputer with only one serial port, I .e. sin and sout; single-chip microcomputer with two or more serial ports, namely snin and snout (n = ,... That is, the serial port number of the single chip microcomputer ).

Example: Assign COM1 <sin> sout

Bind Serial Port 1 of the computer to the serial port of the single-chip microcomputer (for single-chip microcomputer with only one serial port ).

Assign com2 <sin> sout

Bind Serial Port 2 of the computer to serial port 0 of the single chip microcomputer (for single chip microcomputer with multiple serial ports, pay attention to the serial port number position ).

Note that the parameter brackets cannot be omitted, while outreg does not.

5. then DEBUGProgram. We can see that the serial port com3 prints the data of Serial Port 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.