Serial communication is the most basic communication method faced by electronic engineers. RS-232 is the simplest one. Many beginners often don't know the connection and difference between UART and RS-232, RS-422, and RS-485. This article will talk about the understanding of these concepts and help you to clarify the relationship between them.
If you compare serial communication to traffic and UART to station, then one frame of data is like a car. The car runs on the road and must obey the traffic rules. If it is in the city, the general speed limit is 30, 40, and the highway can go to 120. What is the speed of the car, and how much speed limit depends on how the agreement is stipulated. Common serial protocols are RS-232, RS-422, RS-485, etc. What are the nuances between them? Let's discuss it together.
First, what is UART?
The UART is a Universal Asynchronous Receiver/Transmitter, commonly referred to as a UART. It is an asynchronous transceiver that is a key module for asynchronous communication between devices. The UART is responsible for processing the serial/parallel, parallel/serial conversion between the data bus and the serial port, and specifies the frame format; the communication parties can use the same frame format and baud rate to share the clock signal. The communication process can be completed with only two signal lines (Rx and Tx), so it is also called asynchronous serial communication.
If you add a suitable level shifter, such as SP3232E, SP3485, the UART can also be used for RS-232, RS-485 communication, or connected to the computer's port. UART applications are very extensive, and UARTs are used in applications such as cell phones, industrial controls, and PCs.
The UART uses asynchronous, serial communication.
Serial communication refers to the sequential transmission of data bit by bit using a transmission line. The utility model has the advantages that the communication line is simple, the communication can be realized by using a simple cable, the cost is reduced, and the application is suitable for long-distance communication, but the transmission speed is slow.
Asynchronous communication uses one character as the transmission unit. The time interval between two characters in communication is not fixed, but the time interval between two adjacent bits in the same character is fixed.
The data transfer rate is expressed in baud rate, which is the number of binary bits transmitted per second. For example, if the data transfer rate is 120 characters/second and each character is 10 bits (1 start bit, 7 data bits, 1 check bit, 1 end bit), the baud rate is 10 ×120=1200 characters/second=1200 baud.
The data communication format is as follows:
The meaning of each of them is as follows:
Start bit: A logic "0" signal is sent first to indicate the beginning of the transmitted character. Data bits: can be 5~8-bit logic "0" or "1". Such as ASCII code (7 bits), extended BCD code (8 bits). The little endian transmits the check digit: after the data bit is added, the number of bits of "1" should be an even (even parity) or an odd (odd check) stop bit: it is the end of a character data. It can be a high level of 1 bit, 1.5 bits, or 2 bits. Idle bit: In the logic "1" state, there is no data transmission on the current line.
Note: Asynchronous communication is transmitted by character. After receiving the start signal, the receiving device can receive correctly by keeping the synchronization with the transmitting device within one character transmission time. The arrival of the start bit of the next character causes the synchronization to be recalibrated (by detecting the start bit to achieve self-synchronization of the transmit and receive clocks)
Second, the RS-232 standard
RS-232 is a serial physical interface standard developed by the Electronic Industry Association (EIA). RS is an abbreviation of English "Recommended Standard" and 232 is an identification number. RS-232 is a specification of electrical and physical characteristics that acts only on the data transmission path. It does not contain the way data is processed. Need to explain, many people often mistake RS-232, RS-422, RS-485 as the communication protocol, which is very inappropriate, in fact, they are only a mechanical and electrical interface standard for UART communication (at most The physical level in the network protocol).
The standard specifies a 25-pin DB-25 connector that specifies the signal content of each pin of the connector and also specifies the level of each signal. IBM's PCs later reduced RS-232 to a DB-9 connector, making it the de facto standard today. The industrial control RS-232 port generally uses only three lines of RXD (2), TXD (3), and GND (5).
In the early days, since the PCs all had an RS-232 interface, we chose RS-232 when we needed to use the UART. But now personal computers, not just notebooks, including desktops, no longer have an RS-232 interface. Everyone sees that there is no DB9 interface on the computer motherboard. So now the development board chooses TTL UART, or direct UART to USB on the development board.
Embedded in the serial port, generally refers to the UART port, but we often do not know the difference between it and the COM port, and RS232, TTL and other relationships, in fact, UART, COM refers to the physical interface form (hardware), and TTL, RS-232 refers to the level standard (electrical signal).
The UART has 4 pins (VCC, GND, RX, TX), with a TTL level, a low level of 0 (0V), and a high level of 1 (3.3V or more).
Third, RS-485/RS-422 standard
The RS-232 interface enables point-to-point communication, but this method does not enable networking. So, in order to solve this problem, a new standard RS-485 was produced. The RS-485 data signal uses differential transmission, also known as balanced transmission. It uses a pair of twisted pairs, one of which is defined as A and the other is defined as B.
Normally, the positive level between the transmit drivers A and B is +2 to +6V, which is a logic state, and the negative level is -2 to 6V, which is another logic state. There is also a signal ground C, which has an "enable" end in RS-485, which is available and not available in RS-422.
The electrical performance of RS-422 is exactly the same as RS-485. The main difference is that RS-422 has 4 signal lines: two transmissions and two receptions. Since the reception and transmission of RS-422 are separate, it can be simultaneously transmitted and transmitted (full duplex), and because full duplex requires transmission and reception to have a separate channel, RS-422 is suitable for communication between two stations. Star network, ring network, can not be used for bus network; RS-485 only has 2 signal lines, so it can only work in half-duplex mode, which is often used in bus network.
1. Electrical characteristics of RS-485: Logic "1" is represented by a voltage difference between two lines of +(2~6)V; logic "0" is represented by a voltage difference between two lines - (2~6)V . The interface signal level is lower than that of RS-232-C, and it is not easy to damage the chip of the interface circuit, and the level is compatible with the TTL level, which is convenient for connection with the TTL circuit.
2. The maximum transmission rate of RS-485 data is 10Mbps.
3. RS-485 interface is a combination of balanced driver and differential receiver, which has enhanced anti-common mode interference capability, that is, good anti-noise interference.
4. The maximum communication distance of RS-485 is about 1219M, and the maximum transmission rate is 10Mb/S. The transmission rate is inversely proportional to the transmission distance. At the transmission rate of 100Kb/S, the maximum communication distance can be achieved. For long distances, a 485 repeater is required. The RS-485 bus generally supports up to 32 nodes. If a special 485 chip is used, it can reach 128 or 256 nodes, and the maximum can support up to 400 nodes.
Due to the early appearance of the RS-232 interface standard, it is inevitable that there are deficiencies, mainly the following:
(1) The signal level of the interface is high, which is easy to damage the interface circuit chip. Because the 232 level is not compatible with the TTL level, it is necessary to use a level conversion circuit to connect with the TTL circuit.
(2) The transmission rate is low. When transmitting asynchronously, the baud rate is 20Kbps. Now with the new UART chip, the baud rate is 115.2Kbps (1.832M/16);
(3) The interface uses a signal line and a signal return line to form a common ground transmission form. This common ground transmission is prone to common mode interference, so the noise immunity is weak;
(4) The transmission distance is limited, and the maximum transmission distance is 50 meters. In fact, it can only be used at about 15 meters.
(5) RS-232 only allows one-to-one communication, and does not consider forming a serial bus. (This is very important. In many control scenarios, there is a lot of control. If the master device needs to communicate with the device peer-to-peer, then the site is wired into a spider web.)
Unbalanced serial communication interface RS-423, RS-449
Balanced serial communication interface 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, and RS-232 uses unbalanced ground reference signals. Differential transmission uses two lines to transmit and receive signals. Compared to RS-232, it is better resistant to noise and has a longer transmission distance. Better noise immunity and longer transmission distances in an industrial environment are a big advantage.
Fourth, RS-232 and RS-485 comparison
1. Anti-interference: RS485 interface is a combination of balanced driver and differential receiver, which has good anti-noise interference. The RS232 interface uses a signal line and a signal return line to form a common transmission form. This common transmission is prone to common mode interference.
2. Transmission distance: The maximum transmission distance of the RS485 interface is 1200 meters (9600bps), which is actually up to 3000 meters. The RS232 transmission distance is limited, and the maximum transmission distance is 50 meters. In fact, it can only be used at about 15 meters.
3. Communication capability: The RS-485 interface allows up to 128 transceivers to be connected on the bus. Users can easily establish a device network using a single RS-485 interface. RS-232 only allows one-to-one communication.
4, transmission rate: RS-232 transmission rate is low, in the asynchronous transmission, the baud rate is 20Kbps. The maximum data transfer rate of RS-485 is 10Mbps.
5, signal line: RS485 interface half-duplex network, generally only need two signal lines. The RS-232 port generally uses only three lines of RXD, TXD, and GND.
6, electrical level value: RS-485 logic "1" with the voltage difference between the two lines is + (2-6) V; logic "0" with the voltage difference between the two lines - (2-6) V means. The voltage of any one of the signal lines in RS-232-C is in a negative logic relationship. Namely: logic "1", -5 - -15V; logic "0" +5- +15V.
V. Comparison of RS-422 and RS-485
The electrical performance of RS-485 is exactly the same as RS-422. The main differences are:
1. RS-422 has 4 signal lines: two transmissions (Y, Z) and two receptions (A, B). Since the RS-422 is transmitted and sent separately, it can be received and sent simultaneously (full duplex).
2. RS-485 has only two data lines: both transmit and receive are A and B. Since the RS-485 is transmitted and shared by two lines, it cannot be received and sent at the same time (half duplex).
The RS-485 standard uses balanced transmission, differential receiving data transceiver to drive the bus, specific specifications:
Receiver input resistance RIN ≥ 12kΩ
The driver can output a common mode voltage of ±7V
Input capacitance ≤ 50pF
When the number of nodes is 32 and the terminal resistance of 120Ω is configured, the driver can output at least 1.5V (the size of the terminating resistor is related to the parameters of the twisted pair used)
The input sensitivity of the receiver is 200mV (ie (V+)-(V-)≥0.2V, indicating signal "0"; (V+)-(V-)≤-0.2V, indicating signal "1")
Because of the long distance of RS-485, multi-node (32) and low transmission line cost, EIA RS-485 becomes the preferred standard for data transmission in industrial applications.
(1) Electrical characteristics of RS-485: Transmitter: logic "0" is represented by the voltage difference between two lines + (2 ~ 6) V; logic "1" is the voltage difference between two lines - (2 ~ 6) V means. Receiver: A is higher than 200mV above B, which is considered to be logic "0", and A is considered to be logic "1" when it is 200mV or more lower than B;
(2) RS-485 data has a maximum transfer rate of 10 Mbps. However, since RS-485 often communicates with the RS-232 port of a PC, it is generally up to 115.2 Kbps. And because the too high rate will reduce the RS-485 transmission distance, it is often about 9600bps or less;
(3) RS-485 interface is a combination of balanced driver and differential receiver, which has good anti-noise interference;
(4) The maximum transmission distance of the RS-485 interface is 1200 m (9600 bps), which is actually up to 3000 m. The RS-485 interface allows up to 128 transceivers on the bus, ie RS-485 has more Machine communication function, so users can easily establish a network with a single RS-485 interface. Because the half-duplex network consisting of RS-485 interfaces generally only needs two signal lines, the RS-485 interfaces are transmitted by twisted pair. The international standard of RS-485 does not specify the interface connector standard of RS-485, so it is possible to use terminal blocks or connectors such as DB-9 and DB-25.
When using the RS-485 interface, the maximum cable length allowed for data transmission from the generator to the load is a function of the data signal rate for a particular transmission line diameter. This length data is mainly limited by signal distortion and noise. . The relationship between the maximum cable length and the signal rate is obtained by using a 24AWG copper twisted pair telephone cable (wire diameter 0.51mm), a line bypass capacitor of 52.5PF/M, and a terminal load resistance of 100 ohms. (Quoted from GB11014-89 Appendix A). When the data signal rate drops below 90 Kbit/s, the cable length is limited to 1200 m assuming a maximum allowable signal loss of 6 dBV. In fact, in practice, it is possible to obtain a cable length larger than this. When cables with different wire diameters are used, the maximum cable lengths obtained are not the same. For example, when the data signal rate is 600Kbit/S, the 24AWG cable is used, and the maximum cable length is 200m. If 19AWG cable (wire diameter is 0.91mm), the cable length can be greater than 200m; if 28AWG cable is used (wire diameter is 0.32) Mm), the cable length can only be less than 200m.
The long-distance communication of RS-485 is recommended to use a shielded cable and the shield as a ground.
Six factors affecting the communication speed and communication reliability of RS-485 bus
1. Signal reflection in the communication cable
During communication, there are two signal factors that cause signal reflection: impedance discontinuity and impedance mismatch.
The impedance is not continuous, and the signal suddenly encounters a small or no cable impedance at the end of the transmission line. The signal will cause reflection at this place, as shown in the figure. The principle of such signal reflection is similar to the reflection of light from one medium into another. To eliminate this reflection, it is necessary to connect a terminating resistor of the same magnitude as the characteristic impedance of the cable at the end of the cable to make the impedance of the cable continuous. Since the transmission of the signal on the cable is bidirectional, a similarly sized termination resistor can be bridged across the other end of the communication cable.
Theoretically, signal reflection is no longer present as long as the terminating resistor matching the characteristic impedance of the cable is bridged at the end of the transmission cable. However, in the implementation application, since the characteristic impedance of the transmission cable is related to the application environment such as the communication baud rate, the characteristic impedance cannot be exactly equal to the termination resistance, so more or less signal reflections may exist.
Another cause of signal reflection is the impedance mismatch between the data transceiver and the transmission cable. The reflection caused by this reason is mainly manifested in the fact that when the communication line is in the idle mode, the entire network data is confusing.
The effect of signal reflection on data transmission is ultimately because the reflected signal triggers the comparator at the receiver input, causing the receiver to receive an erroneous signal, resulting in a CRC check error or an entire data frame error.
In signal analysis, the parameter that measures the intensity of the reflected signal is the RAF (Refection Attenuation Factor). Its calculation formula is as shown in equation (1).
RAF=20lg(Vref/Vinc) (1)
Where: Vref—the magnitude of the voltage of the reflected signal; Vinc—the magnitude of the voltage at the point where the cable is connected to the transceiver or terminating resistor.
The specific measurement method is shown in Figure 3. For example, the experimentally measured 2.5MHz incident signal sine wave has a peak-to-peak value of +5V and the reflected signal has a peak-to-peak value of +0.297V. When the communication cable is at a communication rate of 2.5MHz, its reflection attenuation factor is :
RAF=20lg(0.297/2.5)=-24.52dB
To reduce the effect of reflected signals on communication lines, noise suppression and biasing resistors are often used. In practical applications, for relatively small reflected signals, for the sake of simplicity and convenience, a method of applying a bias resistor is often employed. In the communication line, how to improve the reliability of communication by adding a bias resistor.
2. Signal attenuation in the communication cable
The second factor affecting signal transmission is the attenuation of the signal during transmission of the cable. A transmission cable can be seen as an equivalent circuit consisting of a distributed capacitor, a distributed inductor, and a resistor, as shown.
The distributed capacitance C of the cable is mainly produced by two parallel wires of the twisted pair. The resistance of the wire here has little effect on the signal and can be ignored. The loss of the signal is mainly due to the LC low-pass filter composed of the distributed capacitance of the cable and the distributed inductance. The LAN standard two-core cable for PROFIBUS (the standard cable selected by Siemens for the DP bus), the attenuation coefficient at different baud rates is shown in Table 1.
Cable attenuation factor
3, pure resistance load in the communication cable
The third factor that affects communication performance is the size of a purely resistive load (also known as a DC load). The pure resistive load referred to here is mainly composed of a terminating resistor, a bias resistor and an RS-485 transceiver.
In describing the EIA RS-485 specification, it was mentioned that the RS-485 driver can output a differential voltage of at least 1.5V with 32 nodes and 150Ω termination resistors. The input resistance of a receiver is 12kΩ, and the equivalent circuit of the whole network is shown in Figure 5. According to this calculation, the load capacity of the RS-485 driver is:
RL=32 input resistors in parallel 2 terminating resistors=((12000/32)×(150/2))/(12000/32)+(150/2))≈51.7Ω
The more commonly used RS-485 drivers are MAX485, DS3695, MAX1488/1489, and SN75176A/D used by Hollysys. Some of them have an RS-485 driver with a load capacity of 20Ω. Regardless of many other factors, the maximum number of nodes a node can carry will be much larger than 32 according to the relationship between drive capability and load.
On-line bias resistors are necessary when the communication baud rate is high. The connection method of the bias resistor is shown in Figure 6. Its role is to pull the level of no data (idle mode) off the 0 level after the line enters the idle state, as shown in Figure 7. In this way, even if a relatively small reflected signal or interference occurs in the line, the data receiver attached to the bus will not malfunction due to the arrival of these signals.
The magnitude of the bias resistor can be calculated by the following example:
Terminal resistance Rt1=Rr2=120Ω;
Assuming that the maximum peak-to-peak value Vref ≤ 0.3 Vp-p of the reflected signal, the voltage Vref of the negative half cycle is ≤ 0.15 V; the reflected current Iref ≤ 0.15 / (120 | | 120) = 2.5 mA caused by the reflected signal on the resistance of the terminal. The hysteresis value of a typical RS-485 transceiver (including the SN75176) is 50mV, ie:
(Ibias-Iref)×(Rt1||Rt2)≥50mV
Then we can calculate the bias current generated by the bias resistor Ibias ≥ 3.33mA
+5V=Ibias (R pull-up + R pull-down + (Rt1||Rt2)) (2)
Equation 2 can be used to calculate R pull-up = R pull-down = 720Ω
In practical applications, there are two ways to add a bias resistor to the RS-485 bus:
(1) Assign the bias resistor balance to each transceiver on the bus. This method adds a bias resistor to each transceiver attached to the RS-485 bus, adding a bias voltage to each transceiver.
(2) Only one pair of bias resistors is used on a segment of the bus. This method is effective for the presence of large reflected or interfering signals on the bus. It is worth noting that the addition of bias resistors increases the load on the bus.
Seven, the relationship between the load capacity of the RS-485 bus and the length of the communication cable
When designing the network configuration (bus length and number of loads) consisting of RS-485 bus, three parameters should be considered: pure resistive load, signal attenuation and noise margin. The two parameters of pure resistive load and signal attenuation have been discussed above. Now we will discuss the noise margin (Noise Margin). The noise margin of the RS-485 bus receiver should be at least 200mV. The previous arguer was made assuming a noise margin of zero. In practical applications, in order to improve the anti-interference ability of the bus, it is always desirable that the noise margin of the system is better than that specified in the EIA RS-485 standard. From the following formula, we can see the relationship between the bus load and the length of the communication cable:
Vend=0.8(Vdriver-Vloss-Vnoise-Vbias)(3)
Where: Vend is the signal voltage at the end of the bus, which is specified as 0.2V in the standard measurement; Vdriver is the output voltage of the driver (related to the number of loads. The number of loads is between 5 and 35, Vdriver = 2.4V; when the number of loads is less than 5, Vdriver = 2.5V; when the load is greater than 35, Vdriver ≤ 2.3V); Vloss is the loss of the signal in the transmission process of the bus (related to the specification and length of the communication cable), the standard cable provided by Table 1 Attenuation coefficient, according to the formula attenuation coefficient b=20lg (Vout/Vin) can calculate Vloss=Vin-Vout=0.6V (Note: the communication baud rate is 9.6kbps, the cable length is 1km, if the special rate increases, Vloss will increase accordingly. Large); Vnoise is the noise margin, specified as 0.1V in the standard measurement; Vbias is the bias voltage provided by the bias resistor (typically 0.4V).
Multiplying 0.8 in equation (3) is to prevent the communication cable from entering the fully loaded state. It can be seen from equation (3) that the size of Vdriver is inversely proportional to the number of loads on the bus. The size of Vloss is inversely proportional to the length of the bus. The other parameters are only related to the type of driver used. Therefore, on the RS-495 bus with the selected drive, the number of loaded loads is directly related to the maximum distance that the signal can be transmitted, given the constant baud rate. The specific relationship is: within the allowable range of the bus, the more the load is, the smaller the distance that the signal can be transmitted; the less the load data, the farther the signal can be transmitted.
Eight, the effect of distributed capacitance on the transmission performance of RS-485 bus
The distributed capacitance of the cable is mainly generated by two parallel wires of the twisted pair. In addition, there is also a distributed capacitance between the wire and the ground. Although it is small, it cannot be ignored in the analysis. The effect of distributed capacitance on bus transmission performance is mainly because the fundamental wave signal is transmitted on the bus, and the signal expression is only "1" and "0". In a special byte, such as 0x01, the signal "0" causes the distributed capacitance to have sufficient charging time, and when the signal "1" comes, due to the charge in the distributed capacitance, it is too late to discharge, (Vin+)-(Vin-)- Still greater than 200mV, the result is that the love is mistaken as "0", and eventually leads to CRC check error, the entire data frame transmission error. The specific process is shown in the figure.
Due to the distribution effect on the bus, data transmission errors are caused, which degrades the overall network performance. There are two ways to solve this problem:
(1) reduce the baud rate of data transmission;
(2) Use a cable with a small distributed capacitance to improve the quality of the transmission line.
Only a pair of twisted pairs are used to connect the A and B ends of each interface without grounding the signal of the RS-485 communication link, and in some cases, it can work, but it poses a hidden danger to the system. The RS-485 interface transmits signals in a differential manner and does not need to detect the signal system for a certain reference point. It is only necessary to detect the potential difference between the two lines. However, it should be noted that the transceiver can only work normally if the common mode voltage does not exceed a certain range (-7V to +12V). When the common mode voltage is outside this range, it will affect the reliability of the communication until the interface is damaged. As shown in Figure 1, when transmitter A sends data to receiver B, the output common-mode voltage of transmitter A is VOS. Since the two systems have separate grounding systems with ground potential difference VGPD, then the receiver input The common mode voltage will reach VCM=VOS+VGPD. The RS-485 standard stipulates that VOS ≤ 3V, but VGPD may have a large amplitude (ten or even tens of volts), and may be accompanied by strong interference signals, causing the receiver common-mode input VCM to exceed the normal circumference and generate on the signal line. Interference currents affect normal communication or damage the device.
to sum up:
The serial port is a very common device interface. It is a common communication interface for instrumentation equipment. It is often used to remotely collect device data or implement remote control. The development of the serial port is also relatively simple, and it is one of the favorite interfaces of many engineers.
Marine baffle control box,baffle control box,Marine baffle controller,baffle controller
Taizhou Jiabo Instrument Technology Co., Ltd. , https://www.taizhoujbcbyq.com