System module for analyzing ModBus RTU message sent by host and UART setting

By designing the acquisition circuit and microcontroller module in the communication connection between the inverter and the controller, and analyzing the UART and ModBus RTU parameters sent by the host, the problem of difficult parameter setting is solved, and rapid and accurate online and debugging efficiency is improved.

CN119087846APending Publication Date: 2024-12-06YOLICO ELECTRIC WUXI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411009716.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

During the communication connection between the inverter and the controller, the host communication parameter setting cannot be accurately obtained, resulting in low debugging efficiency and high trial and error costs. In particular, the combination of UART and ModBus RTU parameters is difficult to quickly determine.

Method used

A module including an acquisition circuit and a microcontroller was designed to intercept the communication data frames sent by the host through the acquisition circuit, and synchronous signal processing is performed using a square wave oscillation circuit. The microcontroller parses the UART and ModBus RTU parameters and quickly obtains baud rate, device address, etc. Key parameters to realize accurate analysis of host parameters.

Benefits of technology

It realizes the rapid and accurate analysis of ModBus RTU messages and UART settings sent by the host, reduces trial and error costs, improves debugging efficiency, and simplifies the linkage process between slaves and hosts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119087846A_ABST
    Figure CN119087846A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of field bus control, in particular to a system module for analyzing ModBus RTU (remote terminal unit) messages and UART (universal asynchronous receiver / transmitter) settings sent by a host, which can quickly and accurately analyze the settings so as to achieve quick online, reduce the trial and error cost and improve the debugging efficiency, and comprises an acquisition circuit and a single chip microcomputer, the acquisition circuit comprises a front-end protection circuit, a communication circuit, an isolation optocoupler circuit, a sampling hold circuit and a square wave oscillation circuit, the square wave oscillation circuit is used for generating a synchronizing signal, intercepting a communication data frame sent by a host, synchronously sampling the communication data frame by the sampling hold circuit and then outputting the communication data frame to an input port of the single chip microcomputer, the single chip microcomputer firstly analyzes UART parameters and then analyzes Modbus Rtu parameters, and the communication data frame is transmitted to the host. And finally, a ModBus RTU message and UART setting sent by the host are obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of field bus control, in particular to a system module for analyzing ModBus RTU messages sent by a host and UART settings. Background Art

[0002] The inverter and controller (such as PLC, industrial computer) are linked to each other through the communication bus, which is the mainstream application in the contemporary era. Among them, the ModBus Rtu communication protocol is more widely used. The inverter is a slave in the electric control system, and the protocol needs to be fully compatible with the controller protocol to operate normally. With the maturity of domestic inverter technology, localization is the trend, and the system replacement of domestic inverters has become a mainstream market behavior.

[0003] However, in the actual replacement process, especially the communication connection with the controller, it is often impossible to obtain the correct host communication parameter settings, and a lot of effort is spent in the trial and error process, and even failure ends. There are two main parts of communication parameter settings; including the underlying UART and the protocol Modbus Rtu. UART is a data frame format, mainly including four important parameters such as baud rate, data length, parity check, and the number of stop bits; ModBus Rtu mainly involves applications such as slave address, function code and parameter address, data, etc.

[0004] When the host cannot obtain these communication parameter settings, the slave can only guess manually, from the combination of the four UART parameters to the Modbus RTU instruction set, resulting in low debugging efficiency and high trial and error costs. Summary of the invention

[0005] In order to solve the above technical problems, the present invention provides a module that can quickly analyze the ModBus RTU message and UART settings sent by the host, which can quickly and accurately parse out the settings to achieve rapid online connection, reduce the cost of trial and error, and improve debugging efficiency.

[0006] The technical scheme is as follows: a module capable of quickly analyzing ModBus RTU messages and UART settings sent by a host, characterized in that it comprises an acquisition circuit and a single-chip microcomputer, the acquisition circuit comprises a front-end protection circuit, a communication circuit, an isolation optical coupling circuit, a sampling and holding circuit, and a square wave oscillation circuit, the square wave oscillation circuit is used as a synchronization signal, the communication data frame sent by the host is intercepted, and the sampling and holding circuit performs synchronous sampling and then outputs it to the input port of the single-chip microcomputer, the single-chip microcomputer first parses the UART parameters, and then parses the Modbus RTU parameters, and finally obtains the ModBus RTU messages and UART settings sent by the host.

