Basic knowledge of UART and RS232, RS485

Source: Internet
Author: User

Blog directory:

1, the UART and RS232, RS485 relations:

2, RS232 and RS485 of the difference and pin introduction

3. Reference documents

The text is as follows


I. The relationship between UART and RS232 and RS485:

Communication problems, and traffic is the same. Serial communication, we can use bus to analogy.

Bus operation can be easily divided into two parts: 1, Station 2, the road where the station determines what (people), how to send (shift) and so on. When the car runs on the road, it is necessary to abide by the rules of road traffic, crossing the bridge of the rules, high-speed rules, and the station is not related.
Back to the serial communication, in fact, the UART is equivalent to the station, while the rs232/rs485 corresponds to the rules of the road.


UART, is a general-purpose asynchronous transceiver (Universal asynchronous Receiver/transmitter), since it is a "device", it is obvious that it is an equipment, to complete a specific function of the hardware, it is not a protocol itself. So what does it have to do? Its most basic function is the conversion between serial data and parallel data. We know that the data in the computer is in the basic unit of byte, and the access to a byte is parallel, that is, 8 bits are obtained/written at the same time. Serial communication requires that this byte be "broken" and sent and received in chronological order to achieve serial. For example: The data in memory is: 1 1 1 0 0 1 0 1 The actual effect of the serial send is (sort by time "Note 1"):10100111Reception is the inverse process of the above process. This is the most basic work of the UART, and further, it must also control the "departure shift", such as the confirmation of a byte of the 8 bit when the start, and when the end of the two shifts between the minimum of a buffer, and so on.       This part, also has the characteristics of the agreement, but compared to the agreement on the road, more general, or, is with the car on what road, relatively independent. So what are the rules on the road?


rs232/rs485, is the two different electrical protocols, that is, the electrical characteristics and physical characteristics of the regulation, for the data transmission path, it does not contain the data processing method. For example, the most notable feature is: RS232 use3-15v effective level, and the UART, because there is no regulation of the electrical characteristics, so the direct use of the CPU level, is the so-called TTL level (possibly between 0~3.3v). More specifically, the electrical characteristics also determine the connection mode of the line, such as RS232, the provision of electricity flat representation of data, so the line is a single line, with two lines to achieve the purpose of full duplex; RS485,using the differential level to represent the data, it is necessary to use two lines to achieve the basic requirements of the transmission of data, to achieve full-duplex, it is necessary to use 4 wires. However, whether using RS232 or RS485, they are relatively independent from the UART, but due to the difference in electrical characteristics, it is necessary to have a dedicated device and a UART connection to complete the normal flow of data between the line and the UART.
RS232 even specifies the specific style of the interface, such as the DB9 interface
Summary: in a sense, it can be said that the line is only the current, rs232/rs485 specify the current on what kind of line flow and flow of the style; at the UART, the current is interpreted and assembled into data and becomes a form of direct read and write by the CPU.

Note 1 "Here is the example is the small-end transmission mode, is the basic serial port transfer mode, but the big-endian mode of serial port transmission is also present, rare."

The UART understands this: Each SOC chip has a UART controller inside it, which is the "station" above. But generally speaking, the UART refers to a serial communication protocol. The data frame format, baud rate, etc. are specified.
RS232 and RS485: The electrical characteristics of the data communication are specified. Is the concept of the physical layer, corresponding to the physical period of the RS232 or RS485 driver chip, the CPU transmitted over the UART voltage signal is driven to RS232 or RS485 level logic.
(Blue font, is the personal understanding, if there is not the right place, want to guide)

Asynchronous serial port is one of the most important communication interfaces of industrial equipment at present. In the specific industrial field, the electrical interface of the serial port is the most common in RS232 and RS485. Most of the serial port in the form of TTL signal from the card PIN input and output, customers need to use their own application board to add the corresponding driver circuit unit to obtain the required serial interface, such as RS232 or RS485. In the actual application, because the field equipment serial Port interface situation is not certain, this requests the customer equipment simultaneously to have the RS232 and the RS485 two kinds of interface function.
The RS232 interface is a unipolar signal with positive and negative levels, generally with a 3-wire interface, and the signal includes RS232_TX, RS232_RX, and GND, Full duplex communication capability。 The RS485 interface uses a pair of TTL-level differential signals rs485_d-and rs485_d+, only half-duplex communication, in the direction of communication (receive or send) switching aspect, generally there are two ways: one way is to use ttl_txd through certain processing as direction control, this way is also known as Automatic direction switching mode, the other way is to use the serial Port RTS control line to control the direction, RTS is active in the sending State, invalid in the receiving State.


The RS485 interface connector uses the DB-9 9-pole plug holder, the RS485 interface with the Smart terminal is DB-9 (hole), the keyboard interface with the keyboard RS485 using DB-9 (PIN).

232 and RS485 definition is the electrical characteristics, affecting the transmission of data on the line, RS232 and RS485 transceiver through the UART to be accessed by the CPU, so as long as the control of the UART, you can control the transmission of the serial port, and so-called programming is actually the UART programming, So RS232 a RS485 from the programmer's perspective is not visible. "Then you just say RS485 and RS232 programming no difference is over?" "The problem is, the actual total is more complex than the theory, there is an exception: RS232 with two lines to achieve full duplex, two lines each do each, do not affect each other, can be carried out at the same time; RS485 Although can be used four lines to achieve full duplex, but the actual application is relatively rare, more commonly used only two lines to achieve half Work, in this way, it involves the "receiving State" and "hair status" switch, which involves two cases: 1, the driver has been in half-duplex case of the acceptance switch, the driver will be based on your read or write action, automatically switch.          In this case, RS485 programming is completely indistinguishable from the RS232. 2, the driver does not have the automatic switch, at this time, in order to complete the switchover, must use the additional gpio to connect the RS485 transceiver module accepts the enable end, before accepts, sends the data, first to enable the end to set the position, causes it to be in the correct "receives" or "sends" the state.



