Two-way communication system and method

By introducing UART bidirectional communication and a heartbeat monitoring mechanism into the SPI communication system, the data transmission error caused by the inconsistency of the master-slave device startup timing was solved, and stable bidirectional communication among multiple slave devices was achieved, ensuring data correctness and system stability.

CN115203114BActive Publication Date: 2025-12-30UNICORE COMM INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210700993.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-20
Publication Date
2025-12-30
Estimated Expiration
2042-06-20

AI Technical Summary

Technical Problem

In SPI communication systems, data transmission errors can occur due to inconsistent startup timing between master and slave devices. This is especially true in the case of multiple slave devices, where it is difficult to ensure that multiple slave devices can initialize and receive data normally. Furthermore, SPI communication is highly complex, occupies many interface lines, and requires complex software control.

Method used

A bidirectional communication system is adopted, in which the master device communicates unidirectionally with the slave device via SPI and bidirectionally with the slave device via UART. A heartbeat monitoring mechanism and a watchdog mechanism are introduced to ensure that data transmission is only performed after the slave device has been initialized. GPIO is used to restart abnormal devices, thereby reducing the complexity of SPI communication and improving system stability.

Benefits of technology

It achieves stable bidirectional communication between master and slave devices, avoids data loss, improves system reliability and stability, simplifies SPI communication complexity, and reduces interface line usage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115203114B_ABST
    Figure CN115203114B_ABST
Patent Text Reader

Abstract

The application discloses a bidirectional communication system and method, which comprises a master device and at least one slave device; the master device and each slave device respectively comprises a first processing module, a master control module and a second processing module; the master control module of the master device or each slave device respectively communicates with the first processing module and the second processing module; the first processing module of the master device is arranged to communicate with the first processing module of each slave device through a first communication mode; and the second processing module of the master device is arranged to communicate with the second processing module of each slave device through a second communication mode. The bidirectional communication system and method realize stable bidirectional communication between the master device and the slave devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and more particularly to a two-way communication system and method. Background Technology

[0002] Currently, an SPI communication system includes one master device (hereinafter referred to as the master) and can have multiple slave devices (hereinafter referred to as slave devices). An SPI communication system requires four lines to achieve bidirectional communication: the serial clock line (CSK), the master input / slave output data line (MISO), the master output / slave input data line (MOSI), and the active-low slave select line (CS). The MOSI data line enables the master to send data to the slave, the MISO data line enables the slave to send data to the master, and the serial clock line is used for data synchronization. Data input and output occur simultaneously. SPI communication requires the slave device to start operating before the master begins sending data. However, in practical applications, there are issues with ensuring the master-slave device startup sequence. For example, if the master device starts and completes initialization first and begins writing to the SPI, but the slave device starts and initializes later, it will lead to SPI data transmission errors and inevitably cause SPI communication anomalies. This results in the master device sending a large amount of data, but the slave devices, regardless of how much data they send, will experience data loss. This is especially true in a master-slave configuration, where it is difficult to ensure that multiple slave devices initialize correctly and receive data correctly.

[0003] In SPI communication, each slave device communicates with the master device by configuring its chip select line to low. This requires independent signal usage, making it complex both in hardware and software. When there are multiple slave devices, each requires a chip select line, resulting in a significant increase in the master device's interface lines. All devices must use the same operating parameters, primarily ensuring consistent clock polarity and phase for proper functioning. The SPI NSS signal is the chip select signal, which can be enabled by hardware control. However, in practice, software operation is still required to control the NSS signal (high or low), necessitating software-based timing assurance. When there are multiple slave devices, different slave devices require different chip select lines, further complicating the software timing assurance. Summary of the Invention

[0004] This application provides a bidirectional communication system and method, which realizes stable bidirectional communication between a master device and multiple slave devices.

[0005] This application provides a two-way communication system, including a master device and at least one slave device;

[0006] The master device and each slave device respectively include a first processing module, a main control module and a second processing module;

[0007] The master control module of the master device or each slave device communicates bidirectionally with its respective first processing module and second processing module.

[0008] The first processing module of the master device is configured to communicate unidirectionally with the first processing module of each slave device through a first communication method.

[0009] The second processing module of the master device is configured to communicate bidirectionally with the second processing module of each slave device via a second communication method.