[0007] It is further characterized in that parsing the UART parameters comprises the following steps: (1) The data frame type is inferred from the total length of the data frame and the multiple relationship; (2) Calculate the effective length of the data frame based on the start bit and stop bit, and if there is a parity check code, then calculate it backwards; (3) Obtain four key parameters of the data frame: baud rate, data length, stop bit length, and whether or not there is a parity check code; Parsing Modbus RTU parameters includes the following steps: (1) Obtain device address and data address; (2) After setting the device address value to the Modbus Rtu address of the slave, the master-slave linkage is completed. If the data addresses of the master and slave are incompatible, modify the data address of the slave, or connect an address converter in the middle to make the data address of the slave fully compatible with the host; The front-end protection circuit includes a common-mode inductor L6, wherein pin 1 of the common-mode inductor L6 is connected to one end of a resistor R29 and one end of a varistor SA and serves as a host signal input terminal, pin 2 is connected to one end of a resistor R30 and the other end of the varistor SA and serves as another host signal input terminal, pin 3 of the common-mode inductor L6 is connected to the cathode of a voltage regulator tube ZD1, one end of a resistor R26, the other end of the resistor R30, and pin 6 of a communication chip IC3 in the communication circuit, and pin 4 of the common-mode inductor L6 is connected to the cathode of a voltage regulator tube ZD2, one end of a resistor R25, and the other end of the varistor SA. The other end of the resistor R29 and the 7th pin of the communication chip IC3 in the communication circuit, the other end of the resistor R25 and the 5th pin of the communication chip IC3 are connected to the IG12V power supply, the other end of the resistor R26 and the 8th pin of the communication chip IC3 are connected to the IP5V power supply, the isolated optical coupler circuit includes an optical coupler PC1, an optical coupler PC2, and an optical coupler PC3, the 4th pin of the optical coupler PC1 is connected to the IP5V power supply, the 3rd pin is connected to the 2nd and 3rd pins of the communication chip IC3 and one end of the resistor R24, the other end of the resistor R24 ​​is connected to the IG12V power supply, the Pin 4 of the optocoupler PC2 is connected to the IG12V power supply, pin 5 is connected to one end of the resistor R22 and pin 4 of the communication chip IC3, and pin 6 is connected to the other end of the resistor R22 and the IP5V power supply. Pin 1 of the optocoupler PC3 is connected to the IP5V power supply through the resistor R23, pin 2 is suspended, and pin 3 is connected to pin 1 of the communication chip IC3. Pin 1 of the optocoupler PC1 is connected to one end of the resistor R19, and pin 2 is connected to the sample-and-hold circuit. Pin 1 of the optocoupler PC2 is connected to one end of the resistor R16, pin 2 is suspended, and pin 3 is connected to the sample-and-hold circuit. The optocoupler PC3 Pin 4 is grounded, pin 5 is connected to one end of resistor R15 and one end of resistor R20, the other end of resistor R16, the other end of resistor R19, the other end of resistor R20, and pin 6 of optocoupler PC3 are all connected to DVCC, the other end of resistor R15 is connected to the sampling and holding circuit, the sampling and holding circuit includes a first register and a second register, the square wave oscillation circuit includes a square wave generator, the 3-pin output end of the square wave generator is connected to the SCK pins of the first register and the second register, and the SDK pin of the first register is connected to the isolation optocoupler circuit.

[0008] After adopting the present invention, the host UART setting can be quickly performed by intercepting the data frame of the host, including four key parameters such as baud rate, parity check code, stop bit, data length, etc., and the host ModBus Rtu message content can be analyzed, including relevant parameters such as device address and data address, so as to replace the original slave debugging method and replace the original blind guessing trial and error, effectively improve the system debugging efficiency and reduce the trial and error cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] Figure 1 It is the principle diagram of the present invention; Figure 2 is a circuit diagram of the present invention; Figure 3 It is a flow chart of the analysis process in the single chip microcomputer of the present invention; Figure 4 This is the schematic diagram of the square wave oscillation circuit; Figure 5 Schematic diagram for calculating baud rate for square wave generator; Figure 6 This is a schematic diagram of the UART standard format; Figure 7 This is an example of a data frame at 9600 baud rate; Figure 8 It is the ModBus RTU message model; Fig. 9 Common function codes for MoDBus RTU; Fig.10 Read 03 function code description for ModBus RTU. DETAILED DESCRIPTION

