Introduction to serial and serial communication

Source: Internet
Author: User

Currently, the commonly used serial ports include 9-pin serial ports (DB9) and 25-pin serial ports (DB25). When the communication distance is close (<12 m ), you can use a cable to directly connect to the standard RS232 port (RS422, RS485 far). If the distance is far, a MODEM must be attached ). The simplest and most common method is the three-line method, that is, connecting the ground, receiving data and sending data. This article only involves the most basic method and is directly connected with RS232.
1. Description of common signal ports of DB9 and DB25
9-pin serial port (DB9) 25-pin serial port (DB25)
PIN number Function Description
1. Data Carrier Detection DCD 8. Data Carrier Detection DCD
2 receive data RXD 3 receive data RXD
3 send data TXD 2 send data TXD
4. Prepare the DTR 20 data terminal for the DTR
5 signal ground GND 7 signal ground GND
6 data equipment ready DSR 6 Data ready DSR
7. Send the RTS 4 request to send the RTS
8. Clear sending CTS 5. Clear sending CTS
9. The ringing command is DELL 22. The ringing command is DELL.
2. RS232C Serial Communication Connection method (three-line)
First, as long as there are receive data pins and send pins for data transmission through the serial port, the receiving pin and sending pin of the same serial port can be directly connected by a line, connect two or more serial ports
· The receiving pin and sending pin of the same serial port are directly connected to the 9-pin serial port and the 25-pin serial port, both of which are 2 and 3;
· Two different serial ports (whether the two serial ports of the same computer or the serial ports of different computers)
The above table is for the standard serial port of the microcomputer, and there are many non-standard devices, such as receiving GPS data or electronic compass data, as long as you remember one principle: receiving data pins (or wires) it is connected to the data transmission pins (or wires), crossover, and signal-to-signal connection.

3. Notes for serial port debugging:
When debugging the serial port, prepare a handy debugging tool, such as the serial port debugging assistant and serial port genie, to get twice the result with half the effort. It is strongly recommended that you do not use the serial port with live connections, and that at least one end is powered off, otherwise, the serial port may be damaged.
Definition of Single-work, half-duplex, and full-duplex
If, at any time in the communication process, information can only be transmitted from one Party A to another, it is called A ticket.
If at any time, the information can be transmitted from A to B and from B to A, but it can only be transmitted in one direction, which is called half-duplex transmission.
If there is A bidirectional signal transmission from A to B and from B to A at any time, it is called full duplex.
The telephone line is the second-line full-duplex channel. Because the echo offset technology is used, two-way transmission signals are not ambiguous. Duplex channels sometimes separate the receiving and sending channels, and transmit signals in the opposite direction using a separate line or band, such as a return line.
Parity
During the transmission of serial data, information error may occur due to interference. For example, the transmission character 'E' is as follows:
0100,0101 = 45 H
D7 D0
Due to interference, the bit may change to 1. In this case, we call it an error code ". We call how to find an error during transmission as "check error ". After an error is found, how to eliminate it is called "error correction ".
The simplest error checking method is "parity", that is, one odd/even parity bit is transferred out of all characters. Odd or even verification can be used.
Odd check: the number of "1" in all transmitted digits (each digit containing characters and the check bit) is odd, for example:
1 0110,0101
0 0110,0001
Even verification: the number of "1" in all transmitted digits (each digit containing characters and the check bit) is an even number, for example:
1 0100,0101
0 0100,0001

The parity check can detect part of the error code in the information transmission process (one-bit error can be detected, and two or more digits cannot be detected). At the same time, it cannot correct the error. After an error is found, you must resend it. However, its implementation is simple and still widely used.
Some methods for checking errors are capable of automatic error correction. Such as cyclic Verification Code (CRC) check errors.
Serial Communication Flow Control
In serial communication processing, we often see two options, namely, RTS/CTS and XON/XOFF. These are two traffic control options. Currently, traffic control is mainly used in modem data communication, however, it is advantageous to know more about General RS232 programming. So what is the role of Stream Control in serial communication and how to apply it in the preparation of serial communication programs? Here we will talk about this issue.

 

1. Role of Stream Control in Serial Communication
The "stream" mentioned here, of course, refers to data streams. When data is transmitted between two serial ports, data loss often occurs, or the processing speed of the two computers is different, such as the communication between the desktop and the single chip microcomputer, the data buffer at the receiving end is full, in this case, the sent data will be lost. Now we can transmit data through MODEM on the network, which is particularly prominent. Stream Control can solve this problem. When the receiving end cannot process data, it sends a "no longer received" signal, and the sending end stops sending until it receives the "can continue sending" signal and then sends data. Therefore, flow control can control the data transmission process to prevent data loss. Two common traffic control methods in PC are hardware traffic control (including RTS/CTS, DTR/CTS, etc.) and software traffic control XON/XOFF (continue/Stop.

 

2. Hardware Traffic Control
Hardware traffic control is commonly used, including RTS/CTS traffic control and DTR/DSR (Data Terminal ready/data set ready) Traffic Control.
The hardware traffic control must be connected to the corresponding cable. When you use the RTS/CTS (request sending/clearing sending) traffic control, the RTS and CTS lines at both ends of the communication should be connected accordingly, data Terminal devices (such as computers) Use RTS to start data streams from a modem or other data communication devices, while data communication devices (such as a modem) use CTS to start and pause data streams from the computer. The hardware handshaking process is: we set a high flag (75% of the buffer size) and a low flag (25% of the buffer size) based on the buffer size at the receiver end during programming ), when the data volume in the buffer reaches a high level, we set the CTS line to a low level (send logic 0) at the receiving end. When the sending end detects that the CTS is low, it stops sending data, until the data volume in the acceptor buffer is lower than the low level, CTS is set to a high level. RTS indicates whether the receiving device is ready to receive data.
Common traffic control methods include DTR/DSR (Data Terminal ready/Data ready ). We will not detail it here. Due to the diversity of flow control, I personally think that when the software uses flow control, we should give a detailed description of how to connect and how to apply it.

 

3. Software Flow Control
Due to the limitations of cables, we generally use software flow control instead of hardware flow control in general control communication. Generally, XON/XOFF is used to implement software flow control. The common method is: when the data volume in the input buffer of the receiving end exceeds the set high, XOFF (19 in decimal or Control-S in decimal format) is sent to the data sending end, the device programming specification should be described in detail). After receiving the XOFF character, the sender immediately stops sending data. When the data volume in the input buffer of the receiver is less than the set low level, send the XON character (17 or Control-Q in decimal format) to the data sender. The sender starts sending the data immediately after receiving the XON character. Generally, you can find the characters sent from the source program of the device.
It should be noted that if binary data is transmitted, the flag characters may also occur in the data stream and cause misoperations. This is a defect in software flow control, and hardware flow control will not have this problem.

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.