[0010] In one exemplary embodiment, the master control module of each slave device is configured to send specific information to the master device through the second processing module of the slave device in a second communication mode after the slave device completes the initialization operation of the first communication mode. The specific information is used to instruct the slave device to complete the initialization operation of the first communication mode.

[0011] In one exemplary embodiment, the master control module of each slave device is further configured to determine whether the specific information has been successfully sent after sending the characteristic information. If the information has not been successfully sent, the specific information is sent again until it is determined that the specific information has been successfully sent.

[0012] In one exemplary embodiment, the first processing module of the master device is configured to communicate unidirectionally with the first processing module of the slave device only after the second processing module of the master device receives specific information sent by the slave device.

[0013] In one exemplary embodiment, the main control module of the main device is configured to trigger its own watchdog timer and restart the main device when the first processing module and the second processing module of the main device malfunction.

[0014] In one exemplary embodiment, the master control module of the master device is further configured to monitor each slave device, and restart the slave device if it does not receive heartbeat information from a slave device within a preset monitoring period.

[0015] In one exemplary embodiment, the master control module of the master device and the master control module of any slave device are physically connected via GPIO;

[0016] The restarting of the slave device includes:

[0017] The master control module of the master device restarts the slave device by controlling the hard reset GPIO of the slave device.

[0018] In one exemplary embodiment, the first communication method is different from the second communication method.

[0019] In one exemplary embodiment, the first communication method is SPI communication.

[0020] The second communication method is UART communication.

[0021] This application provides a bidirectional communication method applied to a bidirectional communication system, the bidirectional communication system including a master device and at least one slave device; the master device and each slave device respectively include a first processing module, a main control module and a second processing module;

[0022] The master control module of the master device or each slave device communicates bidirectionally with its respective first processing module and second processing module.

[0023] The first processing module of the master device communicates unidirectionally with the first processing module of each slave device through a first communication method; the second processing module of the master device communicates bidirectionally with the second processing module of each slave device through a second communication method.

[0024] This application has the following advantages:

[0025] At least one embodiment of this application determines whether any of the at least one slave device has completed the initialization operation of the first communication method; when it is determined that any slave device has completed the initialization operation of the first communication method, the master device sends data to the slave device through the first communication method, thereby avoiding the data loss phenomenon caused by the inability of SPI communication to ensure the startup timing of master and slave devices, and ensuring the reliability of bidirectional communication of the system.

[0026] In one implementation of this application, data integrity is ensured by sending data from the slave device via the UART protocol.

[0027] In one implementation of this application, a heartbeat monitoring mechanism and a master device watchdog mechanism can be used to ensure the stability of the system.

[0028] Of course, any product implementing this application does not necessarily need to achieve all of the advantages described above at the same time.

[0029] Other features and advantages of this application will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the application. Other advantages of this application can be realized and obtained by means of the solutions described in the description and the accompanying drawings. Attached Figure Description

[0030] The accompanying drawings are used to provide an understanding of the technical solutions of this application and constitute a part of the specification. They are used together with the embodiments of this application to explain the technical solutions of this application and do not constitute a limitation on the technical solutions of this application.

[0031] Figure 1 This is a schematic diagram of a two-way communication system according to an embodiment of this application;

[0032] Figure 2 This is a schematic diagram of another bidirectional communication system according to an embodiment of this application. Detailed Implementation

[0033] Figure 1 This is a schematic diagram of a two-way communication system according to an embodiment of this application, such as... Figure 1 As shown, the bidirectional communication system of this embodiment includes a master device and at least one slave device; the master device and each slave device respectively include a first processing module, a main control module and a second processing module; the master device or the main control module of each slave device respectively communicates bidirectionally with their respective first processing module and second processing module; the first processing module of the master device is configured to communicate unidirectionally with the first processing module of each slave device through a first communication method; the second processing module of the master device is configured to communicate bidirectionally with the second processing module of each slave device through a second communication method.

[0034] The master and slave devices can be, for example, chips.

[0035] In one exemplary embodiment, the master control module of each slave device is configured to send specific information to the master device through the second processing module of the slave device in a second communication mode after the slave device completes the initialization operation of the first communication mode. The specific information is used to instruct the slave device to complete the initialization operation of the first communication mode.

[0036] The specific information is used to instruct the slave device to complete the initialization operation of the first communication mode; if the SPI communication mode is used, the specific information can be SPI_READY information.

