A system for fast response to modbus protocol
By introducing independent signal lines and GPIO interrupt mechanisms into the Modbus protocol and eliminating the T3.5 time interval, the problem of low communication efficiency in the Modbus protocol is solved, resulting in faster response speed and a simplified communication process.
Patent Information
- Application Number
- CN202410251155.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-06
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2044-03-06
AI Technical Summary
The existence of the T3.5 interval in the Modbus protocol leads to low bus communication efficiency, especially in the case of multiple slave devices, and the message reception and acknowledgment mechanism is complex, which increases the complexity of program design.
By introducing an independent signal line between the Modbus master and slave devices, and using the GPIO port to generate an interrupt, the T3.5 time interval is eliminated, and the device directly enters the data parsing state, simplifying the communication process.
It improves the response speed of the Modbus protocol, simplifies the message reception and acknowledgment mechanism, and reduces the complexity of program design.
Smart Images

Figure CN118233349B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of industrial control and Internet of Things, and in particular to a system for fast response to Modbus protocol. BACKGROUND
[0002] Modbus protocol is a classic serial communication protocol, originally designed to connect programmable logic controllers (PLC) and other automation devices. Its simplicity and reliability make Modbus one of the most popular communication protocols in the industry, widely used in monitoring, control and data acquisition.
[0003] Modbus protocol is a typical master-slave communication structure, and only one master device can be connected in the link, and multiple slave devices can be connected. The master device sends a request command to the slave device, and the slave device responds to the command. The slave device cannot actively send a command to the master device, and the slave devices cannot communicate with each other.
[0004] Modbus RTU message frame consists of four parts: device address, function code, data and check. Because the message frame lacks specific header and trailer information, in order to distinguish between two different message data, it is usually necessary to separate at least 3.5 characters between two frames of data, which is called T3.5. T3.5 is used to describe the transmission interval time between two different Modbus message frames (the transmission time interval between the end character of the current message frame and the start character of the next message frame). However, because of the existence of T3.5 interval, the overall efficiency of bus communication is low, especially when there are many slave devices on the serial bus that need to be inspected, the impact is particularly obvious. Moreover, because of the existence of T3.5 interval, the message receiving response mechanism becomes more complex, and different interval response mechanisms need to be designed for different communication rates, increasing the complexity of program design. SUMMARY
[0005] In order to solve the above technical problems, the present application provides a system for fast response to Modbus protocol, which can effectively improve the response speed of Modbus protocol on serial bus.
[0006] The technical scheme of the present application is:
[0007] A system for fast response to Modbus protocol, the system as a whole is composed of a Modbus master device and multiple Modbus slave devices. The devices are connected and communicated through a serial bus, and each device on the bus is connected to the same independent signal line through a GPIO port of its own master chip. The independent signal line is connected to the on-board power supply through the pull-up resistor at the Modbus master device end, and is in a high level state by default.
[0008] Further,
[0009] When the devices communicate through the serial bus, the Modbus master device initiates a message frame to the slave device at a specified address, and at the end of the message frame transmission, the master device actively outputs a low level through its GPIO port to pull the level of the independent signal line low. The low level triggers the GPIO interrupt of the slave device, thereby notifying the slave device to directly enter the Modbus data analysis state without waiting for the T3.5 time interval.
[0010] When the slave device sends a response message frame, after the end of the response message transmission, a low level is output through the GPIO port of the master control chip to pull the level of the independent signal line low, and the low level triggers the GPIO interrupt of the master device, thereby notifying the master device to directly enter the Modbus data analysis state without waiting for the T3.5 time interval.
[0011] Further,
[0012] The communication process when the Modbus master device reads the data of the slave device is as follows:
[0013] Initialization: The Modbus master device and the slave device enable the interface interrupts participating in the communication connection, including the serial port reception interrupt and the GPIO interrupt;
[0014] Master sending: The Modbus master device actively sends a message frame to the slave device at a specified address; after the master device completes the transmission of the message frame, it immediately outputs a low level through its GPIO port and then outputs a high level again;
[0015] Slave receiving: The slave device receives the message frame byte by byte through the serial port interrupt program and stores the data in its own reception buffer; after the master device outputs a low level through the GPIO port to pull the level of the independent signal line low, the GPIO interrupt of the slave device is triggered to execute its own GPIO interrupt response program;
[0016] Slave analysis: The slave device executes the Modbus protocol analysis function in the GPIO interrupt response program, processes the data in the reception buffer, and clears the reception buffer;
[0017] Slave response: After the slave device analyzes the Modbus protocol data, it sends a response message frame according to the received modbus instruction, and after the last byte of the message frame is sent, it outputs a low level through its own GPIO port and then outputs a high level again;
[0018] Master receiving: the master device receives the message frame byte by byte through the serial port interrupt program of itself, and stores the data into the receiving buffer area of itself, when the independent signal line is pulled low by the low level output by the slave device through the GPIO port, the GPIO interrupt of the master device is triggered, and the GPIO interrupt response program of itself is executed;
[0019] Master analysis: the Modbus master executes the Modbus protocol analysis function in the GPIO interrupt response program, obtains the required data, and clears the receiving buffer area.
[0020] The communication flow when the Modbus master device writes the register or coil of the slave device is as follows:
[0021] Initialization: the Modbus master device and the slave device start the interrupt of the interface participating in the communication connection, including the serial port receiving interrupt and the GPIO interrupt;
[0022] Master sending: the Modbus master device actively sends the message frame to the slave device of the specified address; after the master device completes the sending of the message frame, the low level is output through the GPIO port of itself immediately, and then the high level is output again;
[0023] Slave receiving: the slave device receives the message frame byte by byte through the serial port interrupt program, and stores the data into the receiving buffer area of itself, when the independent signal line is pulled low by the low level output by the master device through the GPIO port, the GPIO interrupt of the slave device is triggered, and the GPIO interrupt response program of itself is executed;
[0024] Slave analysis: the slave device executes the Modbus protocol analysis function in the GPIO interrupt response program, processes the data in the receiving buffer area, and clears the receiving buffer area;
[0025] Slave execution: after the slave device analyzes the Modbus protocol data, the corresponding register or coil operation is executed according to the received modbus instruction.
[0026] The beneficial effects of the application are
[0027] The way of generating the GPIO interrupt through the independent signal line is used to inform the device that the data sending of the frame is completed, which not only improves the response real-time performance of the Modbus protocol, but also simplifies the message receiving and responding mechanism, and reduces the complexity of the program design. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 is the overall architecture schematic diagram of the application;
[0029] Figure 2 is the communication flow schematic diagram when the Modbus master device reads the data of the slave device;
[0030] Figure 3 is the communication flow diagram when Modbus master device writes the register or coil on slave device. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical scheme and advantages of the embodiments of the present application more clear, the technical scheme in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.
[0032] The present application provides a system for quickly responding to Modbus protocol, the overall architecture of the system is shown in the accompanying Figure 1 The system is composed of Modbus master device and multiple Modbus slave devices. The devices are connected and communicated through serial bus. In order to enhance the communication distance of serial bus, the Modbus master device and slave devices are equipped with level conversion modules, so as to ensure the stability of long-distance communication. Meanwhile, each device on the bus is connected to the same independent signal line through a GPIO port of its own master chip, and the independent signal line is connected to the on-board power supply through the pull-up resistor at the Modbus master device end, and is in a high level state by default.
[0033] The communication flow when the Modbus master device reads the data of the slave device is shown in the accompanying Figure 2 The main process is as follows:
[0034] Initialization: The Modbus master device and slave device start the interface interrupt of their own participation in communication connection, including serial port receiving interrupt and GPIO interrupt.
[0035] Host sending: The Modbus master device actively sends the message frame to the slave device at the specified address. After the master device completes the sending of the message frame, it immediately outputs low level through its own GPIO port, and then outputs high level again.
[0036] Slave receiving: The slave device receives the message frame byte by byte through the serial port interrupt program, and stores the data into its own receiving buffer. When the master device outputs low level through the GPIO port to pull down the level of the independent signal line, the GPIO interrupt of the slave device is triggered, and the GPIO interrupt response program of the slave device is executed.
[0037] Slave analysis: The slave device executes the Modbus protocol analysis function in the GPIO interrupt response program to process the data in the receiving buffer, and clears the receiving buffer.
[0038] Slave response: after the slave device parses the Modbus protocol data, according to the received modbus instruction, a response message frame is sent. And after the last byte of the message frame is sent, a low level is output through the GPIO port of the slave device, and then a high level is output again.
[0039] Host receiving: the host device receives the message frame byte by byte through the serial port interrupt program of the host device, and stores the data in the receiving buffer area of the host device. When the slave device outputs a low level through the GPIO port to pull down the independent signal line, the GPIO interrupt of the host device is triggered, and the GPIO interrupt response program of the host device is executed.
[0040] Host analysis: the Modbus host executes the Modbus protocol analysis function in the GPIO interrupt response program to obtain the required data. And the receiving buffer area is emptied.
[0041] The communication process when the Modbus master device writes the register or coil of the slave device is shown in Fig. 1, and the main process is as follows: Figure 3
[0042] Initialization: the Modbus master device and the slave device start the interface interrupt of the communication connection, including the serial port receiving interrupt and the GPIO interrupt.
[0043] Host sending: the Modbus master device actively sends the message frame to the slave device at the specified address. After the master device completes the sending of the message frame, a low level is immediately output through the GPIO port of the master device, and then a high level is output again.
[0044] Slave receiving: the slave device receives the message frame byte by byte through the serial port interrupt program, and stores the data in the receiving buffer area of the slave device. When the master device outputs a low level through the GPIO port to pull down the independent signal line, the GPIO interrupt of the slave device is triggered, and the GPIO interrupt response program of the slave device is executed.
[0045] Slave analysis: the slave device executes the Modbus protocol analysis function in the GPIO interrupt response program to process the data in the receiving buffer area. And the receiving buffer area is emptied.
[0046] Slave execution: after the slave device parses the Modbus protocol data, according to the received modbus instruction, the corresponding write register or coil operation is executed.
[0047] The above only describes the preferred embodiments of the present application, which are used to illustrate the technical solutions of the present application, and are not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application are included in the protection scope of the present application.
Claims
1. A system for responding to the Modbus protocol quickly, characterized in that, it comprises a Modbus master device and a plurality of Modbus slave devices; each device is connected to communicate through a serial bus, and each device on the bus is connected to the same independent signal line through the GPIO port of its own master chip, and the independent signal line is connected to the on-board power supply through the pull-up resistor at the end of the Modbus master device, and is in a high state by default; devices are connected to communicate through a serial bus to enhance the communication distance of the serial bus, and the Modbus master device and the slave device both have on-board level conversion modules to ensure the stability of long-distance communication; the independent signal line generates a GPIO interrupt to notify the device that the current frame data transmission is complete; when devices communicate through a serial bus, the Modbus master device initiates a message frame to a slave device at a specified address, and at the end of the message frame transmission, the master device actively outputs a low level through its GPIO port to pull the level of the independent signal line low; the low level triggers the GPIO interrupt of the slave device, which directly enters the Modbus data analysis state without waiting for the T3.5 time interval; when the slave device sends a response message frame, after the response message is sent, it outputs a low level through its GPIO port to pull the level of the independent signal line low, and the low level triggers the GPIO interrupt of the master device; to notify the master device to directly enter the Modbus data analysis state without waiting for the T3.5 time interval.
2. The system of claim 1, characterized in that, the communication process when the Modbus master device reads slave device data is as follows: Initialization: the Modbus master device and the slave device enable the interface interrupts involved in their communication connection, including serial port reception interrupts and GPIO interrupts; Master sending: the Modbus master device actively sends a message frame to a slave device at a specified address; After the master device completes the sending of the message frame, it immediately outputs a low level through its GPIO port and then outputs a high level again; Slave receiving: the slave device receives the message frame byte by byte through the serial port interrupt program and stores the data in its own reception buffer, and when the master device outputs a low level through the GPIO port to pull the level of the independent signal line low, the GPIO interrupt of the slave device is triggered to execute its GPIO interrupt response program; Slave analysis: the slave device executes the Modbus protocol analysis function in the GPIO interrupt response program to process the data in the reception buffer and clear the reception buffer; Slave response: after the slave device analyzes the Modbus protocol data, it sends a response message frame according to the received Modbus instruction, and after the last byte of the message frame is sent, it outputs a low level through its GPIO port and then outputs a high level again; Master receiving: the master device receives the message frame byte by byte through its own serial port interrupt program and stores the data into its own receiving buffer area. When the independent signal line is pulled low by the slave device through the GPIO output low level, the GPIO interrupt of the master device is triggered to execute its own GPIO interrupt response program; Master analysis: the Modbus master executes the Modbus protocol analysis function in the GPIO interrupt response program to obtain the required data and clear the receiving buffer area.
3. The system of claim 1, wherein, Modbus master device writes the register or coil of the slave device, and the communication process is as follows: Initialization: the Modbus master device and the slave device start the interrupt of the interface participating in the communication connection, including the serial port receiving interrupt and the GPIO interrupt; Master sending: the Modbus master device actively sends the message frame to the slave device at the specified address; After the master device completes the sending of the message frame, it immediately outputs low level through its own GPIO port, and then outputs high level again; Slave receiving: the slave device receives the message frame byte by byte through the serial port interrupt program and stores the data into its own receiving buffer area. When the independent signal line is pulled low by the master device through the GPIO output low level, the GPIO interrupt of the slave device is triggered to execute its own GPIO interrupt response program; Slave analysis: the slave device executes the Modbus protocol analysis function in the GPIO interrupt response program to process the data in the receiving buffer area and clear the receiving buffer area; Slave execution: after the slave device analyzes the Modbus protocol data, it executes the corresponding write register or coil operation according to the received Modbus instruction.
Citation Information
Patent Citations
Method for realizing universal serial interrupt module based on COMe platform
CN113641617A
Industrial control system and method based on FPGA
CN116633968A