[0010] See Figure 1 and Figure 3 As shown, a module capable of quickly analyzing ModBus RTU messages and UART settings sent by a host computer includes an acquisition circuit and a single-chip microcomputer. The acquisition circuit includes a front-end protection circuit, a communication circuit, an isolation optocoupler circuit, a sampling and holding circuit, and a square wave oscillation circuit. The square wave oscillation circuit is used as a synchronization signal to intercept the communication data frame sent by the host computer, and the sampling and holding circuit performs synchronous sampling and outputs it to the input port of the single-chip microcomputer. The square wave oscillation circuit uses a high-frequency oscillation square wave generator IC 7555 to output a square wave signal with a duty cycle of 1MZ@50% and an amplitude of 0-5V. The frequency is 1Mh and the period is 1us, which can meet the highest baud rate of 115.2KHz. The rising edge of the square wave is used to count the data frame. From the rise and fall of the data frame, the bit rate (bps) of the data frame can be calculated. The schematic diagram of the square wave generator calculating the bit rate is shown in FIG. Figure 5 As shown in the figure, the design period of the square wave generator is Ts / perpulse. By finding the data bit of the most data frame sent by the host, the bit rate from the host can be calculated = (number of times * Ts); for example Figure 5 As shown, DH2 and DL2 are one data bit (1 bit), so the 1bit time of the data frame is (number of times*Ts). By using a square wave generator to calculate the time taken for 1 bit of the data frame, the bit rate (bit / persec) of the data can be calculated. The bit rate refers to the number of bits transmitted per second, and the unit is bps (bitper second).

[0011] The microcontroller first parses the UART parameters, then parses the Modbus RTU parameters, and finally obtains the ModBusRTU message and UART settings sent by the host.

[0012] See Figure 2 , Figure 4 , Figure 5 As shown, the acquisition circuit includes a front-end protection circuit, a communication circuit, an isolation optocoupler circuit, and a sampling and holding circuit connected in sequence. The sampling and holding circuit is connected to the square wave oscillation circuit and the single-chip microcomputer chip. The front-end protection circuit includes a common-mode inductor L6. Pin 1 of the common-mode inductor L6 is connected to one end of the resistor R29 and one end of the varistor SA, and pin 2 is connected to one end of the resistor R30 and the other end of the varistor SA. Pin 3 of the common-mode inductor L6 is connected to the cathode of the voltage-stabilizing tube ZD1, one end of the resistor R26, the other end of the resistor R30, and pin 6 of the communication chip IC3 in the communication circuit. Pin 4 of the common-mode inductor L6 is connected to the voltage-stabilizing tube ZD 2, one end of resistor R25, the other end of resistor R29, and the 7th pin of the communication chip IC3 in the communication circuit. The communication chip IC3 adopts the SN75176BDR model, which can realize two-way data communication. The other end of resistor R25 and the 5th pin of the communication chip IC3 are connected to the IG12V power supply, and the other end of resistor R26 and the 8th pin of the communication chip IC3 are connected to the IP5V power supply. The isolation optocoupler circuit includes optocoupler PC1 (model TLP181), optocoupler PC2 (model TLP719), and optocoupler PC3 (model TLP719). The 4th pin of optocoupler PC1 is connected to IP5V power supply, pin 3 is connected to pins 2 and 3 of communication chip IC3 and one end of resistor R24, the other end of resistor R24 ​​is connected to IG12V power supply, pin 4 of optocoupler PC2 is connected to IG12V power supply, pin 5 is connected to one end of resistor R22 and pin 4 of communication chip IC3, pin 6 is connected to the other end of resistor R22 and IP5V power supply, pin 1 of optocoupler PC3 is connected to IP5V power supply through resistor R23, pin 2 is suspended, pin 3 is connected to pin 1 of communication chip IC3, pin 1 of optocoupler PC1 is connected to one end of resistor R19, pin 2 is connected to sample and hold circuit, pin 1 of optocoupler PC2 is connected to resistor One end of R16 and pin 2 are suspended, and pin 3 is connected to the sampling and holding circuit. Pin 4 of the optocoupler PC3 is grounded, and pin 5 is connected to one end of resistor R15 and one end of resistor R20. The other end of resistor R16, the other end of resistor R19, the other end of resistor R20, and pin 6 of the optocoupler PC3 are all connected to DVCC. The other end of resistor R15 is connected to the sampling and holding circuit. The sampling and holding circuit includes a first register and a second register. The square wave oscillation circuit includes a square wave generator. The output end of pin 3 of the square wave generator is connected to the SCK pins of the first register and the second register, and the SDK pin of the first register is connected to the isolation optocoupler circuit. The power supply circuit is implemented by two voltage regulators of model UPC78L05T, and the interface CN2 is used to connect to the host.