[0037] It should be noted that after receiving specific information, the master device knows that the slave device has completed the initialization operation of the first communication method. Only under these circumstances will the master device send data to the slave device via the first communication method. If the slave device has not completed the initialization operation of the first communication method, the master device will not send data to the slave device. Only the master device sends data to the slave device via the first communication method; the slave device always sends data to the master device via the second communication method.

[0038] For example, in a scenario with one master device and one slave device, after the slave device completes the SPI communication initialization, it sends an SPI_READY message to the master device via UART. Only after receiving this message will the master device send data to the slave device via SPI communication. This avoids data transmission errors caused by incorrect startup timing, voltage levels, or other factors that could affect the stability of SPI operation.

[0039] In one exemplary embodiment, the master control module of each slave device is further configured to determine whether the specific information has been successfully sent after sending the characteristic information. If the information has not been successfully sent, the specific information is sent again until it is determined that the specific information has been successfully sent.

[0040] For example, after the slave device sends the specific information (e.g., SPI_READY information), it listens to whether it has received data sent by the master device through the first communication method (e.g., SPI communication method); if it does not receive data sent by the master device through the first communication method for a preset time period (e.g., 2 seconds), it sends the specific information to the master device again through the second communication method (e.g., UART communication method) until it receives data sent by the master device through the first communication method.

[0041] In one exemplary embodiment, the first processing module of the master device is configured to communicate unidirectionally with the first processing module of the slave device only after the second processing module of the master device receives specific information sent by the slave device.

[0042] In one exemplary embodiment, the main control module of the main device is configured to trigger its own watchdog timer and restart the main device when the first processing module and the second processing module of the main device malfunction.

[0043] Because, for example, SPI communication does not have specified flow control and no acknowledgment mechanism to confirm whether data has been received, when the slave device goes offline abnormally, the master device cannot confirm the status of the slave device, does not know whether the slave device still exists, and therefore cannot ensure the stable operation of the entire system.

[0044] To ensure the stable operation of the entire system, in one exemplary embodiment, the master control module of the master device is further configured to monitor each slave device, and restart the slave device if it does not receive heartbeat information from a slave device within a preset monitoring period.

[0045] For example, when monitoring each slave device, if a heartbeat message is received from the slave device within a preset time (e.g., 10 seconds), the corresponding slave device is considered normal; if no heartbeat message is received from the slave device after the preset time (e.g., 10 seconds), the corresponding slave device is considered abnormal. When a slave device is abnormal, it needs to be restarted.

[0046] In one exemplary embodiment, the master control module of the master device and the master control module of any slave device are physically connected via GPIO; restarting the slave device includes:

[0047] The master control module of the master device restarts the slave device by controlling the hard reset GPIO of the slave device.

[0048] In one exemplary embodiment, after the slave device sends the specific information, it determines whether the specific information was sent successfully. If it was not sent successfully, the specific information is sent again until it is determined that the specific information was sent successfully.

[0049] In one exemplary embodiment, the master device periodically determines whether each slave device is normal, and when a slave device is determined to be abnormal, it controls the abnormal slave device to restart.

[0050] In one exemplary embodiment, the first communication method is different from the second communication method. For example, the first communication method is SPI communication; the second communication method is UART communication.

[0051] The application scenarios of this application include, but are not limited to, scenarios where the master device sends a large amount of data to the slave device, and the slave device sends a small amount of data to the master device. It can be applied to any embedded system application field where there is a need for stable and reliable bidirectional communication between microcontrollers or between a microcontroller and a sensor, such as artificial intelligence, measurement and mapping, mechanical control, the Internet of Things, autonomous driving, and wearable devices.

[0052] In this embodiment, the master device sends data to the slave device via a first communication method, and the slave device sends data to the master device via a second communication method. That is, through the cooperation of the first and second communication methods, stable bidirectional communication between the master device and the slave device is achieved.

[0053] Figure 2 This is a schematic diagram of another bidirectional communication system according to an embodiment of this application, such as... Figure 2As shown, it includes a master device and a slave device. The master device includes an SPI processing module (corresponding to the first processing module of the master device), a master control module, and a UART processing module (corresponding to the second processing module of the master device). The slave device includes an SPI processing module (corresponding to the first processing module of the slave device), a master control module, and a UART processing module (corresponding to the second processing module of the slave device).

[0054] 1) SPI processing module in the master device

