Design of serial communication between Kingview and single-chip multi-machine

Publisher:PeacefulSoulLatest update time:2011-12-12 Keywords:Kingview Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:Kingview Reference address:Design of serial communication between Kingview and single-chip multi-machine

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

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号