Main control board serial port communication method based on non-standard Modbus communication protocol
By adopting non-standard Modbus communication protocol and timeout retransmission mechanism in embedded systems, the communication delay and unreliability problems under UART low-rate communication are solved, and more efficient and reliable serial communication is achieved.
Patent Information
- Application Number
- CN202411572682.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-02-25
AI Technical Summary
In the embedded field, when using UART low-speed 9600 baud rate for communication between the main control board and the slave board, we face communication delays and unreliability problems, especially in big data or variable-length data communication scenarios.
The main control board serial communication method based on the non-standard Modbus communication protocol is adopted to communicate through the non-standard Modbus protocol format. The frame data includes address domain, function code, register address, parameter data, verification, and judge whether the frame reception is completed and the timeout is sent to determine whether it is timeout and retransmission is retransmitted.
It solves the problems of communication delay and unreliability, improves the reliability and flexibility of communication, allows packets and receive variable-length data frames, timeout retransmission and other functions, and improves the stability of communication.
Smart Images

Figure CN119513010A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of embedded communication, in particular to a main control board serial port communication method based on a non-standard Modbus communication protocol. Background Art
[0002] In the embedded field, commonly used communication solutions include UART, I2C, SPI, CAN, etc. UART is known for its ease of use and low cost, suitable for point-to-point communication, but the transmission distance and speed are limited. Modbus protocol is widely used in industrial automation and is open and compatible.
[0003] When the main control board uses UART low-speed 9600 baud rate to control the slave board communication, when there is a large amount of data communication and variable-length data communication, it will cause communication delays and unreliable communication (for example, in smart cat litter box products, the slave board has the functions of controlling the rotation of the inner bin (rotation angle, rotation direction, return detection), fan control, weighing control, overcurrent protection control, cat litter detection, etc., and in the face of future scalability issues, using UART low-speed 9600 baud rate to report all data together will cause communication delays and unreliable communication). Summary of the invention
[0004] The object of the present invention is to provide a main control board serial port communication method based on non-standard Modbus communication protocol to solve the problems in the prior art.
[0005] To achieve the above-mentioned purpose, the present invention provides the following technical solutions: a main control board serial port communication method based on a non-standard Modbus communication protocol, including a main control board and a slave board, wherein the non-standard Modbus protocol format is used as the communication format between the main control board and the slave board, the main control board sends a request to the slave board, and the slave board responds to the request to the main control board, and the frame reception is completed by timeout, and whether to resend after timeout is determined by timeout sending, and the frame data includes an address field, a function code, a register address, parameter data, and a check.
[0006] Preferably, the main control board is used for state logic processing and issuing requests; the slave board is used for machine operation and responding to requests.
[0007] Preferably, the serial port processing logic of the main control board includes the following steps:
[0008] S11. According to the current running state of the main control board, determine whether there is a request to be sent; if it is determined that there is a request to be sent, determine whether the request is waiting for a response; if it is determined that there is no response to be waited for, prepare the request data and prepare to send it; if it is determined that there is a response to be waited for, determine whether the waiting time for the response has timed out, and if it has timed out, set to resend the function request;
[0009] S12, judging whether there is a request ready to be sent; if it is judged that there is a request ready to be sent, data is sent, the corresponding function request is set to wait for response, the communication time is reset, and the function waiting response time is reset;
[0010] S13, judging whether the communication time exceeds 10s; if it is judged to exceed 10s, a communication abnormality error is reported;
[0011] S14, judging whether a response frame from the slave board is currently received; when judging that a response frame from the slave board is received, parsing the frame data, and confirming that the corresponding function request is set to the response end.
[0012] Preferably, when it is determined in S11 that the waiting response time has not exceeded, the process directly enters S12;
[0013] If it is determined in S12 that there is no ready request to send, then directly enter S13;
[0014] If it is judged in S13 that it does not exceed 10s, it directly enters S14;
[0015] If it is determined in S14 that no response frame is received from the slave board, the process ends directly.
[0016] Preferably, the slave board serial port processing logic includes the following steps:
[0017] S21, determine whether a data frame is received; if a data frame is received, enter S22;
[0018] S22, parse the data frame, read the address, function code, function, parameter data, and checksum; determine whether the address, function code, function, and checksum are correct; if the determination is correct, enter S23; if the determination is incorrect, return to S21;
[0019] S23, respond to the main control board function request operation and prepare response data;
[0020] S24. Determine whether there is a response ready to send. If yes, send the data.
[0021] Compared with the prior art, the present invention has the following beneficial effects:
[0022] 1. Solved the problem of delayed communication (avoided large data transmission) and improved the reliability of communication.
[0023] 2. Use non-standard Modbus protocol to facilitate later development and expansion (new functions) and improve flexibility.
[0024] 3. Normal communication is achieved without modifying the low-speed transmission of the UART serial port, ensuring the low cost and anti-interference ability of the product.
[0025] 4. Allow packet interception, receiving variable-length data frames, timeout retransmission and other functions to improve communication stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0027] Figure 1 It is a schematic diagram of the present invention;
[0028] Figure 2 It is the serial port processing logic diagram of the main control board of the present invention;
[0029] Figure 3 This is a logic diagram of the slave board serial port processing of the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention.
[0031] See also Figure 1-3 In an embodiment of the present invention, a main control board serial port communication method based on a non-standard Modbus communication protocol includes a main control board and a slave board. The non-standard Modbus protocol format is used as the communication format between the main control board and the slave board. The main control board sends a request to the slave board, and the slave board responds to the request to the main control board. The frame reception is completed by timeout, and whether to resend after timeout is determined by timeout sending. The frame data includes an address field, a function code, a register address, parameter data, and a check.
[0032] Preferably, the main control board is used for state logic processing and issuing requests; the slave board is used for machine operation and responding to requests.
[0033] Preferably, the serial port processing logic of the main control board includes the following steps:
[0034] S11. According to the current running state of the main control board, determine whether there is a request to be sent; if it is determined that there is a request to be sent, determine whether the request is waiting for a response; if it is determined that there is no response to be waited for, prepare the request data and prepare to send it; if it is determined that there is a response to be waited for, determine whether the waiting time for the response has timed out, and if it has timed out, set to resend the function request;
[0035] S12, judging whether there is a request ready to be sent; if it is judged that there is a request ready to be sent, data is sent, the corresponding function request is set to wait for response, the communication time is reset, and the function waiting response time is reset;
[0036] S13, judging whether the communication time exceeds 10s; if it is judged to exceed 10s, a communication abnormality error is reported;
[0037] S14, judging whether a response frame from the slave board is currently received; when judging that a response frame from the slave board is received, parsing the frame data, and confirming that the corresponding function request is set to the response end.
[0038] Preferably, when it is determined in S11 that the waiting response time has not exceeded, the process directly enters S12;
[0039] If it is determined in S12 that there is no ready request to send, then directly enter S13;
[0040] If it is judged in S13 that it does not exceed 10s, it directly enters S14;
[0041] If it is determined in S14 that no response frame is received from the slave board, the process ends directly.
[0042] Preferably, the slave board serial port processing logic includes the following steps:
[0043] S21, determine whether a data frame is received; if a data frame is received, enter S22;
[0044] S22, parse the data frame, read the address, function code, function, parameter data, and checksum; determine whether the address, function code, function, and checksum are correct; if the determination is correct, enter S23; if the determination is incorrect, return to S21;
[0045] S23, respond to the main control board function request operation and prepare response data;
[0046] S24. Determine whether there is a response ready to send. If yes, send the data.
[0047] The working principle of the present invention is: adopting a non-standard Modbus protocol format as the communication format between the control board and the slave board, the frame data includes an address field, a function code, a register address, parameter data, and a check component; judging the completion of frame reception through timeout (allowing the reception of variable-length data frames and allowing the main control board to process the packets); judging whether to resend after timeout through timeout sending; avoiding large data communication through the non-standard Modbus protocol format, so that the main control board can perform communication control on the slave board according to a specific function, thereby improving communication efficiency.
[0048] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A main control board serial port communication method based on non-standard Modbus communication protocol, characterized in that: It includes a main control board and a slave board. The non-standard Modbus protocol format is used as the communication format between the main control board and the slave board. The main control board sends a request to the slave board, and the slave board responds to the request to the main control board. The frame reception is completed by judging the timeout, and whether to resend after timeout is judged by timeout sending. The frame data includes the address field, function code, register address, parameter data, and check.
2. A main control board serial port communication method based on non-standard Modbus communication protocol according to claim 1, characterized in that: The main control board is used for state logic processing and issuing requests; the slave board is used for machine operation and responding to requests.
3. A main control board serial port communication method based on non-standard Modbus communication protocol according to claim 1, characterized in that: The serial port processing logic of the main control board includes the following steps: S11. According to the current running state of the main control board, determine whether there is a request to be sent; if it is determined that there is a request to be sent, determine whether the request is waiting for a response; if it is determined that there is no response to be waited for, prepare the request data and prepare to send it; if it is determined that there is a response to be waited for, determine whether the waiting time for the response has timed out, and if it has timed out, set to resend the function request; S12, judging whether there is a request ready to be sent; if it is judged that there is a request ready to be sent, data is sent, the corresponding function request is set to wait for response, the communication time is reset, and the function waiting response time is reset; S13, judging whether the communication time exceeds 10s; if it is judged to exceed 10s, a communication abnormality error is reported; S14, judging whether a response frame from the slave board is currently received; when judging that a response frame from the slave board is received, parsing the frame data, and confirming that the corresponding function request is set to the response end.
4. A main control board serial port communication method based on non-standard Modbus communication protocol according to claim 3, characterized in that: If it is determined in S11 that the waiting time for a response is not exceeded, the process directly proceeds to S12; If it is determined in S12 that there is no ready request to send, then directly enter S13; If it is judged in S13 that it does not exceed 10s, it directly enters S14; If it is determined in S14 that no response frame is received from the slave board, the process ends directly.
5. A main control board serial port communication method based on non-standard Modbus communication protocol according to claim 3 or 4, characterized in that: The slave serial port processing logic includes the following steps: S21, determine whether a data frame is received; if a data frame is received, enter S22; S22, parse the data frame, read the address, function code, function, parameter data, and checksum; determine whether the address, function code, function, and checksum are correct; if the determination is correct, enter S23; if the determination is incorrect, return to S21; S23, respond to the main control board function request operation and prepare response data; S24. Determine whether there is a response ready to send. If yes, send the data.