[0013] Parsing UART parameters consists of the following steps: (1) The data frame type is inferred from the total length of the data frame and the multiple relationship; (2) Calculate the effective length of the data frame based on the start bit and stop bit, and if there is a parity check code, then calculate it backwards; (3) Obtain four key parameters of the data frame: baud rate, data length, stop bit length, and whether or not there is a parity check code; Parsing Modbus RTU parameters includes the following steps: (1) Obtain device address and data address; (2) After setting the device address value to the Modbus Rtu address of the slave, the master-slave linkage is completed. If the data addresses of the master and slave are incompatible, modify the data address of the slave, or connect an address converter in the middle to make the data address of the slave fully compatible with the host; The following are some detailed examples: UART protocol, including the content definition of data frame; including start bit, data length, parity check, stop bit, the format standard diagram is as follows Figure 6 For example, the most commonly used 9600 8N1 (9600 baud rate, 8 data bits, no parity bit, 1 stop bit) is as shown in Figure 7 As shown. Conventional settings include: start bit (low level) 1 bit, data length fixed at 8 bits (ModbusRtu fixed at 8 bits, ModbusASCII is 7 bits, which is not the current mainstream), parity check 0-1 bit, stop bit 1-2 bits, depending on the user's setting method. Therefore, the combination of data frame length is generally classified into the following four categories; The present invention proposes a parsing method: first, the total number of data frames is accumulated, and when analyzing the multiples of 10 / 11 / 12, for example, if the total length is 66 bits, it can be inferred that a valid data frame belongs to 11 bits; if the total length is 80 bits, it is inferred to belong to the 10 bits category.

[0014] Then, the start bit is always at a low level L and the stop bit is always at a high level H for judgment. It is worth noting that the stop bit may be set by the user as 2 bits, which must be included in the judgment combination. For example, the total length is 60, or it may be 10 or 12. If the start bit is always at a low level, the data frame is always at a low level every 10 or 12 bits, and the effective length of the data frame can be quickly identified as 10 or 12 bits; if the stop bit is always at a high level, the level is judged by taking the value of the mantissa of every 10 / 11 / 12 bits of the data frame, but it is necessary to consider whether it is 1 or 2 bits high.

[0015] Finally, the parity check code is used to reversely identify and select the setting method. The parity check code method is as follows: Odd parity (ODD): The number of bits that are 1 during the transmission of each byte is an odd number (the number of parity bits is adjusted).

[0016] Even parity (EVEN): The number of bits that are 1 during the transmission of each byte is an even number (the number of parity bits is adjusted).

[0017] The valid content of the data frame is defined as follows Figure 6 and Figure 7 , is the most commonly used data frame format; when the effective length of the data frame is clear, the baud rate can also be determined After parsing out the bit rate (bps) and effective data frame length, the baud rate (Baud rate) setting value can be obtained by the formula of baud rate (BR) = bit rate * number of binary bits corresponding to unit modulation. Through the above method, all parameter settings of the communication format UART data frame can be parsed, including four key parameters such as baud rate (BR), parity check (none / odd / even), stop bit (1 / 2 bit), and data length (7 / 8 bits).

[0018] Parse the UART bottom user settings, and then parse the message content sent by the host. The most important thing about ModBus Rtu user settings is that the device address of the message sent by the host must be consistent with that of the slave; when the correct content of the message is received, the first 8-bit data frame content is the device address, such as ( Figure 7 and Figure 8 ). After setting the device address value to the Modbus Rtu address of the slave, the master-slave linkage function can be completed. If the data addresses of the master and slave are incompatible, there are many solutions: modify the data address of the slave, especially the one used in the communication process, or connect an address converter in the middle to make the data address of the slave fully compatible with the host.

[0019] The message model of ModBus Rtu is as follows Figure 8 As mentioned above, a message is a frame of data, and a data frame is a message, which refers to a complete string of instruction data, just like Figure 8 For the slave, the most important thing is the device address, which is the address that the slave needs to set. It must match the address of the message so that the master and slave can complete the online function. Under the condition of UART setting compatibility, the device address can be easily parsed. There are 8 common function codes of Modbus Rtu, such as Fig. 9 But according to experience, there are two most commonly used functions, one is to read the slave, and the other is to write to the master. The function code for reading is 03, and the function code for writing is 06.

[0020] This article will use the 03 read function as an analytical explanation for the present invention; assuming that the host sends a data frame such as Fig.10 As shown; The address is hexadecimal 0x01. The inverter needs to correct the Modbus Rtu address to 0x01. The data address is 2 bytes, with high and low 0x00 0x01 respectively. If the data address function sent by the host is the same as the original design of the slave, it can be used directly. If it is different and the slave has the ability to modify it, modify the slave data address. If it cannot be modified, an address converter is required. For example, the 0x00 0x01 data address function sent by the host is to read the running current of the slave, but the running current data address of the slave is defined as 0x00 0x06. Using an address converter can easily correct this problem.

