The serial interface, abbreviated as serial port, is also known as the serial communication interface (usually referring to the COM interface). It is an expanded interface that uses serial communication. If classified by interface, there are several types including RS-232, RS-422, and RS-485, among which the RS-232 serial port is the most commonly used serial communication interface, also known as the standard serial port. Its full name is the “Technical Standard for Serial Binary Data Exchange Interface between Data Terminal Equipment (DTE) and Data Communication Equipment (DCE).” The traditional RS-232-C interface standard has 22 wires and uses a standard 25-pin D-type connector (DB25), which was later simplified to a 9-pin D-type connector (DB9). Currently, the use of the 25-pin connector is rare.
Well, that’s the introduction to the serial port. Here, I focus on the practical applications of the serial port in the software development process.
1. RS-232-C DB9 Pin Definitions
Pin Abbreviation DTE [Male] Pin DCE [Female] Pin Function Description (English) Function Description (Chinese) Signal Direction DCD 1 1 Data Carrier Detect 载波检测 In RXD 2 3 Received Data 接收数据 DTE DCE DTR 4 4 Data Terminal Ready 数据终端准备好 DTE -> DCE GND 5 5 Signal Ground 信号地 GND DSR 6 6 Data Set Ready 数据准备好 DTE DCE CTS 8 8 Clear to Send 清除发送请求 DTE DCE ■ DTE: Data Terminal Equipment (数据终端设备), device/male, with pin.
■ DCE: Data Communications Equipment (数据通信设备), device/female, with socket.
2. Male and Female Serial Cables
RS232 DB-9 Male-Female Extension Cable (Left Female Right Male)
RS232 DB-9 Female-Female Extension Cable
3. Distinction Between Direct and Cross Serial Cables
1. Multimeter Testing Method
◆ If pins 2 and 2, 3 and 3 are connected at both ends, it is a direct serial cable.
◆ If pin 2 is connected to pin 3 at the other end, and pin 3 is connected to pin 2 at the other end, it is a cross serial cable.
2. Visual Inspection Method
Both ends with female connectors are cross, one male and one female is direct.
4. When to Use Direct Serial Cable? When to Use Cross Serial Cable?
The standard serial port’s pin 2 connects to the RXD pin of the main control chip, and pin 3 connects to the TXD pin of the main control chip. If both the DTE device (such as a microcontroller, tester, etc.) development board’s serial port and the computer’s (DCE) motherboard’s serial port are standard serial ports, then a cross serial cable should be used for the connection between the two devices.
So it can be summarized as:
◆ DCE [Male] ↔ DTE [Male]: Use cross serial cable
◆ DCE [Male] ↔ DTE [Female]: Use direct serial cable
Therefore, in the actual board-making process, attention should be paid to the choice of the serial port head, and the following rules should be followed:
RS232 DB9 (Male): 2 Receive 3 Transmit
RS232 DB9 (Female): 2 Transmit 3 Receive
5. Points to Note During Serial Port Debugging
1. Different encoding mechanisms cannot be mixed, such as RS-232-C cannot be directly connected to RS-422 or RS-485 interfaces. There are dedicated protocol converters available on the market; connections must be made through converters.
2. Check whether the soldering of the serial port lines is secure; otherwise, the program may be fine, but connection issues can cause problems.
3. Check the male and female heads of the serial port, then select the correct serial data cable.
4. If all the above checks are fine but debugging still has issues, check whether the wiring of the DTE (Data Terminal Equipment) follows the standard serial wiring method. I encountered a situation where the DTE was clearly a male port, but the wiring was done as if it were a female port, wasting several days of time.
5. During serial port debugging, prepare a good debugging tool, such as Serial Port Utility (友善串口调试助手), Serial Port Wizard, etc., which can be very effective.