[Embedded] Detailed explanation of commonly used serial port protocols and conversion chips

0 Preface

  I have been wanting to study the USB protocol recently, and I happened to see some comments saying that I was confused about how to choose a USB-to-serial port module. In fact, I have always wanted to write a summary article about the serial port, and take this opportunity to improve it.

1 The composition of a communication protocol

  The so-called communication protocol, as the name suggests, is essentially an agreement, that is, an agreement. Everyone agrees on some communication standards, so that everyone can design and produce products according to this standard, and avoid the situation that product A is not compatible with product B.
  Then think about it first, what does a communication protocol need to stipulate?
  Generally speaking, it mainly includes three aspects:

  • The physical attributes  are mainly the external characteristics of the agreed plug or interface. Including what the plug looks like (physical shape), how many pins it has (pin definitions), etc.
  • Logical attributes  Logical attributes mainly agree on the timing of data transmission by this protocol. Because in the actual process of transmitting data, the data that needs to be transmitted is not directly transmitted in sequence. In this way, the receiving end does not know where to start receiving, and the data transmission will be chaotic. Therefore, the data is often divided into small pieces and then added Some fixed characters are composed of "a frame" and then transmitted. The receiving end also analyzes it according to the agreed frame format. In this way, data transmission can be carried out in an orderly manner.
  • Electrical properties   In common serial data transmission protocols, digital signals are transmitted, that is, 0 and 1 are used to represent the data that needs to be transmitted. Therefore, it is necessary to clarify how much voltage represents 0 and how much voltage represents 1.

The following content will also be developed according to the above ideas.

Finally, let’s briefly explain the concepts of some basic nouns:

  • Simplex : means that information transmission is one-way, only from A to B, not B to A.
  • Duplex : Information transmission is bidirectional, and AB can exchange information
  • Half-duplex : First of all, information transmission is bidirectional, but it cannot be done at the same time, that is, either A is transmitting to B, or B is transmitting to A, and both cannot be done at the same time.
  • Full duplex : Not only is information transmission bidirectional, it can also occur simultaneously.

2 Explanation of commonly used protocol terms

2.1 UART

  For students who play with microcontrollers, UART may be the earliest serial communication protocol that they are exposed to. Basically every microcontroller has two pins, TXD and RXD. This is the so-called Universal A synchronous Receiver / T ransmitter , asynchronous Serial communication.

  • Physical attributes : There are generally no requirements for the interface. You can customize it according to your own needs, but generally there are three wires: RXD, TXD, GND, and sometimes the power signal VCC is added.
  • Logical attributes : that is, the timing of data transmission. This may be the information we are most concerned about. It is also the main content of code writing: setting the baud rate, setting several data bits, whether there is parity check, etc., which is the so-called configuring the serial port.
  • Electrical properties : Use positive logic levels, that is, 5V/3.3V is 1; 0V is 0. This is the so-called TTL level, so generally speaking, the microcontroller serial port is also called TTL .

    In fact, most microcontrollers now use CMOS circuits, and the level tolerance is larger than TTL. However, because TTL appeared earlier, this level is still called TTL level.

Summary :
  UART does not specify the specific style of the interface, but only the pins, so it is more flexible in actual use. However, the level of the pin should be consistent with the power supply of the microcontroller, and attention should be paid to distinguishing between 3.3V and 5V. UART is a basic peripheral in a microcontroller, generally called a serial port. Communication between the microcontroller and the host computer can be achieved through the USB to TTL module.

2.2 RS-232

  RS-232 is actually an earlier and more widely used standard. Developed in 1970 by the Electronic Industries Association (EIA) in conjunction with a number of companies, the latest standard is RS232C (preceded by A and B). The so-called RS stands for Recommended Standard, and 232 is the identification number.

  • Physical attributes : RS232 specifies 25 wires, but in fact only 9 wires are commonly used (the other 16 wires include: ① 9 wires for current loop signals, few devices currently use these pins; ② 6 empty pins; ③ One protection Ground signal), which is why many RS232 interfaces are currently DB9, and DB25 plugs are rarely seen. The DB9 plug is shown in the picture below.
    Insert image description here
    The shape is similar to the VGA interface, but it only has 9 pins. The definitions of these 9 pins are as follows