[0055] This module periodically transmits the SPI status to the master control module and operates according to the master control module's control logic. It controls the enable signal of the slave device's chip select and generates a clock signal for data synchronization. Regarding MOSI and MISO, this solution only uses MOSI and does not use MISO; it only supports one-way communication. The master device sends data to the slave device via SPI, but the slave device does not send data to the master device via SPI.

[0056] 2) The main control module in the main equipment

[0057] This module collects and summarizes information from the UART and SPI processing modules to control the overall operation of the master module. The master module communicates with the SPI and UART processing modules via shared memory. When either the SPI or UART processing module malfunctions, the master module's watchdog is triggered, restarting the master device. Based on slave device information sent by the UART processing module, the module monitors the slave modules. If a heartbeat message is not received from a slave module, a hard reset of the corresponding slave module is triggered, restarting the slave device through GPIO write operations.

[0058] 3) UART processing module in the main equipment

[0059] This module communicates with the slave device's UART processing module via UART to synchronize information between the master and slave devices. It sends slave device information and the master device's UART status information to the master control module, and sends master device information to the slave device via serial port.

[0060] 4) SPI processing module in the device

[0061] This module periodically transmits SPI status to the master control module and operates according to the master control module's control logic. It synchronizes data with the master device based on the master device's clock signal. It receives data from the master device via the MOSI signal line.

[0062] 5) From the main control module in the device

[0063] This module collects and summarizes information from the UART and SPI processing modules to control the overall operation of the slave module. The master module communicates with the SPI and UART processing modules via shared memory. It periodically generates heartbeat information, which is sent to the master device via the UART processing module. The master device uses this heartbeat information to monitor the slave device and ensure its normal operation.

[0064] The master device is the central controller of the entire system. Slave devices do not have an internal watchdog mechanism. The slave devices implement a watchdog mechanism by cooperating with the master device. The master device restarts the slave devices through a hard reset, which improves the robustness of the slave devices.

[0065] 6) From the UART processing module in the device

[0066] This module communicates with the master device's UART processing module via UART to synchronize information between the master and slave devices. It sends master device information and slave device UART status information to the master control module, and sends slave device information to the master device via serial port.

[0067] This solution addresses the scenario where the master device sends a large amount of data to the slave device, while the slave device sends a small amount of data to the master device, effectively solving the data loss problem in SPI bidirectional communication.

[0068] The scheme of using UART and SPI for communication ensures the timing of the master and slave devices, avoiding SPI communication abnormalities caused by timing errors.

[0069] This solution uses only the Serial Clock line (CSK), Master Input / Slave Output line (MOSI), and Active Low Slave Select line (CS) for SPI communication, omitting the Master Output / Slave Input data line (MOSI). Data transmission from the slave device to the master is achieved via UART, reducing the complexity of SPI communication and improving its robustness.

[0070] UART communication enables the synchronization of critical information between master and slave devices. UART parity checking can perform error checking on the transmitted critical information.

[0071] The master device receives information from the slave device via UART through a protection mechanism. To ensure that the master device can receive the SPI_READY information normally, the slave device listens for SPI data after each time it sends the SPI_READY information via UART. If it does not receive data sent by the master device via SPI after more than 2 seconds, it sends the SPI_READY information to the master device again via UART. This cycle continues until the slave device successfully receives the SPI data sent by the master device.

[0072] The heartbeat monitoring mechanism involves the slave device periodically sending heartbeat information to the master device via UART. The master device monitors the status of the slave device based on the heartbeat information sent by the slave device. If no heartbeat information is received from the slave device for more than 10 seconds, it can be considered that the slave device is abnormal. The master device will operate the GPIO that controls the hard reset of the slave device to restart the slave device and ensure the stability of the entire system.

[0073] This application embodiment achieves stable bidirectional communication between a master device and multiple slave devices by forming a logical closed loop through the cooperation of SPI and UART communication. Four protection mechanisms ensure the reliability of bidirectional communication, the correctness of data, and the stability of the entire system: a slave device heartbeat monitoring mechanism, an SPI timing protection mechanism, a master device watchdog mechanism, and a protection mechanism for the master device receiving slave device information via UART. In actual projects, the usability and reliability of this design scheme have been confirmed through system verification using tens of thousands of UC4C0 chips as master devices and other microcontrollers or sensors as slave devices.

