Application of RS232 serial port communication in microcontroller communication

Background introduction

In control systems with more complex functions, the host computer is an industrial computer and the slave computer is a single-chip microcomputer. In these applications, the single-chip computer faces the bottom layer of the controlled object, and further collection and analysis of data are completed by using a PC. Data exchange needs to be carried out between the microcontroller and the PC. In the configuration of the PC, there are one or more RS232 serial ports, which are responsible for data exchange. The RS232 standard represents the American Electronics Industry Association, 232 is the identification number, C Indicates the latest modification of RS232. The RS232C standard interface has 25 lines, which are status line, contact line, data line and ground line. This article analyzes the application of RS232 serial communication in communication between PC and microcontroller.

Application of RS232 serial port communication in microcontroller communication

RS232 serial communication concept

The concept of serial communication is very simple. It can be equipped on any personal computer. It is a standard interface. The most common types include DB-9 and DB-25. There will be two RS232 interfaces on the computer, and parallel communication. Compared with the speed, the sending and receiving speed of serial communication is slower, but it can send and receive at the same time, and long-distance communication can also be achieved.

RS232 serial communication principle

RS232 serial communication is mainly transmitted through ASCII codes, and the ground wire is used to complete the corresponding reception and transmission. The serial communication end transmits on one line and can then receive on another line. Some of the more important parameters include:

1) Baud rate. It can reflect the speed of communication. The baud rate is the same as the clock cycle. However, it is worth mentioning that the baud rate is inversely proportional to the distance. Only close instruments require a baud rate. 2) Data bits. This parameter can reflect the data in communication. The general standards are 5, 7, and 8 bits. The standard value should be selected depending on what kind of information is sent. The standard ASCII code is 7 or 8 bits. The last bit of a single packet is the stop bit. The data is transmitted through the transmission line during timing, so the devices have different clocks. During the communication process, the data between the devices The transmission is asynchronous, so the difference is relatively small. At this time, stop bits can be used to resolve the asynchrony between devices. Stop bits can also be used to express the end of the transmission. The more stop bits, the better. It should be increased. Appropriate number of bits to ensure data transfer rate.

3) Parity bit. This parameter can check the correctness and error of serial communication. The main methods include even, odd, high and low. When performing parity check, the last bit of the data is the check bit. For the device, it is important to know the meaning of one bit. The status can determine whether the data transmission is interfered by other devices.

Serial communication RS232C standard

With the continuous advancement of science and technology, communication equipment is used more widely in life. There are many serial communication interface standards, all of which are based on the RS232 interface standard. The earliest RS232 standard was the United States in the 1960s. Promulgated by the company, this standard has certain requirements for the transmission rate, and the standard has certain instructions for the related equipment of the serial communication interface. At present, this interface has been widely used. The regulations for device characteristics, logic levels and signal line functions are: on RTS, CTS, DTR, DSR and other control lines, if it is 3V-15V, it means the signal is valid; if it is -3V to -15V, it means the signal is valid. If it is disconnected, the signal is invalid. There is no clear indication in RS232C, but there are various types of connectors. The DB-9 connector does not support the 20mA current loop interface and can only be connected to COM1 and COM2 interfaces.

Interface circuit between RS232 and microcontroller

There are obvious differences between the microcontroller serial port signal and RS232, so conversion is required to ensure level consistency. The most widely used converter is MAX232. Its main power supply source is 5V power supply, which can be easily obtained. After configuring the source, the signal becomes TXD after conversion, which can be directly connected to the PC. After research on the composition, it is mainly composed of three parts.

The charge pump circuit includes 4 capacitors and pins 1, 2, 3, 4, 5, and 6, which can ensure the continuous operation of the level. The data conversion channel includes pins 7 to 14. The above part from pins 11 to 14 is the first data channel, and from pins 7 to 10 is the second data channel. It can be input from pin 10, and output from pin 14 after conversion. Of course There are also many shortcomings in RS232, such as insufficient transmission distance. The transmission distance may be only 50m during operation, so it cannot meet the corresponding requirements.

The maximum transmission rate is 19200B, so the rate is significantly reduced. The form of transmission is mainly common ground transmission. In this process, it is easily interfered by other factors, thus affecting the effect.

Resumir:

In summary, the application of RS232 serial communication in the communication between PC and microcontroller is mainly analyzed. It can be seen that RS232 serial communication plays a very important role in the transmission between microcontroller and PC. It is the main method of information transmission. The hub can complete the transmission of data. Of course, there are also many shortcomings. Researchers need more analysis and practice to find solutions and provide greater help for future work in this area.

Contactar-nos