Understanding of UART, RS232, 485 communication

In fact, what this blog post wants to express is to make it clear what serial communication is.

First popularize the basic knowledge points of communication:

Types of data communication :serial communication, parallel communication. No matter what type of communication, no matter how complicated it is, it is derived from these two types.

It is composed of many transmission lines or channels, and each line can be transmitted one by one. These bits can be transmitted within a specified time, or multiple bits can be transmitted at the same time within a certain time; this is serial communication and parallel communication .

       Transmission direction of data communication :simplex, half-duplex, full-duplex. What are the characteristics of each of them? I have cited an example of a vehicle aisle, and I will explain it to you in a simple and easy to understand way.

    1. Simplex: Only one direction of communication can be carried out at any time, that is, one is fixed as the sending device and the other is fixed as the receiving device. Simplex is similar to a lane that allows only one direction to run. At any time, only one car is allowed to go in the same direction, and no reverse is allowed.

    2. Half-duplex: Data can be sent and received between two devices, but not at the same time. This image example is like a walkie-talkie. When you are speaking out, others can't send it to you at the same time. After you finish speaking, others will reply to you.

    3. Full duplex: At the same time, two devices can send and receive data at the same time. This is like a mobile phone call. While you are talking, the other party can interrupt and you can also hear.

      Data communication method : synchronous and asynchronous.

The difference between synchronization and asynchronous: First of all, there are concepts of synchronization and asynchronous in many places. Simply put, the sender and receiver work in the same clock cycle, which is called synchronization. The sender and receiver do not follow a unified clock cycle, and each Working according to its own clock cycle is called asynchronous.

In synchronous communication, the two parties work in a uniform tempo, so they cooperate well; generally, the sender is required to send information to the receiver while sending a clock signal, and the receiver arranges its own rhythm according to the clock signal sent to it by the sender. Synchronous communication is used when the frequency of information exchange between the communicating parties is fixed or when communicating frequently.
       Asynchronous communication is also called asynchronous notification. Asynchrony means that it can be done at any time, but how to distinguish the beginning, the action and the end? This requires that a start bit (start bit), data content, and end bit (stop bit) are inserted in a frame of data to distinguish it, and then a certain transmission frequency (baud rate) is needed to send the data. When the frequency of communication between the two parties is not fixed (sometimes send and receive once in 3ms, sometimes only once in 3 days) it is not suitable to use synchronous communication, but suitable for asynchronous communication. In asynchronous communication, the receiver does not have to care about the sender all the time. When the sender needs to send information, it will first give the receiver a start signal to start the message. After receiving the start signal, the receiver thinks that the following is valid information. Will begin to pay attention to receiving information until the end sign sent by the sender is received.

Serial communication is asynchronous, and the baud rate is very important at this time.

1. Understanding of UART

UART (Universal Asynchronous Receiver / Transmitter) that is Universal Asynchronous Receiver Transmitter , the English abbreviation is uart, the Chinese referred to the serial port , since it is a "device" Obviously, it is a device just to complete the hardware for a particular function, is between devices The key module for asynchronous communication. UART is responsible for processing the serial/parallel and parallel/serial conversion between the data bus and the serial port, and specifies the frame format (that is, 9600, N, 8, 1); the communication parties only need to use the same frame format and wave Special rate (this is the characteristic of asynchronous communication), can complete the communication process with only two signal lines (Rx and Tx) without sharing the clock signal, so it is also called asynchronous serial communication . In fact, the UART device is a sign of whether the entire circuit board supports serial communication.

Usually, serial communication consists of a start bit and multiple data bits, usually 8 bits or less. The transmission starts from the low bit of a byte, and the stop bit is transmitted after the transmission. This is a basic serial protocol . Of course Some free bits can also be inserted in this protocol, as well as parity bits. We can use a picture to express it vividly:

2. Understanding of RS232/485

1) RS-232 standard

RS-232 is a serial physical interface standard developed by the Electronic Industry Association (EIA). RS is the abbreviation of "Recommended Standard" in English, and 232 is the identification number. RS-232 is the regulation of electrical characteristics and physical characteristics. It only acts on the transmission path of data. It does not contain the way to process data. It needs to be explained that many people often mistake RS-232, RS-422, and RS-485 as communication protocols. This is very inappropriate. In fact, they are only a mechanical and electrical interface standard for UART communication (at most The physical layer in the network protocol).

The standard stipulates that a 25-pin DB-25 connector is used, the signal content of each pin of the connector is specified, and the level of various signals is specified. Later, the IBM PC simplified RS-232 into a DB-9 connector, which became the de facto standard today. The RS-232 port of industrial control generally only uses three lines RXD (2), TXD (3), and GND (5).

2) RS-485/ RS-422 standard

The RS-232 interface can realize point-to-point communication, but this way cannot realize the networking function. So, in order to solve this problem, a new standard RS-485 was produced. The RS-485 data signal adopts differential transmission mode, also called 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 sending driver A and B is +2~+6V, which is a logic state, and the negative level is -2~6V, which is another logic state. There is another signal ground C, and there is an "enable" end in RS-485, but it is available or not in RS-422.

The electrical performance of RS-422 is exactly the same as RS-485. The main difference is: RS-422 has 4 signal lines: two for sending and two for receiving. Since RS-422 is separate for receiving and sending, it can receive and send at the same time (full duplex), and because full duplex requires a separate channel for receiving and sending, RS-422 is suitable for communication between two stations. Star network and ring network cannot be used in bus network; RS-485 has only 2 signal lines, so it can only work in half-duplex mode, and is often used in bus network.

        In fact, RS232/485 is just the transmission method and channel of the UART data frame mentioned above. The straightforward point is how to transmit the 0 and 1 bits in the data frame through physical wiring. This involves a problem, how to represent 0 and 1 on different lines? Of course, we all know that they must be 0 and 1 expressed by level signals, so their difference is only the difference between the level of 0 and 1 or the difference in voltage, and how many volts represent the difference between 0 and 1. The data transmitted on the line is the same, but the form of expression is slightly different.

RS232/RS485 are two different electrical protocols, that is to say, it is the regulation of electrical and physical characteristics, which acts on the data transmission path, and it does not contain the processing method of the data. For example, the most notable feature is: RS232 uses 3-15v effective level, and UART, because there is no regulation on electrical characteristics, directly use the level used by the CPU, which is the so-called TTL level (may be 0~3.3V Between) . More specifically, the electrical characteristics also determine the connection method of the line . For example, RS232 requires that data be expressed by level. Therefore, the line is a single line, and two lines can be used to achieve the purpose of full duplex; while RS485 uses differential electrical Ping represents data. Therefore, two wires must be used to meet the basic requirements for data transmission. To achieve full duplex, 4 wires must be used. However, no matter whether RS232 or RS485 is used, they are relatively independent of UART. However, due to the difference in electrical characteristics, a dedicated device and UART must be connected to complete the normal flow of data between the line and the UART. In a sense, only current exists on the line. RS232/RS485 specifies the type of line and flow of these currents; in the UART, the current is interpreted and assembled into data, and becomes CPU can read and write directly.

Therefore, RS232/485 represents a level standard, but a level different from TTL.

3. Understanding of the agreement

Make up later. . . . .

Reference link:

1. What is the relationship between UART and RS232/RS485?

2. Talking about the bus communication mechanism (communication basics + serial port + I2C)

3. Detailed introduction and use of TTL, COMS, USB, 232, 422, 485 levels

The above links are worth learning and reference.

Guess you like

Origin blog.csdn.net/weixin_38293850/article/details/105875762