[0021] In the present invention, when the system uses a master and slave bus to communicate with each other and uses the Modbus Rtu protocol, but the slave cannot know the UART setting of the host and the Modbus Rtu message format, the module of the present invention can intercept the data frame of the host and quickly set the host UART, including four key parameters such as baud rate, parity check code, stop bit, and data length, and can also parse the content of the host ModBus Rtu message, including relevant parameters such as device address and data address. It can improve the system debugging efficiency and reduce the trial and error cost.

Claims

1. A module that can quickly analyze ModBus RTU messages and UART settings sent by a host, characterized in that: It includes an acquisition circuit and a single-chip microcomputer. The acquisition circuit includes a front-end protection circuit, a communication circuit, an isolation optocoupler circuit, a sampling and holding circuit, and a square wave oscillation circuit. The square wave oscillation circuit is used as a synchronization signal to intercept the communication data frame sent by the host. The sampling and holding circuit performs synchronous sampling and then outputs it to the input port of the single-chip microcomputer. The single-chip microcomputer first parses the UART parameters and then parses the Modbus Rtu parameters, and finally obtains the ModBus RTU message and UART settings sent by the host.

2. A module capable of quickly analyzing ModBus RTU messages and UART settings sent by a host according to claim 1, characterized in that: Parsing UART parameters consists of the following steps: (1) The data frame type is inferred from the total length of the data frame and the multiple relationship; (2) Calculate the effective length of the data frame based on the start bit and stop bit, and if there is a parity check code, then calculate it backwards; (3) Obtain four key parameters of the data frame: baud rate, data length, stop bit length, and whether or not there is a parity check code; Parsing Modbus RTU parameters includes the following steps: (1) Obtain device address and data address; (2) After setting the device address value to the Modbus RTU address of the slave, the master-slave linkage is completed. If the data addresses of the master and slave are incompatible, modify the data address of the slave, or connect an address converter in the middle to make the data address of the slave fully compatible with the host.

3. A module capable of quickly analyzing ModBus RTU messages and UART settings sent by a host according to claim 1, characterized in that: The front-end protection circuit includes a common-mode inductor L6, wherein pin 1 of the common-mode inductor L6 is connected to one end of a resistor R29 and one end of a varistor SA and serves as a host signal input terminal, pin 2 is connected to one end of a resistor R30 and the other end of the varistor SA and serves as another host signal input terminal, pin 3 of the common-mode inductor L6 is connected to the cathode of a voltage regulator tube ZD1, one end of a resistor R26, the other end of the resistor R30, and pin 6 of a communication chip IC3 in the communication circuit, and pin 4 of the common-mode inductor L6 is connected to the cathode of a voltage regulator tube ZD2, one end of a resistor R25, and the other end of the varistor SA. The other end of the resistor R29 and the 7th pin of the communication chip IC3 in the communication circuit, the other end of the resistor R25 and the 5th pin of the communication chip IC3 are connected to the IG12V power supply, the other end of the resistor R26 and the 8th pin of the communication chip IC3 are connected to the IP5V power supply, the isolated optical coupler circuit includes an optical coupler PC1, an optical coupler PC2, and an optical coupler PC3, the 4th pin of the optical coupler PC1 is connected to the IP5V power supply, the 3rd pin is connected to the 2nd and 3rd pins of the communication chip IC3 and one end of the resistor R24, the other end of the resistor R24 ​​is connected to the IG12V power supply, the Pin 4 of the optocoupler PC2 is connected to the IG12V power supply, pin 5 is connected to one end of the resistor R22 and pin 4 of the communication chip IC3, and pin 6 is connected to the other end of the resistor R22 and the IP5V power supply. Pin 1 of the optocoupler PC3 is connected to the IP5V power supply through the resistor R23, pin 2 is suspended, and pin 3 is connected to pin 1 of the communication chip IC3. Pin 1 of the optocoupler PC1 is connected to one end of the resistor R19, and pin 2 is connected to the sample-and-hold circuit. Pin 1 of the optocoupler PC2 is connected to one end of the resistor R16, pin 2 is suspended, and pin 3 is connected to the sample-and-hold circuit. The optocoupler PC3 Pin 4 is grounded, pin 5 is connected to one end of resistor R15 and one end of resistor R20, the other end of resistor R16, the other end of resistor R19, the other end of resistor R20, and pin 6 of optocoupler PC3 are all connected to DVCC, the other end of resistor R15 is connected to the sampling and holding circuit, the sampling and holding circuit includes a first register and a second register, the square wave oscillation circuit includes a square wave generator, the 3-pin output end of the square wave generator is connected to the SCK pins of the first register and the second register, and the SDK pin of the first register is connected to the isolation optocoupler circuit.