The basic concept of serial communication

Source: Internet
Author: User
Tags control characters requires file transfer protocol
Questions:From there I can learn the basics of serial communication

Answer:The basic concept of serial communication
1, what is the 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 the serial port.
The serial port is the protocol for a very general device communication on a computer (not to be confused with the Universal Serial Bus Universal Serial bus or USB). Most computers contain two RS232-based serial ports. Serial port is also a common communication protocol for instrumentation equipment, and many GPIB-compatible devices also come with RS-232 ports. At the same time, serial communication protocol can be used to obtain data of remote acquisition device.

The concept of serial communication is very simple, the serial port bitwise (BIT) Send and receive bytes. Although it is slower than parallel communication by Byte (byte), the serial port can receive data with another line while sending data using one line. It is simple and enables long-distance communication. For example, when IEEE488 defines the parallel state of passage, the equipment line is usually not more than 20 meters, and the length of any two devices shall not exceed 2 meters, but for the serial port, the length can reach 1200 meters.

Typically, the serial port is used for the transmission of ASCII code characters. Communication is done using 3 wires: (1) ground, (2) sent, (3) received. Because the serial communication is asynchronous, the port can send data on one line and receive data on the other line at the same time. Other lines are used to shake hands, but are not required. The most important parameters of serial communication are baud rate, data bit, stop bit, and parity check. For two ports to pass, these parameters must match:
A, baud rate: This is a parameter that measures the speed of communication. It represents the number of bits transmitted per second. For example, 300 baud indicates that 300 bits are sent per second. When we refer to the clock cycle, we refer 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. Usually the baud rate of the telephone line is 14400,28800 and 36600. The baud rate can be much larger than these values, but the baud rate is inversely proportional to the distance. The high baud rate is often used to place very close inter-instrument communication, the typical example being the communication of a GPIB device.
b, Data bits: This is the parameter that measures the actual data bits in the communication. When the computer sends a packet, the actual data is not 8-bit, and the standard values are 5, 7, and 8 bits. How to set up depends on the information you want to send. For example, the standard ASCII code is 0~127 (7-bit). The extended ASCII code is 0~255 (8-bit). If the data uses simple text (the standard ASCII code), then each packet uses 7 bits of data. Each package refers to a byte, which includes the start/stop bits, data bits, and parity bits. Since 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 represent the last one in a single package. Typical values are 1, 1.5, and 2 bits. Since the data is timed on the transmission line, and each device has its own clock, it is likely that there is a small difference between the two devices in the communication. So the stop bit is more than just the end of the transmission, and provides the opportunity for the computer to calibrate the clock synchronization. The more bits that apply to the stop bit, the greater the tolerance for different clock synchronizations, but the slower the data transfer rate.
D, parity bit: A simple method of error detection in serial communication. There are four methods of error detection: Occasional, odd, high and low. Of course, no check bit is also possible. For even and odd checks, the serial port sets the check bit (one after the data bit), using a value to ensure that the transmitted data has an even or odd logical high. For example, if the data is 011, for parity, the check bit is 0, and the number of bits that are logically high is an even number. If it is a parity check, the parity bit is 1, so there are 3 logical highs. High and low levels do not really check the data, simple set logic or low logic. This allows the receiving device to know the state of a bit, the opportunity to determine whether there is noise interfering with the communication or whether the transmission and reception of the data is not synchronized.

2, what is RS-232.
The RS-232 (ansi/eia-232 standard) is the serial connection standard on IBM-PC and its compatible machines. Can be used for many purposes, such as connecting the mouse, printer or modem, but also can be connected to industrial instruments and meters. For the improvement of drive and wiring, the transmission length or speed of RS-232 in practical applications often exceeds the standard value. RS-232 is limited to the PC serial port and the point-to-point communication between devices. RS-232 serial communication maximum distance is 50 feet.

DB-9 Pin Connection Head
-------------
\ 1 2 3 4 5/
\ 6 7 8 9/
-------
The cross-section of a line that is connected from the computer.
RS-232 pin Function:

Data:
TXD (PIN 3): Serial data output
RXD (pin 2): Serial data input

Shake hands:
RTS (pin 7): Send data request
CTS (pin 8): Clear Send
DSR (PIN 6): Data Send ready
DCD (pin 1): Data carrier detection
DTR (pin 4): Data Terminal ready

Ground:
GND (pin 5): Ground

Other
RI (pin 9): Ringtone indication

3, what is RS-422.
The RS-422 (EIA rs-422-a Standard) is the serial connection standards for Apple's Macintosh computers. The RS-422 uses a differential signal to RS-232 the signal using a non-balanced reference. Differential transmission uses two wires to send and receive signals, compared to RS-232, which can better resist noise and have a longer transmission distance. Better noise resistance and further transmission distances in industrial environments are a big advantage.

