Basic concepts of Serial Communication

Source: Internet
Author: User
Tags file transfer protocol

Basic concepts of Serial Communication

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?
The serial port is a protocol used to communicate with a very general device on a computer (do not confuse it with the Universal Serial Bus or USB ). Most computers contain two RS232-based serial ports. Serial Port is also a universal communication protocol for instrumentation equipment; many devices are also compatible with the RS-232 port. At the same time, the serial communication protocol can also be used to obtain data from remote collection devices.

The concept of serial communication is very simple. The serial port sends and receives bytes by bit. Although it is slower than byte parallel communication, the serial port can use one line to send data while the other line to receive data. It is simple and can implement remote communication. For example, when ieee488 defines the parallel traffic status, the total length of the device line must not exceed 20 meters, and the length of any two devices must not exceed 2 meters. For the serial port, the length can be up to 1200 meters.

Typically, the serial port is used for ASCII character transmission. Communication is completed using three wires: (1) Ground Wire, (2) Send, (3) receive. Because serial communication is asynchronous, the port can send data on one line and receive data on the other line at the same time. Other cables are used for handshaking, but not required. The most important parameters for serial communication are the baud rate, data bit, stop bit, and parity. For two ports that are in use, these parameters must match:
A. baud rate: This is a parameter used to measure the communication speed. It indicates the number of bits transmitted per second. For example, 300 port indicates that 300 bits are sent every second. When we mention the clock cycle, we mean the baud rate. For example, if the Protocol requires a 4800 baud rate, the clock is 4800Hz. This means that the sampling rate of serial communication on the data line is 4800Hz. Generally, the baud rates of telephone lines are 14400,28800 and 36600. The baud rate can be much greater than these values, but the baud rate is inversely proportional to the distance. The high baud rate is often used for communication between very close instruments. A typical example is the communication between devices on the GUI.
B. Data bit: This is a parameter used to measure the actual data bit in communication. When a computer sends an information package, the actual data is not 8 bits, and the standard values are 5, 7, and 8 bits. The setting depends on the information you want to transmit. For example, the standard ASCII code is 0 ~ 127 (7 digits ). The extended ASCII code is 0 ~ 255 (8 digits ). If the data uses simple text (Standard ASCII code), each packet uses 7-bit data. Each packet is a byte, including the start/stop bits, data bits, and parity bits. Because the actual data bit depends on the selection of the communication protocol, the term "package" refers to any communication situation.
C. Stop bit: used to indicate the last bit of a single package. The typical values are 1, 1.5, and 2. Because the data is scheduled on the transmission line, and each device has its own clock, it is very likely that there is a small non-synchronization between the two devices in the communication. Therefore, the stop bit is not only the end of the transmission, but also the opportunity for the computer to correct the clock synchronization. The more digits the stop bit, the higher the synchronization tolerance for different clocks, but the slower the data transmission rate.
D. parity bit: a simple error detection method in serial communication. There are four error checking methods: Even, Odd, tall, and low. Of course, it is acceptable that there is no checkpoint. In the case of parity and odd parity, the serial port sets the parity bit (one digit after the data bit), and uses a value to ensure that the transmitted data has even or Odd logic highs. For example, if the data is 011, the parity check bit is 0 to ensure that the number of digits with high logic is an even number. If it is an odd check, the check bit is 1, so there are three logic High. High-level and low-level check data, simple location logic high or low-level Logic validation. In this way, the receiving device can know the status of a single position, and has the opportunity to determine whether there is noise interfering with communication or whether the transmission and receiving data are not synchronized.

2, what is RS-232?
RS-232 (ANSI/EIA-232 standard) is a serial connection Standard for IBM-PC and its compatible devices. It can be used for many purposes, such as connecting the mouse, printer, or modem, as well as connecting industrial instruments. Used to improve the drive and connection, in actual application, the transmission length or speed of the RS-232 often exceeds the standard value. RS-232 is limited to point-to-point communication between PC serial port and device. RS-232 serial communication is 50 feet at the longest distance.

DB-9 pin connector
-------------
/1 2 3 4 5/
/6 7 8 9/
-------
The cross section of the line connected from the computer.
RS-232 pin functions:

Data:
Txd (Pin 3): Serial Data Output
Rxd (PIN 2): Serial Port Data Input

Handshake:
RTS (pin 7): send data requests
CTS (PIN 8): Clear sending
DSR (Pin 6): Data Transmission ready
DCD (Pin 1): Data Carrier Detection
DTR (PIN 4): Data Terminal ready

Ground:
Gnd (pin 5): Ground

Others
RI (PIN 9): ringtone indication

3, What Is RS-422?
RS-422 (EIA RS-422-A standard) is Apple's Macintosh computer serial port connection Standard. RS-422 uses differential signals and RS-232 uses non-balanced reference signals. Differential transmission uses two lines to send and receive signals, compared to the RS-232, it can better resist noise and have a longer transmission distance. In the industrial environment, better noise resistance and farther transmission distance are a great advantage.

