1 Introduction
With the increasing requirements of industrialization, the development of distributed systems and the need for communication between control equipment and monitoring equipment, monitoring systems designed by configuration software have gradually become popular. There are many configuration software now, such as KingView, MCGS, WinCC, etc. KingView software is based on Microsoft Windows XP, NT/2000 operating system. It has a friendly human-machine interface and powerful IO device port driving capability, and can communicate with various PLCs, intelligent instruments, intelligent modules, boards, inverters, etc. in real time. Since the use of PLC and configuration software communication in industrial sites that detect a large number of analog quantities is bound to increase product costs. However, the single-chip microcomputer has rich interfaces and can complete the same work in combination with A/D conversion modules, and the system is reliable and low-cost.
2 Serial communication method between KingView and MCU
At present, the communication between KingView and MCU is mostly completed through dynamic data exchange (DDE) or by developing communication drivers by yourself. DDE is a complete communication protocol on Windows platform, through which KingView exchanges data with other applications. But it is unreliable and non-real-time. Developing communication drivers by yourself will bring design difficulties, increase system development cycle, and is not feasible. KingView provides a special method for serial communication with MCU and multiple machines, which can meet most system requirements.
3 Hardware interface circuit between PC and microcontroller
Figure 1 shows the connection circuit between the upper PC and the lower microcontroller 80C51. Both the PC and the microcontroller have their own serial communication interface, but because the PC and the microcontrollers are not distributed in a centralized manner in the distributed system, RS-232 communication cannot be used, and RS-485 can only be used instead. RS-485 uses differential transmission signals, with a maximum transmission distance of 1 219 m. The maximum transmission rate is 10 Mb/s. It has a strong suppression capability for the interference of two signal lines A and B that appear at the same time. When the two lines are twisted together, the interference signals coupled by various distributed parameters of the communication can be evenly distributed to the two lines. Therefore, for the differential transmission line of RS-485, using twisted pair cables can obtain a stronger anti-interference capability. RS-485 uses two-wire and four-wire balanced transmission methods. The two-wire system can realize true multi-point two-way communication, but a resistor (about 120 Ω) needs to be connected to the transmission line.
Since the TTL electrical characteristics of the serial interface of the 80C51 series microcontroller STC89C52 do not match the electrical characteristics of RS-485, STC89C52 cannot be directly connected to RS-485 and requires electrical conversion. Here, Maxim's MAX485 is used, and Figure 2 is its interface circuit.
In Figure 2, RE and DE of MAX485 are controlled by P1.7 of STC89C52 microcontroller. Since MAX485 works in half-duplex mode, P1.7 controls its transmission and reception. When P1.7 is high, the driver is enabled and the receiver is in high impedance state, and data can be sent at this time; when P1.7 is low, the receiver is enabled and the driver is in high impedance state, and data is received at this time. In addition, since the COM port of the PC is a serial communication port based on RS-232, its electrical characteristics are inconsistent with RS-485, so level conversion is also required.
Figure 3 is the circuit for setting the address of the microcontroller. The lower 4 bits of the P1 port of the microcontroller STC89C52 are used to set the local address. Up to 16 addresses can be set through the combination of the 4-bit DIP switch. For example, when all 4-bit switches are disconnected, the corresponding local address is 11 11. The lower microcontroller needs to set its own address before starting to work, so that the lower microcontroller can obtain the local address during the power-on self-test. [page]
4 System communication protocol design
KingView provides a driver for hexadecimal data communication between the PC and the microcontroller serial port, and the communication protocol has been specified in the driver.
4.1 Communication parameters
Communication parameters include data bit, stop bit, baud rate, and check mode. Among them, data bit, stop bit, and baud rate are determined by the single-chip microcomputer. The settings in the KingView can be consistent with the single-chip microcomputer. For the check mode, refer to the "Data Transmission Format" section.
4.2 Data Transmission Format and Protocol Description
Format 1 KingView sends address request format (check bit is 1):
Format 2 MCU response address format (check bit is 0):
Format 3 KingView read data request format (check bit is 0):
Format 4 MCU response read data format (correct) (check bit is 0):
Format 5 MCU response read data format (error) (check bit is 0):
Format 6 KingView write data request format (check bit is 0):
Format 7 MCU response write data format (correct) (check bit is 0):
The specific description of the protocol is as follows:
ENQ (header): H05, inquiry, the start code of the request frame;
ACK (header): H06, confirmation, the start code of the ACK response frame;
NAK (header): H15, denial, the start code of the NAK response frame;
EOT (tail): H04, the end of the text, the end ASCII code of the request frame;
ETX (tail): H03, the end of the text, the end ASCII code of the response frame;
Data transmission: All data are in hexadecimal; [page]
Sta: device address, 1 byte, the KingView device address range is 0 to 255, this address is the address of the microcontroller, which is determined by the program in the microcontroller;
R: read flag, 1 byte (0x52);
W: write flag, 1 byte (0x57);
DataType: the data type to be exchanged, 1 byte. "1" represents byte, "2" represents word, and "3" represents floating point type;
DataNum: the number of read data, 1 byte;
DataAddr: data offset address, 2 bytes, low byte first, high byte second;
Data: the actual transmitted data, low byte first, high byte second;
DataLong: the number of bytes returned by the microcontroller, 2 bytes, low byte first, high byte second:
CRC: the XOR value of all bytes from the first byte to the CRC, 1 byte;
ErrorCode: error code, "0" represents a correct response, "1" represents a data type error, "2" represents a data range out of limit, and "3" represents an instruction that cannot be recognized.
5 MCU communication program flow design
Figure 4 is the KingView program flow, and Figure 5 is the MCU communication program flow. 80C51 series MCU multi-machine communication can be summarized as follows:
The SM2 of the host computer is 0, and the SM2 of all the slave computers is 1, so that only the address sent by the host computer is received;
when the host computer sends an address to the slave computer, the 9th data bit should be 1 to indicate that the slave computer receives this address;
when SM2=1, RB8=1 and RI=0, all the slave computers receive the address sent by the host computer, enter the corresponding interrupt service program, and compare it with the local address to confirm whether it is the addressed slave computer;
the addressed slave computer clears SM2 through instructions to receive the data sent by the host computer normally, and sends the received address back to the host computer for verification. The unaddressed slave computers keep SM2=1 and exit their respective interrupt service programs;
after completing the data communication between the host computer and the addressed slave computer, the addressed slave computer makes SM2=1, exits the interrupt service program, and waits for the next communication.
6 Conclusion
This system realizes real-time communication between Kingview software and multiple single-chip microcomputers and has been applied in actual projects. The application results show that this design method is simple and effective, has good real-time performance and low cost, and can be promoted and applied in control and monitoring systems.
Previous article:Development and application of single chip microcomputer control technology
Next article:Micro-power design of battery-powered equipment based on single-chip microcomputer platform
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Xingkong Board Python Programming Learning Main Control Board Review 4] Turtle Turtle Drawing
- What exactly is the problem?
- [EETALK]What are the applications of GaN in RF?
- Free application: 800MHz RISC-V high-performance domestic chip, Xianji HPM6750EVK2 is coming, OpenHarmony buff
- There are some things I don't understand about this circuit that I would like to ask?
- High frequency transformer air gap
- I have a question about static electricity.
- How to adjust the abnormal power output
- Matter and Developers - Connectivity Standards Alliance
- 【MPS Reply with Prizes】Learn the practical knowledge of electromagnetic interference (EMI), share and win prizes!