2284 views|0 replies

1140

Posts

0

Resources
The OP
 

Communication design between eView touch screen and 51 single chip microcomputer based on Modbus communication protocol [Copy link]

Modbus protocol has become the first choice of communication protocol in the current industrial field due to its openness, transparency, low cost and easy development.
  This paper introduces a communication method between eView touch screen and commonly used 51 single-chip microcomputer based on Modbus communication protocol. This method realizes Modbus communication through C51 programming, which is universal on 51 series single-chip microcomputers and has a certain reference role.
  In industrial control, it is often necessary to observe the operating status of the system or modify the operating parameters. The touch screen can display the operating parameters and operating status intuitively and vividly, and the system operating parameters can be directly modified through the touch screen screen, with good human-computer interaction. Single-chip microcomputers are widely used in the field of industrial control, and can form a good human-computer interaction environment with touch screens. For the
  touch screen to communicate with the single-chip microcomputer, it is necessary to write a corresponding communication program for the single-chip microcomputer according to the communication protocol adopted by the touch screen. Modbus protocol is a protocol launched by Modicon Corporation of the United States, which effectively supports communication between controllers and between controllers and other devices via networks (such as Ethernet). This paper takes STC89C51 single-chip microcomputer and eView touch screen of Human-Machine Electronics Co., Ltd. as examples to introduce the development process of its communication program.
  1 System Structure
  To achieve communication between the touch screen and the single-chip microcomputer, the main problem is to solve the communication protocol. This article uses the open Modbus communication protocol, with the touch screen as the master station and the single-chip microcomputer as the slave station. The eView touch screen itself supports the Modbus communication protocol. If the single-chip microcomputer also supports the Modbus protocol, communication can be carried out. The eView touch screen supports two communication interfaces, RS-232 and RS-485. In the field of industrial control, RS-485 has the advantages of high reliability, long transmission distance, and strong anti-interference ability. Therefore, in this system, the touch screen and the single-chip microcomputer communicate using RS-485 connection, and the transmission rate is set to 9600 kbps. RS-485 signal transmission is a half-duplex transmission mode. The single-chip microcomputer converts the 232 signal into a 485 signal through an RS-232/RS-485 passive converter and connects it to the eView touch screen. Figure 1 is the schematic diagram of the system.
  

  The single-chip control system uses the STC89C51 series single-chip microcomputer, which integrates the MAX810/STC810 dedicated reset circuit (the original external reset can continue to be retained and is compatible with the Intel 8051 pin). It has the characteristics of strong anti-interference ability, strong encryption, high anti-static (ESD), ultra-low power consumption, etc., and is inexpensive. In this system, the touch screen is the upper computer and the single-chip microcomputer is the lower computer.
  2 Modbus protocol
  2.1 Introduction to Modbus protocol
  Modbus protocol is a common language used in electronic controllers. Through this protocol, controllers can communicate with each other and with other devices via a network (such as Ethernet). It has become a universal industrial standard. Control devices produced by different manufacturers can be connected to an industrial network through it for centralized monitoring.
  The Modbus protocol defines a message structure that a controller can recognize and use, regardless of the network they communicate through. It describes the process of a controller requesting access to other devices. How to respond to requests from other devices, and how to detect and record errors; a common format for the message domain pattern and content is established.
  When communicating on a Modbus network, the protocol determines that each controller needs to know their device address, identify messages sent by address, and decide what action to take. If a response is required, the controller will generate feedback information and send it using the Modbus protocol. On other networks, messages containing the Modbus protocol are converted into frames or packet structures used on this network.
  2.2 Modbus RTU communication data transmission mode
  When the controller device communicates in RTU mode based on the Modbus protocol, each byte in the message contains 2 4-bit hexadecimal characters. The main advantage of this method is that more data can be transmitted than the ASCII method at the same baud rate.
  The encoding uses 8-bit binary, hexadecimal numbers 0 to 9 and A to F; each 8-bit field in the message is composed of 2 hexadecimal characters. The organizational structure is as follows:


  2.3 Modbus RTU message frame structure
  The Modbus RTU message frame structure is as follows:


  (1) Address code
  The address code is the first byte of the communication transmission. This section indicates that the slave with the address code set by the user will receive the information sent by the host. Each slave has a unique address code. Only slaves that match the address code can respond and return, and the response and return start with their own address code. The address code sent by the host indicates the address of the slave to be sent, while the address code sent by the slave indicates the address of the slave to be returned. Address 0 is used as a broadcast address so that all slave devices can recognize it.
  (2) Function code
  The function code is the second byte of the communication transmission. The Modbus communication protocol defines the possible code range as decimal 1 to 255. Of course, some codes are applicable to all controllers, some are only applicable to certain controllers, and some are reserved for future use. The host sends a request and tells the slave what action to perform through the function code; the slave responds to the request, and the function code sent by the slave is the same as the function code sent from the host, indicating that the slave has responded to the host to perform an operation. If the highest bit of the function code sent by the slave is 1, it means that the slave does not respond to the operation or the transmission is wrong. After the master device application receives the objection response, the typical processing is to resend the message. Table 1 lists some of the function codes supported by common Modbus.
 

  Take reading the coil status as an example. The master sends the command: [Device address] [Command number 01] [Starting register address high 8 bits] [Low 8 bits] [Number of registers to read high 8 bits] [Low 8 bits] [Low 8 bits of CRC check] [High 8 bits]. The slave responds: [Device address] [Command number 01] [Number of bytes returned] [Data 1] [Data 2]… [Data n] [Low 8 bits of CRC check] [High 8 bits].
  (3) Data area
  The data area varies depending on the function code. The data area contains what action the slave needs to perform, or the return information collected by the slave. This information can be actual values, set points, addresses sent by the host to the slave or sent by the slave to the host, etc. For example, if the function code tells the slave to read the value of the register, the data area must contain the starting address of the register to be read and the read length. For different slaves, the address and data information are different.
  (4) Error check code
  The host or slave can use the check code to determine whether the received information is wrong. The error detection field contains a 16-bit value (implemented by two 8-bit characters). The content of the error detection field is obtained by performing a "cyclic redundancy check" on the message content. The CRC field is attached to the end of the message, first the low byte and then the high byte, so the high byte of the CRC is the last byte of the message sent. The error check uses the CRC-16 check method.
  3 Software Programming
  The following is the software written in C5l, which mainly includes CRC check and terminal reception and baud rate setting. Due to limited space, other programs are omitted.
    

  

  4 Summary
  Since Modhus protocol has the characteristics of openness and transparency, and 51 series single-chip microcomputer technology is mature and has low development cost, the combination of the two will continue to be the first choice for various communication system designs. This design method has been applied to the communication design between touch screen and single-chip microcomputer, and has achieved good results. This method has a certain reference role in compiling similar communication software, and some programs can be directly transplanted.

This post is from RF/Wirelessly
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

快速回复 返回顶部 Return list