Is "RS-485" equivalent to "half duplex"?
Answer: No, the RS-485 interface can be connected to half-duplex and full duplex two kinds of communication, half-duplex communication chip has sn75176,sn751276,sn75lbc184,max485,max1478,max3082,max1483, Full-duplex communication: sn75179,sn75180,max488-491,max1482, etc.

Second, the difference between RS232 and RS485:

I. Interference Resistance:

1: RS485 interface is a combination of balanced driver and differential receiver, anti-noise interference is good. 2. The RS232 interface uses a signal line and a signal return line to form a common form of transmission, this common transmission is prone to common mode interference, so anti-noise interference is weak.

Two. Transmission Distance:

The maximum transmission distance of the 1.rs485 interface is 1200 meters (9600bps) and can actually reach 3000 meters. 2. RS232 transmission distance is limited, the maximum transmission distance standard value is 50 meters, in fact, can only be used at about 15 meters.

Three Communication capability:

1.rs-485 interface on the bus is allowed to connect up to 128 transceivers, that is, multi-station capability, so that users can use a single RS-485 interface to easily set up a device network. 2.rs-232 only allow one-to-two communication.

Four. Transfer rate:

1. The transfer rate is low, and the baud rate is 20Kbps at asynchronous transmission. The maximum data transfer rate for 2.rs-485 is 10Mbps.

Five Signal line:

The 1.rs485 interface consists of a half-duplex network, typically requiring only two signal lines. 2.rs-232 Port generally uses only RXD, TXD, GND three lines, namely "Send Data", "Receive data" and "signal ground".

Six. Electrical level value:

1. The logic "1" is expressed as the voltage difference between the two lines is + (2-6) v, and the logic "0" is indicated by the voltage difference between the two lines-(2-6) v. 2. The voltage of any signal line in the rs-232-c is a negative logical relationship. That is: Logic "1", -15v; logic "0" +5-+15v. Noise tolerance is 2V. That is, the receiver is required to recognize a signal as low as +3v as the logic "0", high to 3 V signal as the logic "1". 3.rs232 interface high signal level, easy to damage the interface circuit chip, and because the TTL level is incompatible with the need to use a level conversion circuit can be connected with the TTL circuit. 4.rs485 interface signal level is lower than rs-232-c, it is not easy to damage the chip of the interface circuit, and the level is compatible with the TTL level, it is convenient to connect with the TTL circuit.

RS232 contact with RS485:

1. Can be connected via DB-9 connector. 2. The interface can be transmitted by shielded twisted pair cable. 3. All serial communication. 4. All modes of communication are full duplex. (typically 485 is half duplex)


Since some devices are 232 interfaces, there are 485 interfaces, if there is a device with a 232 interface to communicate with a 485 interface device, then a rs232/rs485 converter is required, 232 signal of 232 interface device is converted to 485 signal, and then the device communicates with 485 interface. If two 232-port devices are to communicate over a long distance, add two rs232/rs485 conversion circuitry.
The so-called "passive rs232/rs485 converter" used from the computer serial port to steal the power technology, and "active rs232/rs485 converter" in the circuit schematic diagram with the front of the similar, just the power supply part of the changes.


Pin assignment for RS232 and RS485

Table 1 pin assignment at the RS-232 end

Db9female (PIN)

RS-232C interface Signal

1

Protected land

2

Receive Data sin (RXD)

3

Send data Sout (TXD)

4

Data Terminal Preparation DTR

5

Signal Ground GND

6

Data Device Preparation DSR

7

Request to send RTS

8

Clear Send CTS

9

Bell Indicator R1

Table 2 pin assignment at the RS-485 end

Db9male (PIN)

Output signal

RS-485 Half-duplex wiring

1

t/r+

RS-485 (A +)

2

t/r-

RS-485 (b-)

3

Rxd+

Empty

4

rxd-

Empty

5

GND

Ground

6

Vcc

+ V Standby Power input

In table 1, because the transmission control signal of the monitoring computer is not used, only three interface lines are required, i.e. "Send data", "Receive data" and "signal ground". Table 2 in the t/r+, t/r-representative send and receive a +, B-,VCC on behalf of the standby power input, GND represents the public ground, points to point to multipoint, half-duplex communication two lines (t/r+, t/r-), the principle of "send/Receive +" to the other party's "Send/Receive +", "Send/Receive-" "Send/Receive- ", RS-485 half-duplex mode wiring will t/r+ (send/Receive +) connected to each other's A +, t/r-(send/Receive-) to each other's B-.



Is "RS-485" equivalent to "half duplex"?
Answer: No, the RS-485 interface can be connected to half-duplex and full duplex two kinds of communication, half-duplex communication chip has sn75176,sn751276,sn75lbc184,max485,max1478,max3082,max1483, The full duplex communication is: sn75179,sn75180,max488-491,max1482 and so on.



Third, the reference documents:
Http://www.360doc.com/content/13/1119/18/13253385_330564821.shtml
Http://www.360doc.com/content/11/0404/16/1317564_107153860.shtml (important, you can take a closer look)
Http://www.chinadmd.com/file/xoawuzuvowzx66r63iwrpuae_1.html

Basic knowledge of UART and RS232, RS485

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.