abbreviation DTE25 core (male) DCE25 core (mother) DTE9 core (male) DCE9 core (mother) Signal function explanation
TXD 2 3 3 2 Send dataTransmit Data
RXD 3 2 2 3 Receive DataReceive Data
GND 7 7 5 5 Signal Ground
RTS 4 5 7 8 Require to Send
CTS 5 4 8 7 Clear requestClear to Send
DSR 6 20 6 4 Data Set ReadyData Set Ready
DCD 8 8 1 1 Receive line signal detectionData Carry Detected
DTR 20 6 4 6 Data Terminal ReadyData Terminal Ready
RI 22 22 9 9 Ringing indication

Among them, the first three lines are necessary lines, and the last six lines are actually flow control signals , which may not necessarily be used in actual use.

  • Logical attributes : It is worth mentioning that the timing of RS232 is actually the same as the UART mentioned above . The baud rate, data bits, check bits, stop bits, etc. also need to be set. However, it should be noted that the RS232 baud rate setting generally does not exceed 19200, because the upper limit of RS232 transmission is 20kbps.
  • Electrical properties : RS-232 uses negative logic levels , logic 1: -15V ~ -3V logic 0: +3V ~ +15V

Summary
  RS-232 is a full-duplex communication method. The timing is the same as UART, but the electrical properties are different. In addition, it can only achieve single-point communication, and the maximum communication rate is 20kbps and the maximum communication distance is 15m.

2.3 RS-485

  • Physical properties : RS-485 is transmitted through differential lines, so it generally requires two wires (plus a reference ground wire at most). Generally, twisted pairs are used, which can reduce interference as much as possible. Therefore, its transmission distance is longer, up to 4000 feet (about 1219 meters) , and the maximum transmission rate can reach 10Mbps (within 40 inches, about 12.2 meters)
  • Logic attributes : Since it is a differential signal line, it depends on the voltage difference between the two pins to determine whether it is a logic 0 or a logic 1.
  • Electrical properties : One of these two wires is A and one is B. The voltage on these two wires is required to be -7 ~ +12V. The sending end is required to provide a differential voltage of at least 1.5V, and the receiving end requires two wires. The voltage difference on the line is at least 200mV. When the voltage difference on line AB is ≥200mV, it is recognized as logic 1; when the voltage difference on line AB is <200mV, it is recognized as logic 0.

Summary
  Compared with the single-point communication of RS-232, RS-485 supports bus communication, and a maximum of 32 devices can be mounted on the bus (this number seems to be related to the bus impedance). RS-485 is a half-duplex communication protocol.

2.4 RS-422

  RS-422 is actually two sets of 485, one pair transmitting and one receiving pair, so 4 wires are needed to achieve full-duplex communication. But in fact, RS-422 is based on RS-232, which is earlier than RS-485. Although both 422 and 485 are differential signal transmission, their electrical characteristics are different from 485.
  RS-422 also supports mounting multiple devices on the bus, but not as many as 485. It only supports 10 devices. The maximum transmission distance and maximum transmission rate are the same as RS485.

2.5 Comparison

Insert image description here

Image source link

3 commonly used chips

  Commonly used chips for USB to serial port include CH340 , CP2102 , FT232 , and PL2303 . These can be used directly. For specific usage, it is recommended to refer to the official manual, mainly to see the example circuit usage.

  What needs to be noted about MAX232 is that its function is level conversion, that is, converting TTL levels and RS-232 levels to each other. Therefore, it is generally necessary to connect a USB to serial port protocol to communicate with the computer USB.

Guess you like

Origin blog.csdn.net/ZHOU_YONG915/article/details/133618065