4, what is RS-485.
The RS-485 (EIA-485 standard) is a RS-422 improvement because it increases the number of devices, from 10 to 32, and defines the electrical characteristics of the maximum number of devices to ensure sufficient signal voltages. With the ability to have multiple devices, you can use a single RS-422 port to establish a network of devices. Excellent noise and multi-device capability, serial connections Choose RS-485 when establishing a distributed device network for PC-connected, other data collection controllers, HMI or other operations in industrial applications. RS-485 is a superset of RS-422, so all RS-422 devices can be RS-485 controlled. The RS-485 can be used in serial traffic over a 4000-foot line.

DB-9 PIN Connection

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

The cross-section of a line that is connected from the computer.

Pin function of 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 Pass mode allows simple connection of three lines: Tx, RX, and ground. However, for data transmission, both parties must use the same baud rate for the timing of the information. Although this approach is sufficient for most applications, this use is limited in cases where the receiver is overloaded. This requires the handshake function of the serial port. In this section, we discuss three of the most commonly used RS-232 handshake forms: software handshake, hardware handshake, and Xmodem.

A, software handshake: the first handshake we discussed is the software handshake. This is usually used in situations where the actual data is a control character, similar to how GPIB uses a command string. The required line is still three root: Tx,rx and ground, since the control character is not distinguished on the transmission line and the normal character, the function Setxmodem allows the user to enable or disallow the user to use two control characters Xon and Oxff. These characters are sent by the receiver in the communication, causing the sender to pause.
For example, suppose the sender sends data at high baud rate. In transit, the receiver discovers that the input buffer is full because the CPU is busy with other work. In order to temporarily stop the transmission, the receiver sends Xoff, the typical value is decimal 19, or hexadecimal 13, until the input buffer is empty. Once the receiver is ready to receive, it sends Xon, the typical value is decimal 17, which is hexadecimal 11, which continues to communicate. When the input buffer is half full, Labwindows sends the 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 the use of a hardware line handshake. Like TX and RX lines, rts/cts and DTR/DSR work together, one as the output and the other as input. The first set of lines is the RTS (Request to send) and the CTS (Clear to send). When the receiver is ready to receive the data, it sends a high RTS line indicating that it is ready, and if the sender is also ready, it is high CTS, indicating that it is about to send data. Another set of lines is DTR (data Terminal Ready) and DSR (data Set Ready). These are now mainly used for modem communication. Make the serial port and modem communicate their state. For example: When the modem is ready to receive data from the PC, it sets the high DTR line, which indicates that the connection to the telephone line has been established. Read the DSR line height and the PC starts sending data. A simple rule is that DTR/DSR is used to indicate system communication readiness, while rts/cts is used for the transmission of a single packet.

In Labwindows, the function Setctsmode enables or disables the use of a hardware handshake. If the CTS mode is enabled, Labwindows uses the following rules:
When the PC sends the data:
The RS-232 library must detect the CTS line height before it can send data.

When the PC receives data:
If the port is open and the input queue has empty receive data, the library function is set to high RTS and DTR.
If the input queue is 90% full, the library function puts the RTS low, but the DTR maintains the high level.
If the port queue is nearly empty, cry the number high RTS, but keep the DRT high.
If the port is closed, the library function is low RTS and DTR.

C,xmodem handshake: The last handshake discussed is called the Xmodem file Transfer protocol. This protocol is very common in modem communication. Although it is commonly used in modem communication, the XMODEM protocol can be used directly in other device communications that follow this protocol. In Labwindows, the actual Xmodem application is hidden from the user. As long as the PC and other devices use the Xmodem protocol, the Labwindows Xmodem function is used in the file transfer. Functions are Xmodemconfig,xmodemsend and xmodemreceive.

Xmodem uses protocols in the following parameters: Start_of_data, End_of_data, Neg_ack, Wait_delay, Start_delay, Max_tries, packet_size. These parameters require communication between the parties to determine that the standard Xmodem has a standard definition: However, the Xmodemconfig function can be modified to meet the specific needs. The way these parameters are used is determined by the character Neg_ack sent by the receiver. This notifies the sender that it is ready to receive data. It starts to attempt to send, has a timeout parameter start_delay, when the timeout attempt exceeds the max_ties number of times, or receives start_of_data sent by the receiver, the sender stops trying. If Start_of_data is received from the sender, the receiver reads the successor packet. The package contains the number of packages, the complement of the number of packages as the error check, the packet_size byte size of the actual packet, and further error checking the summation checksum value. After the data is read, the receiver calls Wait_delay and then sends a response to the sender. If the sender does not receive a response, it will resend the packet until it receives a response or exceeds the maximum number of max_tries. If the response has not been received, the sender notifies the user that the data transfer failed.
Since the data must be sent in Pack_size bytes, when the last packet is sent, if the data is not enough to fill a packet, the ASCII code null (0) bytes will be populated later. This results in more data being received than the original data. Do not use Xon/xoff in xmodem cases, because the number of packets emitted by the Xmodem sender is likely to increase to the value of the Xon/off control character, resulting in a communication failure.


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.