4, What Is RS-485?
RS-485 (EIA-485 standard) is an improvement in RS-422 because it increases the number of devices, from 10 to 32, while defining electrical properties in the case of the maximum number of devices, to ensure sufficient signal voltage. With the capabilities of multiple devices, you can use a single RS-422 port to build a device network. Excellent noise resistance and multi-device capabilities, serial connection selects a RS-485 when establishing a distributed device network to a PC, other data collection controllers, HMI, or other operations in industrial applications. The RS-485 is the superset of the RS-422, so all RS-422 devices can be controlled by the RS-485. The RS-485 can be connected in serial mode with over 4000 feet lines.

DB-9 Pin Connection

-------------
/1 2 3 4 5/
/6 7 8 9/
-------

The cross section of the line connected from the computer.

Pin functionality for RS-485 and RS-422
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 mode allows simple connections to three lines: Tx, RX, and ground. However, for data transmission, both parties must use the same baud rate for data at regular intervals. Although this method is sufficient for most applications, the use of this method is limited when the receiver is overloaded. In this case, the serial handshake function is required. In this section we discuss three of the most common RS-232 handshakes: Software handshakes, hardware handshakes, and XMODEM.

A. Software handshake: The first handshake we discuss is software handshake. It is usually used when the actual data is a control character, similar to the use of command strings by using the export function. The required line is still three: Tx, RX, and ground line, because the control characters are no different from common characters in the transmission line, the setxmodem function allows or disables the use of two control characters, Xon and oxff. These characters are sent by the receiver during communication, causing the sender to pause.
For example, assume that the sender sends data at a high baud rate. During transmission, the receiver finds that the input buffer is full because the CPU is busy with other work. To temporarily stop transmission, the receiver sends xoff. The typical value is decimal 19, that is, hexadecimal 13, until the input buffer is empty. Once the receiver is ready to receive the message, it sends Xon, the typical value is decimal 17, that is, hexadecimal 11, continue communication. When the input buffer is half full, LabWindows sends xoff. In addition, if the xoff transmission is interrupted, LabWindows will send xoff when the buffer reaches 75% and 90%. Obviously, the sender must follow this Code to ensure that the transmission continues.

B. Hardware handshake: The second is hardware handshake. Like the Tx and Rx lines, the RTS/CTS and DTR/DSR work together, one as the output and the other as the input. The first line is RTS (request to send) and CTS (clear to send ). When the receiver is ready to receive data, it is set to a high RTS line, indicating that it is ready. If the sender is also ready, it is set to a high CTS, indicating that it is about to send data. Another line is DTR (Data Terminal ready) and DSR (data set ready ). These are mainly used for modem communication. Enable the serial port to communicate with the modem. For example, when the modem is ready to receive data from the PC, it is set to a high DTR line, indicating that the connection to the telephone line has been established. When the DSR line is set to 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 to transmit a single data packet.

In LabWindows, The setctsmode function enables or disables the use of hardware handshakes. If the CTS mode is enabled, LabWindows uses the following rules:
When the PC sends data:
The RS-232 library must detect the high CTS line before sending data.

When the PC receives data:
If the port is opened and the input queue has no time to receive data, the library function is set to high-priority (RTS) and DTR.
If the input queue is 90% full, the library function is set to lower the RTS, but the DTr remains high.
If the port queue is almost empty, the crying count is high, but the DRT remains high.
If the port is disabled, the library function is set to lower the values of RTS and DTR.

C. XMODEM handshake: the handshake discussed at the end is called the XMODEM file transfer protocol. This Protocol is very common in modem communication. Although it is usually used in modem communication, the XMODEM protocol can be used directly in other devices that follow this protocol. In LabWindows, the actual XMODEM application hides users. As long as the PC and other devices use the XMODEM protocol, use the XMODEM function of LabWindows during file transfer. The functions are xmodemconfig, xmodemsend, and xmodemreceive.

XMODEM uses the following protocols: start_of_data, end_of_data, neg_ack, wait_delay, start_delay, max_tries, and packet_size. These parameters need to be determined by both parties. The standard XMODEM has a standard definition: however, you can use the xmodemconfig function to modify these parameters to meet specific needs. The usage of these parameters is determined by the neg_ack character sent by the receiver. This notification sender prepares to receive data. It starts sending an attempt. There is a timeout parameter start_delay. When the timeout attempt exceeds the number of max_ties attempts, or the sender stops trying to receive the start_of_data sent by the receiver. If start_of_data is received from the sender, the receiver reads the subsequent information packet. The package contains the number of packages and the number of packages as the actual packet size for error verification, packet_size, and the sum of the values for further error checks. After reading data, the Receiver calls wait_delay and wants the sender to send a response. If the sender does not receive a response, it resends the packet until it receives the response or exceeds the maximum number of resends max_tries. If no response is received, the sender notifies the user that data transmission fails.
Because the data must be sent in pack_size bytes by package, when the last packet is sent, if the data is not full, the ASCII Code null (0) bytes will be entered. As a result, more data is received than the original data. Do not use Xon/xoff in the case of XMODEM, because the number of XMODEM senders sending packets is likely to be increased to the value of the Xon/off control character, resulting in communication failure.

Related links:
Knowledgebase 1m9d8h6q: Serial Communication starting point
Knowledgebase 3 draguoy: A quick comparison of RS-232, RS-422, and RS-485 serial communication interfaces
 

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.