RS232 serial communication principle
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 that interferes with communication or whether the transmitted and received data are not synchronized.