Low-delay control method, system, storage medium and device for RS485 communication
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN KBIDM TECH CO LTD
- Filing Date
- 2025-12-17
- Publication Date
- 2026-08-07
AI Technical Summary
当采用上述传统方案与高速设备进行通信时,系统在数据处理能力和通信速率匹配等方面均表现出显著不足
[0031]本申请提供的RS485通信的低延迟控制方法、系统、存储介质及设备,通过预估串行数据发送耗时,并提前触发IO扩展芯片的控制命令拉低RS485通信模块的驱动使能端,从而消除因IO拓展通信固有延迟导致的数据接收冲突与丢包问题。通过软硬件协同优化,使得驱动使能端在串口发送数据完成后的规定时间内被拉低,满足高速RS485从设备的快速响应需求,显著降低数据丢包率,通信可靠性大幅提升。同时无需更改硬件设计,仅通过算法优化即可实现高速通信兼容,具有成本低、易移植和高兼容性等显著优势,极大提升了现有低速扩展方案的应用范围与工程实用性。
Smart Images

Figure CN121644268B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, specifically to a low-latency control method, system, storage medium, and device for RS485 communication. Background Technology
[0002] In applications such as industrial control and intelligent transportation, RS485 communication technology has become the mainstream solution for data interaction between devices due to its excellent anti-interference performance and long-distance transmission characteristics. Traditional solutions typically employ a combination of multiple serial ports and multiple I / O hardware architectures to meet the communication needs with low-speed RS485 devices.
[0003] With technological advancements, devices employing high-speed RS485 communication, such as LiDAR, are gradually achieving large-scale application. When using the aforementioned traditional solutions to communicate with high-speed devices, the system exhibits significant shortcomings in data processing capabilities and communication rate matching. Particularly in high-speed data transmission scenarios, the RS485 bus frequently experiences packet loss, sometimes even failing to receive complete single-frame data packets, rendering the communication link essentially unusable. Adopting a hardware replacement strategy would not only extend the user's development cycle but also significantly increase development costs, creating numerous implementation obstacles. Summary of the Invention
[0004] In view of the above-mentioned shortcomings of the prior art, this application provides a low-latency control method, system, storage medium and device for RS485 communication, which effectively solves the problems of RS485 communication data reception conflict and packet loss in high-speed data transmission scenarios.
[0005] In a first aspect, this application provides a low-latency control method for RS485 communication. The method is applied to a hardware communication system, which includes at least a main control chip, a serial port expansion chip, and an I / O expansion chip. The main control chip is connected to the serial port expansion chip via a first communication interface to send serial data. The main control chip is also connected to the I / O expansion chip via a second communication interface to control the driver enable terminal of the RS485 communication module. The method includes:
[0006] Obtain the number of bytes in the current data frame to be sent and the serial port baud rate of the serial port expansion chip;
[0007] Calculate the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate;
[0008] Based on the estimated time and hardware response delay time, determine the trigger time for the control command to pull down the driver enable terminal;
[0009] Before or during the transmission of the data frame to be sent, a control command is sent to the IO expansion chip according to the control command trigger time, so that the driver enable terminal is pulled low for a specified time after the data frame transmission ends, so that the RS485 communication module can receive data.
[0010] In an optional implementation, calculating the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate includes:
[0011] Calculate the byte transmission time required to send one byte based on the serial port baud rate;
[0012] The estimated time is calculated based on the byte transmission time and the number of bytes.
[0013] In an optional implementation, the estimated time further includes an offset time, which represents the serial port startup delay time between when the drive enable terminal is pulled high and when the serial port expansion chip begins to send data frames.
[0014] In an optional implementation, determining the control command trigger time for pulling down the driver enable terminal based on the estimated time and hardware response delay time includes:
[0015] Set an additional hardware response latency time based on the serial port baud rate and the number of bytes;
[0016] The control command trigger time is obtained by adding the reserved time to the estimated time and subtracting the hardware response delay time.
[0017] In an optional implementation, the first communication interface is a Serial Peripheral Interface (SPI), and the second communication interface is a Bidirectional Synchronous Serial Bus Interface (I2C).
[0018] Secondly, this application provides a low-latency control system for RS485 communication, the system comprising a main control module, a serial port expansion chip, an I / O expansion chip, and an RS485 communication module, wherein:
[0019] The serial port expansion chip is connected to the main control module via the SPI bus, and the serial port expansion chip is used to expand at least one UART channel.
[0020] The IO expansion chip is connected to the main control module via an I2C bus, and the IO expansion chip is used to provide programmable GPIO output;
[0021] The RS485 communication module is connected to the serial port expansion chip and the IO expansion chip respectively, and the driver enable terminal of the RS485 communication module is connected to one GPIO terminal of the IO expansion chip.
[0022] The main control module includes a communication control unit. The communication control unit is used to determine the control command trigger time for pulling down the driver enable terminal based on the number of bytes of the current data frame to be sent and the serial port baud rate, and to send the control command for pulling down the driver enable terminal to the IO expansion chip according to the control command trigger time, so as to enable the RS485 communication module to quickly switch to the data receiving state after the data is sent.
[0023] In an optional implementation, the communication control unit includes:
[0024] The data acquisition subunit is used to acquire the number of bytes of the current data frame to be sent and the serial port baud rate of the serial port expansion chip;
[0025] The first calculation subunit is used to calculate the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate.
[0026] The second calculation subunit is used to determine the control command trigger time for pulling down the drive enable terminal based on the estimated time and the hardware response delay time.
[0027] The instruction sending subunit is used to send a control instruction to the IO expansion chip according to the control command trigger time before or during the transmission of the data frame to be sent, so that the driver enable terminal is pulled low for a specified time after the data frame is sent, so that the RS485 communication module can receive data.
[0028] In an optional implementation, the serial port expansion chip is a WK2124 chip, and the IO expansion chip is an NCA9555 chip.
[0029] Thirdly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the low-latency control method for RS485 communication as described in the first aspect of this application.
[0030] Fourthly, this application provides an electronic device that includes the low-latency control system for RS485 communication described in the second aspect of this application.
[0031] The low-latency control method, system, storage medium, and device for RS485 communication provided in this application eliminate data reception conflicts and packet loss problems caused by the inherent latency of IO extended communication by estimating the serial data transmission time and triggering the control command of the IO extension chip to pull the driver enable pin of the RS485 communication module low in advance. Through hardware and software co-optimization, the driver enable pin is pulled low within a specified time after the serial port data transmission is completed, meeting the fast response requirements of high-speed RS485 slave devices, significantly reducing the data packet loss rate, and greatly improving communication reliability. At the same time, high-speed communication compatibility can be achieved without changing the hardware design, only through algorithm optimization. It has significant advantages such as low cost, easy portability, and high compatibility, greatly improving the application scope and engineering practicality of existing low-speed extension solutions. Attached Figure Description
[0032] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 This is a schematic flowchart of the low-latency control method for RS485 communication provided in the embodiments of this application;
[0034] Figure 2 This is a timing comparison diagram between the solution provided in the embodiments of this application and the traditional solution;
[0035] Figure 3 This is a schematic diagram of the low-latency control system structure for RS485 communication provided in an embodiment of this application;
[0036] Figure 4 This is a schematic diagram of the communication control unit in an embodiment of this application;
[0037] Figure 5 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application.
[0038] Key component symbols: 200, Low-latency control system for RS485 communication; 210, Main control module; 220, Serial port expansion chip; 230, IO expansion chip; 240, RS485 communication module; 2111, Data acquisition subunit; 2112, First calculation subunit; 2113, Second calculation subunit; 2114, Command sending subunit; 300, Electronic equipment. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be further described clearly and completely below with reference to the accompanying drawings of the embodiments. It should be noted that the described embodiments are merely some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0040] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.
[0041] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of this application.
[0042] Currently, electronic devices such as LiDAR using high-speed RS485 communication are gradually achieving large-scale application. When communicating with electronic devices using a combination of multi-channel serial ports and multi-channel I / O hardware architecture, the system exhibits significant shortcomings in data processing capabilities and communication rate matching. Especially in high-speed data transmission scenarios, the RS485 communication bus frequently experiences data packet loss, sometimes even failing to receive complete single-frame data packets, rendering the communication link essentially unusable. Adopting a hardware replacement strategy would not only extend the user's development cycle but also significantly increase development costs, creating numerous implementation obstacles.
[0043] Example 1
[0044] This application provides a low-latency control method for RS485 communication, which effectively solves the problems of data reception conflict and packet loss in RS485 communication under high-speed data transmission scenarios.
[0045] In this embodiment, the method is applied to a hardware communication system, which includes at least a main control chip, a serial port expansion chip, and an I / O expansion chip. The main control chip is connected to the serial port expansion chip through a first communication interface to send serial data, and the main control chip is connected to the I / O expansion chip through a second communication interface to control the driver enable terminal of the RS485 communication module.
[0046] As an optional implementation of this application, the first communication interface can be a serial peripheral interface (SPI), and the second communication interface can be a bidirectional synchronous serial transmission bus interface (I2C). That is, the serial port expansion chip is connected to the main control chip through the SPI bus, and the main control chip is connected to the IO expansion chip through the I2C bus. The clock frequencies of the SPI bus and the I2C bus can be set according to the actual situation. For example, the SPI bus clock frequency can be 8MHz, the I2C bus clock frequency can be 400kHz, and the operating system can be Linux.
[0047] Figure 1 This is a schematic flowchart of a low-latency control method for RS485 communication provided in an embodiment of this application, as shown below. Figure 1 As shown, the method includes:
[0048] S100: Obtain the number of bytes in the current data frame to be sent and the serial port baud rate of the serial port expansion chip.
[0049] In this embodiment of the application, the number of bytes in the data frame to be sent, i.e., the data frame length, can be obtained in the following way:
[0050] First, initialize a counter variable. i =0, and set the number of bytes to be sent to tx_count. Then check if the current serial port transmit buffer is empty. If it is empty, end the data reading directly; otherwise, enter the loop reading process. In the loop, read one byte of data from the circular transmit buffer one by one and store it in the temporary array txbuf[i]. Then update the buffer tail pointer tail, using modulo arithmetic to ensure loop access within the fixed-size buffer. Increment the index for each successfully read byte. i The count of bytes sent is incremented by the count, while the count of bytes remaining to be processed is decremented. This loop continues until tx_count bytes have been processed or the buffer is empty. Finally, the actual number of bytes read is recorded. i The length of this data frame is the number of bytes in the data frame to be sent.
[0051] In this embodiment of the application, the serial port baud rate can be accurately read from the configured serial port operating parameters. By accurately obtaining the number of bytes of the data frame to be sent through the serial port and the serial port baud rate, a data basis can be provided for subsequent time calculations.
[0052] S200: Calculate the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate.
[0053] In this embodiment, the serial port baud rate represents the number of symbols transmitted per second, which is typically equal to the number of bits transmitted per second in RS485 communication. Each byte consists of multiple bits, therefore, the byte transmission time required to send one byte can be calculated based on the serial port baud rate, using the following formula:
[0054]
[0055] In the above formula, t b This represents the byte transfer time required to transmit one byte. B This represents the number of bits in one byte. baud This indicates the serial port baud rate.
[0056] Multiplying the byte transmission time by the number of bytes yields the pure data transmission time of the data frame to be sent.
[0057] In this embodiment, the master control chip sends a set of data commands conforming to the I2C bus timing sequence. Upon receiving these commands, the IO expansion chip pulls a designated GPIO pin high. This designated GPIO pin is connected to the driver enable pin of the RS485 communication module, thus pulling the driver enable pin high. During RS485 bus communication, a high driver enable pin indicates that the master device is starting to send data to the slave device; conversely, a low driver enable pin indicates that the master device is not sending data, only receiving it. Only after the RS485 communication module's driver enable pin is high can the data frames sent by the serial port expansion chip be received by other slave devices. A high RS485 communication module driver enable pin indicates the start of RS485 bus data transmission, requiring coordination with the serial port expansion chip to complete the transmission.
[0058] Because of the hardware and software delays between the RS485 communication module's driver enable pin going high and the serial port actually starting to send data frames, the estimated time also includes an offset time. This offset time represents the serial port startup delay time between when the driver enable pin is pulled high and when the serial port expansion chip starts sending data frames.
[0059] In this embodiment of the application, the formula for calculating the estimated time required to send the data frame to be sent is as follows:
[0060]
[0061] In the above formula, T P This indicates the estimated time required to send the data frame to be sent. t b This represents the byte transfer time required to transmit one byte. i Indicates the number of bytes in the data frame to be sent. t1 indicates the offset time.
[0062] S300: Determine the trigger time of the control command to pull down the driver enable terminal based on the expected time and hardware response delay time.
[0063] As an optional implementation of this application, an additional hardware response delay time can be set according to the serial port baud rate and the number of bytes. First, a basic hardware response delay time can be defined. This value can be calibrated by measuring the hardware communication system using tools such as a logic analyzer. Optionally, this hardware response delay time can be set to 117µs. Since the signal transmission cycle is longer at low baud rates, the internal processing behavior of the serial port expansion chip differs, requiring additional delay compensation. Therefore, if the current serial port baud rate is 9600bps, the hardware response delay time is adjusted to 207µs. Additionally, if the number of bytes in the data frame to be sent is greater than or equal to 30 bytes, the flag others_baud=1 is set, indicating that other special baud rate scenarios may be involved, which can be used for subsequent dynamic adjustment strategies.
[0064] In this embodiment, to ensure that the control command is not issued prematurely, a reserve time is set. Optionally, this reserve time can be set to 7µs. The control command trigger time is obtained by adding the estimated time to the reserve time and subtracting the hardware response delay time, as shown in the following formula:
[0065]
[0066] In the above formula, T N Indicates the trigger time of the control command. T P This indicates the estimated time required to send the data frame to be sent. t 2 indicates reserved time. T E This indicates the hardware response delay time.
[0067] As an optional implementation of this application, if the control command trigger time is less than or equal to 0, it means that there is no need to wait and the control command should be sent immediately. In this case, it is forcibly set to the minimum positive value of 1 microsecond to prevent negative delay from causing abnormalities.
[0068] The embodiments of this application improve the adaptability and accuracy of the algorithm in different communication scenarios through a fine-grained compensation mechanism based on the serial port baud rate and the number of bytes of the data frame to be sent.
[0069] S400: Before or during the transmission of the data frame to be sent, a control command is sent to the IO expansion chip according to the control command trigger time, so that the driver enable terminal is pulled low within a specified time after the data frame is sent, and the RS485 communication module receives data.
[0070] In this embodiment, before or during the transmission of the data frame to be sent, a control command is sent to the IO expansion chip according to the control command trigger time using an operating system timer or a high-precision delay function. This sets the GPIO pin corresponding to the driver enable terminal of the IO expansion chip connected to the RS485 communication module to a low level. At this time, although the serial port expansion chip is still sending the last byte of data, due to advance scheduling, the RS485 communication module has switched to data reception mode within a specified time after the serial port expansion chip finishes sending data. This specified time can be set to 10µs. When high-speed slave devices such as LiDAR return response data, the main control chip is already in data reception mode, capable of completely capturing the returned data frame and avoiding data packet loss.
[0071] To verify the effectiveness of the low-latency control method for RS485 communication provided in this application embodiment, a comparative test was conducted between the solution provided in this application embodiment and a traditional solution using a combination architecture of multiple serial ports and multiple I / O hardware. The test results show that the traditional solution has a packet loss rate of only one data return out of eight attempts, and this data return is incomplete. In contrast, the solution provided in this application embodiment has normal data transmission and reception with no packet loss. Figure 2 This is a timing comparison diagram between the solution provided in this application and the traditional solution, as shown below. Figure 2 As shown, the interval between the end of serial port transmission and the pull-down of the RS485 driver enable pin in the solution provided in this application is significantly shorter than that of the traditional solution. Therefore, the solution provided in this application is more suitable for use in high-speed RS485 devices such as LiDAR.
[0072] The low-latency control method for RS485 communication provided in this application calculates the time required for each data frame to be sent by the serial port expansion chip, and pre-processes the control command sending operation of the IO expansion chip. This allows the sending of serial port data and the pulling down of the RS485 communication module's driver enable terminal by the IO expansion chip to be done in parallel. As a result, after a data packet is sent, the pulling down of the RS485 communication module's driver enable terminal is within a specified time, thereby reducing the previous hard delay time. This meets the transmission requirements of high-speed communication slave devices such as LiDAR, and allows the complete acquisition of data packets transmitted by the slave device, maintaining stable data transmission.
[0073] Example 2
[0074] Based on the same technical concept as Embodiment 1 above, this application provides a low-latency control system for RS485 communication. Figure 3 This is a schematic diagram of the low-latency control system structure for RS485 communication provided in an embodiment of this application, as shown below. Figure 3As shown, the low-latency control system 200 for RS485 communication includes a main control module 210, a serial port expansion chip 220, an I / O expansion chip 230, and an RS485 communication module 240, wherein:
[0075] The serial port expansion chip 220 is connected to the main control module via the SPI bus. The serial port expansion chip 220 is used to expand at least one UART channel.
[0076] As an optional implementation of this application, the serial port expansion chip 220 can be a WK2124 chip, which can expand 4 UART channels through the SPI bus.
[0077] The IO expansion chip 230 is connected to the main control module via the I2C bus and is used to provide programmable GPIO output.
[0078] As an optional implementation of this application, the IO expansion chip 230 can be an NCA9555 chip. This NCA9555 chip can expand 10 GPIO channels via the I2C bus, and the main control module can control the high and low level outputs of each GPIO channel by reading and writing the register data of the NCA9555 chip via the I2C bus.
[0079] The RS485 communication module 240 is connected to the serial port expansion chip 220 and the IO expansion chip 230 respectively. The driver enable terminal of the RS485 communication module is connected to a GPIO terminal of the IO expansion chip 230. The RS485 communication module 240 realizes bus communication with external slave devices such as LiDAR through physical circuits and interfaces to achieve data interaction.
[0080] The main control module 210 includes a communication control unit 211. The communication control unit 211 is used to determine the control command trigger time of the pull-down drive enable terminal according to the number of bytes of the current data frame to be sent and the serial port baud rate, and send the control command of the pull-down drive enable terminal to the IO expansion chip 230 according to the control command trigger time, so as to realize that the RS485 communication module 240 quickly switches to the data receiving state after the data is sent. Figure 4 This is a schematic diagram of the communication control unit in an embodiment of this application, as shown below. Figure 4 As shown, the communication control unit 211 includes:
[0081] The data acquisition subunit 2111 is used to acquire the number of bytes of the current data frame to be sent and the serial port baud rate of the serial port expansion chip 220;
[0082] The first calculation subunit 2112 is used to calculate the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate;
[0083] The second calculation subunit 2113 is used to determine the control command trigger time for pulling down the drive enable terminal based on the expected time and the hardware response delay time.
[0084] The instruction sending subunit 2114 is used to send control instructions to the IO expansion chip 230 according to the control command trigger time before or during the transmission of the data frame to be sent, so that the drive enable terminal is pulled low within a specified time after the data frame is sent, and the RS485 communication module 240 receives data.
[0085] The low-latency control system for RS485 communication provided in this application, through hardware and software co-optimization, ensures that the driver enable pin is pulled low within a specified time after the serial port data transmission is completed. This meets the rapid response requirements of high-speed RS485 slave devices, significantly reduces data packet loss rate, and greatly improves communication reliability. Furthermore, it achieves high-speed communication compatibility without requiring changes to the hardware design; it offers significant advantages such as low cost, ease of portability, and high compatibility, greatly expanding the application scope and engineering practicality of existing low-speed expansion solutions.
[0086] It is understood that the implementation methods of the low-latency control method for RS485 communication in the above embodiments are also applicable to the embodiments of this application and can achieve the same technical effect, so they will not be described again here.
[0087] Example 3
[0088] Based on the same concept, embodiments of this application also provide a computer-readable storage medium storing a computer program containing at least one piece of code executable by a master device to control the master device to implement the steps of the low-latency control method for RS485 communication as described in the above embodiments. For example, it includes:
[0089] S100: Obtain the number of bytes in the current data frame to be sent and the serial port baud rate of the serial port expansion chip;
[0090] S200. Calculate the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate;
[0091] S300. Based on the expected time and hardware response delay time, determine the trigger time of the control command to pull down the driver enable terminal;
[0092] S400: Before or during the transmission of the data frame to be sent, a control command is sent to the IO expansion chip according to the control command trigger time, so that the driver enable terminal is pulled low within a specified time after the data frame is sent, and the RS485 communication module receives data.
[0093] Based on the same technical concept, this application also provides a computer program, which, when executed by a main control device, is used to implement the above-described method embodiments.
[0094] The computer program may be stored, in whole or in part, on a computer-readable storage medium packaged with the processor, or in part or in whole on a memory not packaged with the processor.
[0095] Based on the same technical concept, this application also provides a processor for implementing the above-described method embodiments. The processor can be a chip.
[0096] Example 4
[0097] Based on the same technical concept as the above embodiments, this application provides an electronic device. Figure 5 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application, such as... Figure 5 As shown, the electronic device 300 includes the low-latency control system 200 with RS485 communication as described in Embodiment 2.
[0098] The electronic device provided in this application significantly reduces the communication packet loss rate, enables stable and continuous high-speed data interaction, and can still operate stably under high-frequency communication, greatly enhancing the overall response performance and engineering practicality of the device, and is particularly suitable for intelligent sensing application scenarios that are sensitive to communication timing.
[0099] It is understood that the implementation methods of the low-latency control method for RS485 communication in the above embodiments are also applicable to the embodiments of this application and can achieve the same technical effect, so they will not be described again here.
[0100] In summary, the low-latency control method, system, storage medium, and device for RS485 communication provided in this application eliminate data reception conflicts and packet loss caused by the inherent latency of IO extended communication by estimating the serial data transmission time and triggering the control command of the IO extension chip to pull low the driver enable pin of the RS485 communication module in advance. Through hardware and software co-optimization, the driver enable pin is pulled low within a specified time after the serial port data transmission is completed, meeting the fast response requirements of high-speed RS485 slave devices, significantly reducing the data packet loss rate, and greatly improving communication reliability. Furthermore, high-speed communication compatibility can be achieved through algorithm optimization without changing the hardware design, offering significant advantages such as low cost, easy portability, and high compatibility, greatly expanding the application scope and engineering practicality of existing low-speed extension solutions.
[0101] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0102] The embodiments described above are merely examples of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these modifications and improvements all fall within the protection scope of this application.
[0103] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A low-latency control method for RS485 communication, characterized in that, The method is applied to a hardware communication system, which includes at least a main control chip, a serial port expansion chip, and an I / O expansion chip. The main control chip is connected to the serial port expansion chip through a first communication interface to send serial data, and the main control chip is connected to the I / O expansion chip through a second communication interface to control the driver enable terminal of the RS485 communication module. The method includes: Obtain the number of bytes in the current data frame to be sent and the serial port baud rate of the serial port expansion chip; Based on the number of bytes and the serial port baud rate, the estimated time required to send the data frame to be sent is calculated; the estimated time also includes an offset time, which represents the serial port startup delay time between when the driver enable terminal is pulled high and when the serial port expansion chip starts sending the data frame. Based on the estimated time and hardware response delay time, determine the trigger time for the control command to pull down the driver enable terminal; Before or during the transmission of the data frame to be sent, a control command is sent to the IO expansion chip according to the control command trigger time, so that the driver enable terminal is pulled low for a specified time after the data frame transmission ends, so that the RS485 communication module can receive data. The step of determining the control command trigger time for pulling down the driver enable terminal based on the estimated time and hardware response delay time includes: Set an additional hardware response latency time based on the serial port baud rate and the number of bytes; The control command trigger time is obtained by adding the reserved time to the estimated time and subtracting the hardware response delay time.
2. The low-latency control method for RS485 communication according to claim 1, characterized in that, The step of calculating the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate includes: Calculate the byte transmission time required to send one byte based on the serial port baud rate; The estimated time is calculated based on the byte transmission time and the number of bytes.
3. The low-latency control method for RS485 communication according to claim 1, characterized in that, The first communication interface is a serial peripheral interface (SPI), and the second communication interface is a bidirectional synchronous serial transmission bus interface (I2C).
4. A low-latency control system for RS485 communication, characterized in that, The system includes a main control module, a serial port expansion chip, an I / O expansion chip, and an RS485 communication module, wherein: The serial port expansion chip is connected to the main control module via the SPI bus, and the serial port expansion chip is used to expand at least one UART channel. The IO expansion chip is connected to the main control module via an I2C bus, and the IO expansion chip is used to provide programmable GPIO output; The RS485 communication module is connected to the serial port expansion chip and the IO expansion chip respectively, and the driver enable terminal of the RS485 communication module is connected to one GPIO terminal of the IO expansion chip. The main control module includes a communication control unit, which is used to determine the control command trigger time for pulling down the drive enable terminal based on the number of bytes of the current data frame to be sent and the serial port baud rate, and to send the control command for pulling down the drive enable terminal to the IO expansion chip according to the control command trigger time, so as to enable the RS485 communication module to quickly switch to the data receiving state after the data is sent. The communication control unit includes: The data acquisition subunit is used to acquire the number of bytes of the current data frame to be sent and the serial port baud rate of the serial port expansion chip; The first calculation subunit is used to calculate the estimated time required to send the data frame to be sent based on the number of bytes and the serial port baud rate; the estimated time also includes an offset time, which represents the serial port startup delay time between when the driver enable terminal is pulled high and when the serial port expansion chip starts sending the data frame. The second calculation subunit is used to determine the control command trigger time for pulling down the drive enable terminal based on the estimated time and the hardware response delay time. The instruction sending subunit is used to send a control instruction to the IO expansion chip according to the control command trigger time before or during the transmission of the data frame to be sent, so that the driver enable terminal is pulled low for a specified time after the data frame transmission ends, so that the RS485 communication module can receive data. The second calculation subunit is further configured to set an additional hardware response delay time based on the serial port baud rate and the number of bytes; and to obtain the control command trigger time by adding the reserved time to the estimated time and subtracting the hardware response delay time.
5. The low-latency control system for RS485 communication according to claim 4, characterized in that, The serial port expansion chip is a WK2124 chip, and the IO expansion chip is an NCA9555 chip.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the low-latency control method for RS485 communication as described in any one of claims 1-3.
7. An electronic device, characterized in that, The electronic device includes a low-latency control system for RS485 communication as described in any one of claims 4-5.
Citation Information
Patent Citations
Method and device for RS485 transceiving switching, electronic equipment and computer readable storage medium
CN117714565A
Type ii collector, and data collection method and system
WO2018107426A1