[0074] This application also provides a bidirectional communication method applied to a bidirectional communication system, the bidirectional communication system including a master device and at least one slave device; the master device and each slave device respectively include a first processing module, a main control module and a second processing module;

[0075] The master control module of the master device or each slave device communicates bidirectionally with its respective first processing module and second processing module.

[0076] The first processing module of the master device communicates unidirectionally with the first processing module of each slave device through a first communication method; the second processing module of the master device communicates bidirectionally with the second processing module of each slave device through a second communication method.

[0077] This application describes several embodiments, but these descriptions are exemplary and not restrictive, and it will be apparent to those skilled in the art that many more embodiments and implementations are possible within the scope of the embodiments described herein. Although many possible combinations of features are shown in the drawings and discussed in the detailed description, many other combinations of the disclosed features are also possible. Unless specifically limited, any feature or element of any embodiment may be used in combination with, or may replace, any feature or element of any other embodiment.

[0078] Any feature shown and / or discussed in this application may be implemented individually or in any suitable combination.

[0079] Furthermore, in describing representative embodiments, the specification may have presented methods and / or processes as a specific sequence of steps. However, the method or process should not be limited to the specific order of steps described herein, to the extent that it does not depend on such a specific order. Other sequences of steps are possible, as will be understood by those skilled in the art.

[0080] It will be understood by those skilled in the art that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

Claims

1.A bidirectional communication system, characterized in that, a master device and at least one slave device are included; the master device and each slave device respectively include a first processing module, a master control module and a second processing module; the master control module of the master device or each slave device respectively communicates with the first processing module and the second processing module of the respective device in a bidirectional manner; the first processing module of the master device is configured to communicate with the first processing module of each slave device in a unidirectional manner through a first communication mode; the second processing module of the master device is configured to communicate with the second processing module of each slave device in a bidirectional manner through a second communication mode; the first communication mode is different from the second communication mode; the master control module of each slave device is configured to send specific information to the master device through the second processing module of the slave device in the second communication mode after the slave device completes the initialization operation of the first communication mode, and the specific information is used to indicate that the slave device completes the initialization operation of the first communication mode; the first processing module of the master device is configured to communicate with the first processing module of the slave device in a unidirectional manner through the first communication mode only after the second processing module of the master device receives the specific information sent by the slave device. 2.The bidirectional communication system of claim 1, characterized in that, the master control module of each slave device is further configured to determine whether the sending of the specific information is successful after sending the specific information, and if the sending is not successful, the specific information is sent again until the sending of the specific information is determined to be successful. 3.The bidirectional communication system of claim 1, characterized in that, the master control module of the master device is configured to trigger a watchdog of itself and restart the master device when the first processing module and the second processing module of the master device are abnormal. 4.The bidirectional communication system of claim 1, characterized in that, the master control module of the master device is further configured to monitor each slave device, and restart a slave device when heartbeat information of the slave device is not received within a preset monitoring period. 5.The bidirectional communication system of claim 3, characterized in that, the master control module of the master device and the master control module of any slave device are physically connected through a GPIO; the restarting of the slave device includes: the master control module of the master device restarts the slave device by controlling a hard reset GPIO of the slave device. 6.The bidirectional communication system of claim 1, characterized in that, the first communication mode is an SPI communication mode; the second communication mode is a UART communication mode. 7.A bidirectional communication method applied to a bidirectional communication system, characterized in that, the bidirectional communication system includes a master device and at least one slave device; the master device and each slave device respectively include a first processing module, a master control module and a second processing module; the master control module of the master device or each slave device respectively communicates with the first processing module and the second processing module of the respective device in a bidirectional manner; The first processing module of the master device respectively performs unidirectional communication with the first processing module of each slave device through a first communication mode; the second processing module of the master device respectively performs bidirectional communication with the second processing module of each slave device through a second communication mode; The first communication mode is different from the second communication mode; The master control module of each slave device sends specific information to the master device through the second processing module of the slave device in the second communication mode after the slave device completes the initialization operation of the first communication mode, and the specific information is used to indicate that the slave device completes the initialization operation of the first communication mode; The first processing module of the master device performs unidirectional communication with the first processing module of the slave device through the first communication mode only after the second processing module of the master device receives the specific information sent by the slave device.

Citation Information

Patent Citations

  • SPI hardware structure system and operation process thereof

    CN110399318A

  • Method for achieving multi-machine communication based on I2C bus and multi-machine communication system

    CN112416841A