Basic theory of computer serial port
1. What is a serial port?
2. What is RS-232?
3. What is RS-422?
4. What is RS-485?
5. What is a handshake?
1. What is a serial port?
Serial ports are a very common protocol for device communication on computers (not to be confused with Universal Serial Bus or USB). Most computers contain two serial ports based on RS232. Serial ports are also a common communication protocol for instrumentation devices; many GPIB-compatible devices also have RS-232 ports. Serial port communication protocols can also be used to obtain data from remote acquisition devices.
The concept of serial communication is very simple. Serial ports send and receive bytes by bit. Although slower than parallel communication by byte, serial ports can send data on one line while receiving data on another line. It is simple and can achieve long-distance communication. For example, when IEEE488 defined the parallel communication state, it stipulated that the total length of the device line should not exceed 20 meters, and the length between any two devices should not exceed 2 meters; for serial ports, the length can reach 1200 meters.
Typically, serial ports are used to transmit ASCII characters. Communication is accomplished using three wires: (1) ground, (2) transmit, and (3) receive. Since serial communication is asynchronous, the port can send data on one wire while receiving data on another. The other wires are used for handshaking, but are not required. The most important parameters for serial communication are the baud rate, data bits, stop bits, and parity. For two ports to communicate, these parameters must match:
a. Baud rate: This is a parameter that measures the speed of communication. It indicates the number of bits transmitted per second. For example, 300 baud means 300 bits are sent per second. When we mention the clock cycle, we are referring to the baud rate. For example, if the protocol requires a 4800 baud rate, then the clock is 4800Hz. This means that the sampling rate of the serial communication on the data line is 4800Hz. Common baud rates for telephone lines are 14400, 28800 and 36600. The baud rate can be much larger than these values, but the baud rate is inversely proportional to the distance. High baud rates are often used for communication between instruments that are placed very close to each other. A typical example is the communication between GPIB devices.
b. Data bits: This is a parameter that measures the actual data bits in communication. When a computer sends a packet of information, the actual data will not be 8 bits. The standard values are 5, 7, and 8 bits. How to set it depends on the information you want to transmit. For example, the standard ASCII code is 0 to 127 (7 bits). The extended ASCII code is 0 to 255 (8 bits). If the data uses simple text (standard ASCII code), then each data packet uses 7 bits of data. Each packet refers to a byte, including start/stop bits, data bits, and parity bits. Since the actual data bits depend on the choice of communication protocol, the term "packet" refers to any communication situation.
c. Stop bit: used to indicate the last bit of a single packet. Typical values are 1, 1.5 and 2 bits. Since data is timed on the transmission line and each device has its own clock, it is likely that there will be a small desynchronization between the two devices during communication. Therefore, the stop bit not only indicates the end of the transmission, but also provides an opportunity for the computer to correct the clock synchronization. The more bits are applied to the stop bit, the greater the tolerance for different clock synchronization, but the data transmission rate is also slower.
d. Parity bit: A simple error detection method in serial communication. There are four error detection methods: even, odd, high and low. Of course, no parity bit is also possible. For even and odd parity, the serial port will set the parity bit (the bit after the data bit) with a value to ensure that the transmitted data has an even or odd number of logical high bits. For example, if the data is 011, then for even parity, the parity bit is 0, ensuring that the number of logical high bits is an even number. If it is odd parity, the parity bit is 1, so there are 3 logical high bits. The high and low bits do not actually check the data, and simply set the logic high or logic low check. This allows the receiving device to know the state of a bit and have the opportunity to determine whether noise interferes with communication or whether the transmission and reception of data are not synchronized.
2. What is RS-232?
RS-232 (ANSI/EIA-232 standard) is the serial connection standard for IBM-PC and its compatible machines. It can be used for many purposes, such as connecting a mouse, printer or modem, and can also connect industrial instruments. It is used for driver and wiring improvements. In actual applications, the transmission length or speed of RS-232 often exceeds the standard value. RS-232 is limited to point-to-point communication between PC serial ports and devices. The maximum distance of RS-232 serial communication is 50 feet.
DB-9 pin connector
-------------
/ 1 2 3 4 5 /
/ 6 7 8 9 /
-------
The cross section of the line connected from the computer.
Functions of RS-232 pins:
data:
TXD (pin 3): serial port data output
RXD (pin 2): serial port data input
shake hands:
RTS (pin 7): Send data request
CTS (pin 8): Clear to Send
DSR (pin 6): Data send ready
DCD (pin 1): Data Carrier Detect
DTR (pin 4): Data Terminal Ready
Ground Wire:
GND (pin 5): ground wire
other
RI (pin 9): Ring Indicator
3. What is RS-422?
RS-422 (EIA RS-422-A Standard) is the serial port connection standard for Apple's Macintosh computers. RS-422 uses differential signals, while RS-232 uses unbalanced ground reference signals. Differential transmission uses two wires to send and receive signals. Compared with RS-232, it has better noise immunity and longer transmission distance. Better noise immunity and longer transmission distance are a great advantage in industrial environments.
4. What is RS-485?
RS-485 (EIA-485 standard) is an improvement over RS-422 because it increases the number of devices from 10 to 32 while defining electrical characteristics at the maximum number of devices to ensure adequate signal voltage. With multiple device capabilities, you can build a network of devices using a single RS-422 port. With excellent noise immunity and multi-device capabilities, RS-485 is the serial connection of choice when building a distributed device network connected to a PC, other data collection controller, HMI or other operation in industrial applications. RS-485 is a superset of RS-422, so all RS-422 devices can be controlled by RS-485. RS-485 can use more than 4000 feet of wire for serial communication.
DB-9 Pin Connection
-------------
/ 1 2 3 4 5 /
/ 6 7 8 9 /
-------
The cross section of the line connected from the computer.
Functions of RS-485 and RS-422 pins
Data: TXD+ (pin 8), TXD- (pin 9), RXD+ (pin 4), RXD- (pin 5)
Handshake: RTS+ (pin 3), RTS- (pin 7), CTS+ (pin 2), CTS- (pin 6)
Ground: GND (pin 1)
5. What is a handshake?
The RS-232 communication method allows for a simple connection of three wires: Tx, Rx, and ground. However, for data transmission, both parties must use the same baud rate for data timing. Although this method is sufficient for most applications, its use is limited in cases where the receiver is overloaded. This is when the serial port's handshake function is needed. In this section, we discuss the three most commonly used RS-232 handshake forms: software handshake, hardware handshake, and Xmodem.
a. Software handshake: The first type of handshake we discuss is software handshake. It is usually used when the actual data is control characters, similar to the way GPIB uses command strings. The required wires are still three: Tx, Rx and ground. Because control characters are no different from ordinary characters on the transmission line, the function SetXModem allows the user to enable or disable the use of two control characters XON and XOFF. These characters are sent by the receiver in the communication to make the sender pause.
For example: suppose the sender is sending data at a high baud rate. During the transmission, the receiver discovers that the input buffer is full because the CPU is busy with other work. To temporarily stop the transmission, the receiver sends XOFF, a typical value of decimal 19, or hexadecimal 13, until the input buffer is empty. Once the receiver is ready to receive, it sends XON, a typical value of decimal 17, or hexadecimal 11, to continue communication. When the input buffer is half full, LabWindows sends XOFF. In addition, if the XOFF transmission is interrupted, LabWindows sends XOFF at 75% and 90% of the buffer. Obviously, the sender must follow this rule to ensure that the transmission continues.
b. Hardware handshake: The second is to use hardware line handshake. Like Tx and Rx lines, RTS/CTS and DTR/DSR work together, one as output and the other as input. The first set of lines is RTS (Request to Send) and CTS (Clear to Send). When the receiver is ready to receive data, it sets the RTS line high to indicate that it is ready. If the sender is also ready, it sets CTS high to indicate that it is about to send data. The other set of lines is DTR (Data Terminal Ready) and DSR (Data Set Ready). These lines are mainly used for Modem communication. It allows the serial port and Modem to communicate their status. For example: When the Modem is ready to receive data from the PC, it sets the DTR line high to indicate that the connection with the telephone line has been established. Reading the DSR line high, the PC starts to send data. A simple rule is that DTR/DSR is used to indicate that the system is ready for communication, while RTS/CTS is used for the transmission of a single data packet.
In LabWindows, the function SetCTSMode enables or disables the use of hardware handshaking. If CTS mode is enabled, LabWindows uses the following rules:
Previous article:ARM CPU big and small endian
Next article:ARM study notes 14 - C language and assembly are applied to each other
Recommended ReadingLatest update time:2024-11-16 10:37
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- What GaN innovations will emerge in the next few years?
- 【McQueen Trial】The third post is delayed——Simple wireless control car
- Will mobile phones last four days on a single charge in the future? Are you looking forward to the world's first 2nm chip?
- A brief introduction to UWB
- [Anxinke NB-IoT Development Board EC-01F-Kit] 2. Power-on test and RX0/TX0 compatibility issues
- The perfect Baidu Netdisk is about to dominate the Internet's download resources
- [Raspberry Pi Pico Review] Unboxing and Power-On Test
- TPS62903: What causes Vout to deviate from the expected value?
- 0-10V, PWM, potentiometer three-in-one dimming power supply interface GP9301 solution
- 3 ways to handle lithium-ion battery testing equipment. Do you know this solution?