Communication bus control method and single-master communication system
By listening to the bus idle period and broadcasting the bus preemption message in the RS-485 bus communication system, the data conflict problem caused by multiple masters is solved, and a smooth bus control takeover is achieved, ensuring the stability and reliability of the communication system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU KANGBEI MOTOR
- Filing Date
- 2025-12-15
- Publication Date
- 2026-05-08
AI Technical Summary
In RS-485 bus communication systems, when a new master device is connected, bus data conflicts and communication anomalies occur due to multiple masters.
By monitoring the bus idle period, a preset bus preemption message is broadcast, causing the second master device to switch from master mode to slave mode, and the first master device to switch back to master mode, ensuring that the preemption operation is performed during the bus idle period and avoiding data conflicts.
It implements a "deterministic safe harbor" strategy that achieves precise synchronization with the existing protocol clock cycle, ensuring smooth and reliable preemption actions, non-interference takeover of bus control, and avoiding data packet collision issues.
Smart Images

Figure CN121333844B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of communication technology, and in particular to a communication bus control method and a single-host communication system. Background Technology
[0002] The RS-485 bus, due to its advantages such as high anti-interference capability from differential signal transmission, support for multiple nodes, and long transmission distance, is widely used for device communication in industrial automation, building automation, and smart homes. In a typical RS-485 communication system, a master-slave communication architecture is usually adopted. In this architecture, there is only one master on the bus, and the rest are slave devices. The master initiates communication by periodically polling each slave device, sending commands or reading status information, while the slave devices passively respond to the master's requests. This single-master polling mechanism has a simple structure, clear communication timing, and effectively avoids data conflicts on the bus, ensuring communication stability and reliability.
[0003] For example, in a temperature control system, a central temperature controller can act as the master, responsible for polling and controlling multiple slave devices such as fan drive boards and sensors. However, as system functions become more complex and intelligent, it is often necessary to introduce external monitoring equipment, such as a host computer for system diagnostics, data analysis, or parameter configuration. When this host computer is connected to an RS-485 bus, it also needs to actively send query commands to each slave device to obtain the required information; that is, it also needs to act as the master.
[0004] At this point, two hosts appear on the RS-485 bus: the existing central thermostat and the newly connected host computer. Each host will attempt to occupy the RS-485 bus to send data according to its own logic and timing. This can easily lead to multiple hosts sending signals to the RS-485 bus simultaneously, causing physical signal collisions, or data "packet collisions." Data packet collisions result in corrupted messages, which the receiver cannot correctly parse, ultimately paralyzing the entire RS-485 bus communication and rendering it unable to function properly. Summary of the Invention
[0005] This disclosure provides a communication bus control method and a single-master communication system, which aims to solve the problem of bus data conflict and communication abnormality caused by multiple masters when a new master device needs to connect to an existing single-master polling communication system.
[0006] The technical solution disclosed herein is implemented as follows:
[0007] In a first aspect, this disclosure provides a communication bus control method applied to a first master device. The communication bus includes a second master device and at least one slave device. The communication bus control method includes: monitoring the bus idle period of the communication bus, the bus idle period being a period of time after the second master device and at least one slave device complete a round of query frames and response frames; during the bus idle period, broadcasting a preset bus preemption message through the communication bus to enable the second master device to switch from master working mode to slave working mode; and switching the working mode back to master working mode.
[0008] Secondly, this disclosure provides a communication bus control method applied to a second master device. The communication bus control method includes: switching the working mode to a slave working mode in response to a bus preemption message sent by a first master device.
[0009] Thirdly, this disclosure provides a single-master communication system, comprising: a communication bus, a first master device, a second master device, and at least one slave device, wherein the first master device, the second master device, and at least one slave device are connected via the communication bus; the first master device is configured to listen to a bus idle period of the communication bus, the bus idle period being a duration after the second master device and at least one slave device complete a round of query frames and response frames; and, during the bus idle period, to broadcast a preset bus preemption message via the communication bus; the second master device is configured to switch its operating mode to slave operating mode in response to the received bus preemption message sent by the first master device; the first master device is further configured to switch its operating mode to master operating mode.
[0010] Fourthly, this disclosure provides a communication bus control device. The communication bus includes a second master device and at least one slave device. The device includes: a listening section configured to listen to the bus idle period of the communication bus, the bus idle period being a duration after the second master device and at least one slave device complete a round of query frames and response frames; a communication section configured to broadcast a preset bus preemption message through the communication bus during the bus idle period, so as to switch the second master device from master working mode to slave working mode; and a mode switching section configured to switch the working mode to master working mode.
[0011] Fifthly, this disclosure provides a communication bus control device, which includes: a state switching section configured to switch the operating mode to a slave operating mode in response to a bus preemption message sent by a first master device.
[0012] In a sixth aspect, this disclosure provides an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the communication bus control method as described in the first aspect and / or the second aspect.
[0013] In a seventh aspect, this disclosure provides a computer-readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the communication bus control method as described in the first aspect and / or the second aspect.
[0014] Eighthly, this disclosure provides a computer program product, wherein the computer program product includes a computer program or instructions that, when the computer program product is run on a processor, cause the processor to execute the computer program or instructions to implement the steps of the communication bus control method as described in the first aspect and / or the second aspect.
[0015] Ninthly, this disclosure provides a chip including a processor and a communication interface coupled to the processor, the processor being used to run programs or instructions to implement the steps of the communication bus control method as described in the first aspect and / or the second aspect.
[0016] This disclosure provides a single-master communication system, comprising: a communication bus, a first master device, a second master device, and at least one slave device, wherein the first master device, the second master device, and at least one slave device are connected via the communication bus; the first master device sends a bus preemption message with a specific data combination to the communication bus during bus idle periods. Because no other device (including the second master device 120 and all slave devices) sends data on the communication bus during the bus idle periods according to the original master-slave protocol, the transmission of the bus preemption message is completely staggered in time from all normal business communications, thus completely avoiding data conflicts at the physical level. This mechanism is based on a "deterministic safe harbor" strategy of precise synchronization with the existing protocol's clock speed, ensuring the smoothness, reliability, and interference-free nature of the preemption action itself, avoiding the data "packet collision" problem additionally caused by the preemption action. The first master device can smoothly take over control of a running single-master communication bus in a predictable, synchronous, and conflict-free manner. Attached Figure Description
[0017] Figure 1 This is a schematic diagram of the structure of a single-host communication system provided in this disclosure.
[0018] Figure 2 This is a timing diagram of a timing signal provided in this disclosure.
[0019] Figure 3 This disclosure provides a schematic diagram of the interaction process between a first master device and a second master device.
[0020] Figure 4 This is a schematic diagram of the interaction process between the first master device and the second master device provided in this disclosure.
[0021] Figure 5 This is a schematic diagram illustrating the interaction process between the first master device and the second master device, as provided in this disclosure.
[0022] Figure 6 This is a flowchart illustrating a process for restoring the host operating mode of a second master device, as provided in this disclosure.
[0023] Figure 7 This is a schematic diagram illustrating another process for restoring the host operating mode of the second master device provided in this disclosure.
[0024] Figure 8 This is a structural block diagram of a communication bus control device provided in this disclosure.
[0025] Figure 9 A structural block diagram of another communication bus control device provided in this disclosure.
[0026] Figure 10 This is a schematic diagram of the hardware structure of an electronic device provided in this disclosure. Detailed Implementation
[0027] The technical solutions in the embodiments of this disclosure will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure are within the scope of protection of this disclosure.
[0028] See Figure 1 , Figure 1 A schematic diagram of the architecture of a single-host communication system 10 according to an embodiment of the present disclosure is shown. The single-host communication system 10 can be a temperature control system, a building automation system, an industrial automation system, or any single-host polling system that uses an RS-485 bus for communication.
[0029] The single-master communication system 10 includes a second master device 120 and at least one slave device ( Figure 1 Slave devices 1301 and 1302 and a first master device 110 are illustrated in the example. These devices are physically connected and communicate data via a shared communication bus 140, such as an RS-485 bus.
[0030] In the initial or normal operating state of the system, the second master device 120 operates as the primary host in the system. For example, in a temperature control system, the second master device 120 can be a central thermostat. It operates in master mode and is responsible for actively initiating all communications. Specifically, the second master device 120 sequentially and periodically sends query frames to each slave device 1301 and slave device 1302 on the communication bus 140 according to a polling list and time period preset in its internal memory, in order to control the behavior of slave devices 1301 and 1302 (e.g., adjusting fan speed) or read the status of slave devices 1301 and 1302 (e.g., obtaining temperature readings).
[0031] Slave devices 1301 and 1302 can be peripheral devices such as fan drive boards, temperature sensors, and humidity sensor modules. The slave devices are always in a passive position in the communication protocol, i.e., they operate in slave mode. The slave devices do not actively send any data to the communication bus 140; they only respond within the time specified in the protocol after receiving an inquiry frame from the second master device 120 whose address field matches their own. The slave device then sends a response frame to the second master device 120 via the communication bus 140.
[0032] The first master device 110 is an external device that can temporarily access the single-host communication system 10. For example, the first master device 110 can be a laptop, a dedicated handheld diagnostic instrument, or a host computer application used for system maintenance, firmware upgrades, advanced diagnostics, or data acquisition. When the first master device 110 needs to perform advanced operations on the single-host communication system 10, it needs to obtain control of the communication bus 140, that is, temporarily become a new master in the single-host communication system 10.
[0033] The core technical concept of this disclosure lies in proposing and standardizing a complete set of application layer protocols, enabling the first master device 110 to safely and conflict-free take over bus control from the second master device 120.
[0034] Please see Figure 2 , Figure 2 A detailed timing diagram of the bus signals in the embodiments of this application is shown, which reveals the fundamental principle by which this application achieves conflict-free preemption. During normal polling, the signal activity on the bus exhibits a clear, periodic rhythm. Each query frame is followed by an acknowledgment frame, and the communication bus 140 is in an idle state between the acknowledgment frame of the previous cycle and the query frame of the next cycle.
[0035] First, the second master device 120 (the original host) sends an interrogation frame 210 on the communication bus 140 to a target slave device (e.g., slave device 1301). The transmission of the interrogation frame 210 takes a certain amount of time, which depends on the message length and the bus baud rate. Figure 2 In the middle, t0 indicates the duration from the start to the end of the transmission of query frame 210.
[0036] After the last bit of the interrogation frame 210 is transmitted on the communication bus 140 (i.e., t0), the communication bus 140 enters a brief silence period. After fully receiving and parsing the interrogation frame, the slave device 1301 needs a certain processing time to prepare the response data. This time interval from the end of the interrogation frame 210 to the start of the response frame 220 is defined in this disclosure as the response delay t1 of the slave device 1301. The length of t1 mainly depends on the processing power of the microcontroller inside the slave device 1301 and the implementation efficiency of the protocol stack.
[0037] After a delay of t1, slave device 1301 begins to send an acknowledgment frame 220 on communication bus 140. The transmission of acknowledgment frame 220 also requires a certain amount of time. Figure 2 In this context, t2 represents the duration from the start of transmission to the end of transmission of the acknowledgment frame 220.
[0038] After the last bit of the response frame 220 is transmitted on the communication bus 140, the complete query-response interaction with slave device 1301 ends. At this time, the communication bus 140 enters a physically idle state. The second master device 120 will have a preset waiting time before it initiates a poll for the next slave device (e.g., slave device 1302). This time interval from the end of the current response frame to the start of the next query frame is a physical idle window that must exist on the communication bus 140 after a complete interaction cycle and before the start of the next interaction, and is defined in this disclosure as the bus idle period t3.
[0039] In this embodiment of the disclosure, the first master device 110 does not attempt to preempt the bus at any time, but must precisely identify and utilize the bus idle period t3. For example... Figure 3 As shown, the first master device 110 performs the following steps S301, S302 and S304, and the second master device 120 performs the following step S303.
[0040] In step S301, the idle period of the communication bus is monitored.
[0041] After the first master device 110 physically connects to the communication bus 140 through its communication interface, its internal communication application first sets its communication interface to a pure receive mode, i.e., a "listen-only" monitoring mode. During this phase, the first master device 110 continuously receives all data frames appearing on the communication bus 140 and stores them in its internal receive buffer for analysis, but the first master device 110 does not actively send any data. This preemptive method of determining when the communication bus 140 is idle before intervening, compared to a brute-force preemptive method, ensures that the access behavior of the first master device 110 itself will not cause any interference to the running single-host communication system 10. After a complete interaction of a query frame 210 and a response frame 220 is detected, it is determined that the communication bus 140 is in an idle period t3.
[0042] In step S302, during the bus idle period, a preset bus preemption message is broadcast through the communication bus.
[0043] To enable those skilled in the art to implement this disclosure without difficulty, the Modbus communication protocol, widely used in industrial control, is used as an example to illustrate bus preemption messages. However, this disclosure is not limited to the Modbus protocol; any custom protocol capable of defining addresses and function codes may be applied.
[0044] The bus preemption message is a control message with special meaning at the application layer. Its key lies in using reserved or infrequently used field values in the protocol to assign it "preemption" semantics. In a specific implementation, the structure of this bus preemption message can be as shown in Table 1.
[0045] Table 1. Structure of Bus Preemption Messages
[0046]
[0047] According to the Modbus protocol, 0xFF is used as the system-level broadcast address in many practices. Using the broadcast address ensures that all devices on the communication bus 140, especially the second master device 120, will unconditionally receive and process the message.
[0048] In the Modbus protocol, function code 0x50 (decimal 80) is not used in regular read / write operations, or falls within the scope of user-defined function codes. This disclosure defines it as the unique "bus preemption request" instruction. When the second master device 120 receives a bus preemption message with function code 0x50, it knows that this is a signaling for the transfer of control, rather than a normal service data request.
[0049] 0x 00 00 00 00 is a data segment that can be defined as needed. In the simplest implementation, it can be a fixed padding value, such as all zeros. In more advanced implementations, this data segment can be used to carry authentication information, preemption priority, etc.
[0050] 0xD418 is a cyclic redundancy check (CRC) code calculated based on the preceding byte of the bus preemption message (FF 50 00 00 00 00). The CRC check ensures the integrity and accuracy of the bus preemption message during transmission, preventing erroneous commands from being executed due to bus noise.
[0051] The first master device 110 continuously and in real time analyzes the data in its receive buffer. It needs to identify a pair of matching, consecutive, and valid communication messages based on the frame format of the communication protocol (such as the commonly used Modbus protocol) adopted by the single-master communication system 10.
[0052] An effective communication cycle consists of two core parts: First, an inquiry frame 210 with the source address of the second master device 120 and the destination address of a slave device (e.g., slave device 1301). Second, a response frame 220 that follows with the source address of the slave device 1301 and the destination address of the second master device 120.
[0053] Both data frames (interrogation frame 210 and response frame 220) must pass the data integrity checks specified by the protocol, such as Cyclic Redundancy Check (CRC), to confirm that the data has not been corrupted by noise or collisions during transmission. By successfully identifying and verifying a complete question-and-answer interaction, the first master device 110 can not only confirm the existence of an active primary host (i.e., the second master device 120) on the communication bus 140, but also accurately synchronize with the current system's communication rhythm, preparing for the next step of determining the preemption window.
[0054] When the first master device 110 detects the precise moment that the last bit of the acknowledgment frame 220 has been transmitted, it determines that the communication bus 140 has entered an available bus idle period t3. To ensure timely operation, the first master device 110 may start a high-precision timer to prepare for the next operation within the t3 period. The typical length of t3 may be between a few milliseconds and tens of milliseconds, depending on the polling cycle setting of the second master device 120 and the number of slave devices.
[0055] After determining that the t3 period has begun, the first master device 110 will broadcast a pre-formatted bus preemption message to the communication bus 140. The broadcast must be completed before the end of the t2 period (i.e., before the second master device 120 sends the next query frame) to ensure no conflicts.
[0056] In step S303, in response to receiving a bus preemption message, the working mode is switched to slave working mode.
[0057] After successfully sending the bus preemption message, the first master device 110 unilaterally considers itself to have gained control of the communication bus 140. Its internal communication state machine switches from "listening mode" to "master mode". Subsequently, the first master device 110 can, according to its own task logic, begin sending query frames or control commands to other devices on the communication bus 140 (including the second master device 120, which should now be in slave mode, and all slave devices, such as slave devices 1301 and 1302), and execute advanced functions such as deep system status monitoring, online device parameter configuration, and batch firmware upgrades.
[0058] In step S304, the working mode is switched to host working mode.
[0059] When the second master device 120 is in host mode, it will also continuously listen to the communication bus 140 during its own polling cycle's t2 idle period (i.e., before completing a question-and-answer interaction and preparing to initiate the next query). If a valid bus preemption message is received from the communication bus 140 at this time, the second master device 120 will parse the message and, based on its special broadcast address (e.g., 0xFF) and preset function code (e.g., 0x50), identify it as a legitimate bus preemption instruction.
[0060] In response to the bus preemption command parsed from the bus preemption message, the second master device 120 immediately switches from master mode to slave mode, thereby stopping the next round of polling. Through this well-defined mode transition triggered by an external command, the second master device 120 orderly and controllably transfers control of the communication bus 140 to the first master device 110, thus resolving the root cause of multi-master conflicts.
[0061] In this embodiment, the first master device 110 sends a bus preemption message with a specific data combination to the communication bus 140 during the bus idle period. Since no other device (including the second master device 120 and all slave devices) sends data on the communication bus 140 during the bus idle period according to the original master-slave protocol, the transmission of the bus preemption message is completely staggered from all normal business communications in terms of timing, thus completely avoiding data conflicts at the physical level. This mechanism is based on a "deterministic safe harbor" strategy that precisely synchronizes the existing protocol beat, ensuring the smoothness, reliability, and interference-free nature of the preemption action itself, avoiding the data "packet collision" problem caused by the preemption action. The first master device 110 can smoothly take over control of a running single-master communication bus in a predictable, synchronous, and conflict-free manner.
[0062] In some embodiments, to make the handover process of control between the first master device 110 and the second master device 120 more robust and verifiable, such as Figure 4 As shown, the first master device 110 executes the following steps S401, S402 and S405, and the second master device 120 executes the following steps S403 and S404.
[0063] In step S401, the idle period of the communication bus is monitored.
[0064] In step S402, during the bus idle period, a preset bus preemption message is broadcast through the communication bus.
[0065] In step S403, in response to receiving a bus preemption message, a response message is sent to the first master device.
[0066] During the bus idle period t3, the first master device 110 sends a bus preemption message. After the second master device 120 receives and successfully parses the bus preemption message, it replies to the communication bus 140 with a "preemption confirmation" response message in a specific format when it is ready to switch to slave mode. For example, this message can be a simple response to the original preemption message, with the function code still being 0x50, but the data segment containing a status code indicating "acknowledgment".
[0067] In step S404, the working mode is switched to slave working mode.
[0068] In step S405, upon receiving a response message from the second master device, the operating mode is switched to master operating mode.
[0069] After sending a bus preemption message, the first master device 110 does not immediately enter the host operating mode. Instead, it enters a brief "waiting for confirmation" state. Only after receiving a "preemption confirmation" response message from the second master device 120 within the set timeout period does the first master device 110 officially switch to the host operating mode. If no "preemption confirmation" response message is received within the timeout period, the preemption is considered to have failed, and it may retry during the next bus idle period t3.
[0070] This two-way handshake mechanism prevents potential conflicts caused by the second master device 120 failing to successfully process bus preemption messages (e.g., message loss due to transient interference), making the handover of control more reliable.
[0071] Steps S401, S402 and S404 can be referred to the descriptions of steps S301, S302 and S304 above, and will not be repeated here.
[0072] In some complex scenarios, multiple external devices may need to connect to the communication bus 140. The first master device 110, which has successfully preempted the bus, can be understood as the master in the entire single-master communication system 10. After the first master device 110 successfully preempts the bus, it becomes the second master device 120. When other bus preemption messages are received, priority management of the preemption requests corresponding to the bus preemption messages is required. Therefore, in some embodiments, such as Figure 5 As shown, the first master device 110 performs the following steps S501, S502 and S506, and the second master device 120 performs the following steps S503 to S505.
[0073] In step S501, the idle period of the communication bus is monitored.
[0074] In step S502, during the bus idle period, a preset bus preemption message is broadcast through the communication bus.
[0075] In step S503, the bus preemption message is parsed to obtain the priority function code.
[0076] In step S504, if the priority indicated by the priority function code is higher than the current task priority, a response message is sent to the first master device.
[0077] Bus preemption messages include a priority function code, which indicates the priority of the bus preemption request corresponding to the message. For example, 0x01 indicates low priority (such as routine data monitoring), and 0xEE indicates the highest priority (such as emergency fault diagnosis or firmware upgrade).
[0078] After receiving a bus preemption message, the second master device 120 parses the priority function code and compares it with the priority of the task it is currently executing or about to execute. The second master device 120 will only switch operating modes if the priority of the bus preemption request corresponding to the received priority function code is higher than the priority of the current task.
[0079] This mechanism allows preemption among multiple "first master devices". A higher-priority first master device can preempt a lower-priority temporary first master device 110 that has already gained control through preemption, thereby enabling more granular bus access control.
[0080] In step S505, the working mode is switched to slave working mode.
[0081] In step S506, upon receiving a response message from the second master device, the operating mode is switched to master operating mode.
[0082] Steps S501, S502, S505 and S506 can be referred to the descriptions of steps S301, S302, S304 and S405 above, and will not be repeated here.
[0083] To prevent unauthorized external devices from maliciously preempting the communication bus 140 and thus disrupting the normal operation of the entire single-host communication system 10, security authentication elements can be added to the preemption protocol. In some feasible implementations, the bus preemption message can also include a verification code. This verification code can be a dynamic password included in the data segment of the bus preemption message or a cryptographic signature based on a shared key.
[0084] Before preemption, the first master device 110 needs to obtain a one-time dynamic token from an authentication server via an out-of-band channel (such as Ethernet) or a preset algorithm. The first master device 110 sends this token in the data segment of the preemption message. Upon receiving the preemption message, the second master device 120 also obtains the token from the authentication server in the same way or verifies its validity locally. Only after successful token verification does the second master device 120 perform a working mode switch. This mechanism greatly enhances the security of the industrial control bus and is an important technical means to prevent network attacks and unauthorized intrusions.
[0085] When the first master device 110 finishes its work, or when the first master device 110 experiences a communication failure, causing the communication bus 140 to be idle, the second master device 120 switches its working mode to host working mode, so that the entire single host communication system 10 returns to its initial and stable working state.
[0086] Specifically, in some embodiments, such as Figure 6 As shown, the first master device 110 executes the following steps S601, S602 and S604, and the second master device 120 executes the following steps S603, S605 and S606.
[0087] In step S601, the idle period of the communication bus is monitored.
[0088] In step S602, during the bus idle period, a preset bus preemption message is broadcast through the communication bus.
[0089] In step S603, in response to receiving a bus preemption message, the working mode is switched to slave working mode.
[0090] In step S604, the working mode is switched to host working mode.
[0091] Steps S601 to S604 can be referred to the description of steps S301 to S304 above, and will not be repeated here.
[0092] In step S605, the status of the communication bus is obtained.
[0093] In step S606, if the duration of the communication bus being idle is greater than the duration threshold, the slave device working mode is switched to the master working mode.
[0094] The communication bus 140 has two states: idle and occupied. The second master device 120 continuously monitors the communication bus 140. Once any valid bus communication is detected, it immediately resets the value of the idle timer to zero and then continues monitoring. Resetting the value of the idle timer to zero indicates that the current master (i.e., the first master device 110) is still working normally and bus control does not need to be reclaimed.
[0095] If the communication bus 140 remains silent, the idle timer will continuously increment. The second master device 120 will periodically compare the current value of the idle timer with a preset duration threshold. Setting this preset duration threshold is crucial to ensuring the recovery mechanism is both reliable and free from misjudgments. This duration threshold must be significantly longer than the maximum polling interval that the first master device 110 might experience during normal operation. A preferred and specific implementation is to set this duration threshold to the duration of two complete polling cycles executed by the second master device 120 in master mode. For example, if it takes 500ms for the second master device 120 to poll all its managed slave devices once, then this threshold can be reasonably set to 1000ms. This ensures that normal communication gaps are effectively filtered out, ensuring that the recovery action is only triggered when a prolonged, genuine abnormal silence occurs.
[0096] If the idle time does not exceed the duration threshold, it indicates that the idle time of the communication bus 140 is still within the allowable range, which may be a normal communication gap. Continue monitoring and timing. If the idle time has exceeded or equaled the duration threshold, it indicates that the first master device 110 may have malfunctioned (e.g., crashed, software crashed) or has been physically disconnected from the communication bus 140, causing the communication bus 140 to be in a dangerous "deadlock" state of being unattended.
[0097] Upon determining a timeout, the second master device 120 immediately performs a mode switch, transitioning from slave mode back to master mode. The second master device 120 reloads its original polling configuration and immediately begins sending query frames to the first slave device in the list, thereby regaining control of the bus and restoring the entire single-master communication system 10 to its initial, stable operating state. This automatic recovery process requires no manual intervention, ensuring the continuous availability of core system functions (such as temperature control).
[0098] In some embodiments, after a new host (first master device 110) successfully preempts the communication bus 140, it may choose to periodically broadcast a bus occupancy message to the communication bus 140. The bus occupancy message may also use a broadcast address and a special function code indicating that the bus is occupied.
[0099] Specifically, such as Figure 7 As shown, the first master device 110 executes the following steps S701, S702, S704 and S705, and the second master device 120 executes the following steps S703, S706 and S707.
[0100] In step S701, the idle period of the communication bus is monitored.
[0101] In step S702, during the bus idle period, a preset bus preemption message is broadcast through the communication bus.
[0102] In step S703, in response to receiving a bus preemption message, the working mode is switched to slave working mode.
[0103] In step S704, the working mode is switched to host working mode.
[0104] Steps S701 to S704 can be referred to the description of steps S301 to S304 above, and will not be repeated here.
[0105] In step S705, periodic broadcasts are used to indicate bus occupancy messages that indicate the current communication bus is being occupied by the first master device.
[0106] In step S706, based on the received bus occupancy message, it is determined that the communication bus is in an occupied state.
[0107] In step S707, if the duration of the communication bus being idle is greater than the duration threshold, the slave device working mode is switched to the master working mode.
[0108] The first master device 110 periodically broadcasts bus occupancy messages, enabling any newly connected device to the communication bus 140, or a device that wakes up from sleep mode, to quickly understand the current master control status of the communication bus 140 by listening to the bus occupancy messages, thereby avoiding erroneous attempts to communicate with the second master device 120, which is already in slave mode, at the master level.
[0109] Furthermore, the second master device 120, operating in slave mode, can reset the idle timer described in the above embodiments by listening to this periodic bus occupancy message. Compared to listening to any activity on the communication bus 140, listening to a specific "heartbeat" message from the first master device 110 can more accurately determine the liveness status of the first master device 110, effectively avoiding erroneous timeouts and unnecessary control revocations caused by excessively long gaps in normal business communication.
[0110] Figure 8 This is a structural block diagram of a communication bus control device disclosed herein. The communication bus includes a second master device and at least one slave device, such as... Figure 8 As shown, the communication bus control device includes: a listening section 801, configured to listen to the bus idle period of the communication bus, the bus idle period being a period of time after the second master device and at least one slave device complete a round of query frames and response frames; a communication section 802, configured to broadcast a preset bus preemption message through the communication bus during the bus idle period, so as to switch the second master device from master working mode to slave working mode; and a mode switching section 803, configured to switch the working mode to master working mode.
[0111] In some embodiments, the mode switching section 803 is configured to switch the operating mode to host operating mode upon receiving a response message of a bus preemption message from a second master device.
[0112] In some embodiments, the bus preemption message includes a priority function code, and the response message indicates that the priority indicated by the priority function code is higher than the task priority of the second master device.
[0113] In some embodiments, periodic broadcasts are used to indicate bus occupancy messages that indicate the current communication bus is being used by a first master device.
[0114] In this embodiment, each part can implement the steps executed by the first master device 110 in the single-host communication system 10 and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0115] Figure 9 This is a structural block diagram of a communication bus control device disclosed herein, such as... Figure 9 As shown, the communication bus control device includes a state switching section 901, which is configured to switch the working mode to slave working mode in response to a bus preemption message sent by a first master device.
[0116] In some embodiments, the communication bus control device further includes a communication section configured to send a response message to the first master device in response to a bus preemption message received from the first master device.
[0117] In some embodiments, the communication bus control device further includes: a parsing section configured to parse a bus preemption message to obtain a priority function code; and a communication section configured to send a response message to a first master device when the priority indicated by the priority function code is higher than the current task priority.
[0118] In some embodiments, the communication bus control device further includes: an acquisition section configured to acquire the state of the communication bus; and a state switching section 901 configured to switch the slave working mode to the master working mode when the duration of the communication bus being in an idle state is greater than a duration threshold.
[0119] In some embodiments, the acquisition section is configured to determine that the communication bus is in a occupied state based on a bus occupancy message broadcast by the first master device.
[0120] In this embodiment, each part can implement the steps executed by the second master device 120 in the single-host communication system 10 and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0121] Please refer to Figure 10 This illustration shows a schematic diagram of the hardware structure of an electronic device provided in an exemplary embodiment of this disclosure. Both the first main device 110 and the second main device 120 can be this electronic device. In some examples, the electronic device can be at least one of devices such as a smartphone, smartwatch, desktop computer, laptop, virtual reality terminal, augmented reality terminal, wireless terminal, and laptop computer. The electronic device has communication functions and can access wired or wireless networks. "Electronic device" can refer to one of multiple terminals; those skilled in the art will understand that the number of terminals can be more or less. It is understood that the electronic device undertakes the computation and processing work of the technical solution of this disclosure, and this disclosure does not limit this aspect.
[0122] like Figure 10 As shown, the electronic device in this disclosure may include one or more of the following components: processor 1010 and memory 1020.
[0123] Optionally, the processor 1010 connects various parts within the electronic device using various interfaces and lines. It executes various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 1020, and by calling data stored in the memory 1020. Optionally, the processor 1010 can be implemented using at least one hardware form of Digital Signal Processing (DSP), Field Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 1010 can integrate one or more of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), Neural-network Processing Unit (NPU), and baseband chip. Specifically, the CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content displayed on the touchscreen; the NPU implements Artificial Intelligence (AI) functions; and the baseband chip handles wireless communication. It is understandable that the aforementioned baseband chip may not be integrated into the processor 1010, but may be implemented using a separate chip.
[0124] The memory 1020 may include random access memory (RAM) or read-only memory (ROM). Optionally, the memory 1020 may include a non-transitory computer-readable storage medium. The memory 1020 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 1020 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the various method embodiments described above, etc.; the data storage area may store data created based on the use of the electronic device, etc.
[0125] In addition, those skilled in the art will understand that the structure of the electronic device shown in the above figures does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements. For example, the electronic device may also include a display screen, camera assembly, microphone, speaker, radio frequency circuit, input unit, sensors (such as accelerometer, angular velocity sensor, light sensor, etc.), audio circuit, Wi-Fi module, power supply, Bluetooth module, etc., which will not be described in detail here.
[0126] This disclosure also provides a computer-readable storage medium storing at least one instruction, which is executed by a processor to implement the steps performed by the first master device 110 and the second master device 120 as described in the above embodiments.
[0127] This disclosure also provides a computer program product including computer instructions stored in a computer-readable storage medium; a processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform steps performed by the first main device 110 and the second main device 120 as described in the above embodiments.
[0128] This disclosure also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the steps executed by the first master device 110 and the steps executed by the second master device 120, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0129] It should be understood that the chip mentioned in the embodiments of this disclosure may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0130] In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, apparatuses, servers, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0131] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0132] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0133] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0134] Those skilled in the art will recognize that the functions described in this disclosure in one or more of the examples above can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any medium that facilitates the transfer of a computer program from one place to another. Storage media can be any available medium accessible to a general-purpose or special-purpose computer.
[0135] It should be noted that the technical solutions described in this disclosure can be combined arbitrarily as long as they do not conflict.
[0136] The above description is merely a specific embodiment of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A communication bus control method, characterized in that, Applied to a first master device, the communication bus includes a second master device and at least one slave device, and the communication bus control method includes: Receive all data frames on the communication bus; Analyzing the data frame, an inquiry frame sent by the second master device to a target slave device among the at least one slave device was identified; After delays t0 and t1, in response to the detected target slave device starting to send the response frame corresponding to the query frame, after the last bit of the response frame is transmitted on the communication bus, the bus idle period is determined. t0 represents the time from the start of the query frame transmission to the completion of the transmission of the last bit on the communication bus, t1 is the time for the target slave device to prepare the response frame after fully receiving and parsing the query frame, and the bus idle period is the time from the completion of the transmission of the last bit of the response frame on the communication bus to the time before preparing to initiate polling of the next slave device. During the bus idle period, a preset bus preemption message is broadcast through the communication bus to enable the second master device to switch from master working mode to slave working mode; Switch the working mode to host working mode; The step of switching the working mode to the host working mode includes: Upon receiving a response message from the second master device regarding the bus preemption message, the operating mode is switched to master operating mode.
2. The method according to claim 1, characterized in that, The bus preemption message includes a priority function code, and the response message indicates that the priority indicated by the priority function code is higher than the task priority of the second master device.
3. The method according to claim 1, characterized in that, Periodic broadcasts are used to indicate bus occupancy messages that indicate the current communication bus is being used by the first master device.
4. A communication bus control method, characterized in that, The communication bus control method, applied to a second master device, includes: In response to the bus preemption message received from the first master device, the operating mode is switched to slave operating mode, and a response message is sent to the first master device; The bus preemption message is broadcast by the first master device via the communication bus during a bus idle period. The bus idle period is the time from the completion of the transmission of the last bit of the acknowledgment frame on the communication bus to the preparation of initiating polling of the next slave device. The determination of the bus idle period includes: The first master device receives all data frames on the communication bus; The first master device analyzes the data frame and identifies a query frame sent by the second master device to a target slave device among at least one slave device; After delays t0 and t1, the first master device responds to the detected target slave device by sending a response frame corresponding to the query frame. After the last bit of the response frame is transmitted on the communication bus, the bus idle period is determined. t0 represents the time from the start of the query frame transmission to the completion of the transmission of the last bit on the communication bus, and t1 is the time for the target slave device to prepare the response frame after fully receiving and parsing the query frame.
5. The method according to claim 4, characterized in that, The communication bus control method further includes: Parse the bus preemption message to obtain the priority function code; The step of sending a response message to the first master device in response to the received bus preemption message includes: If the priority indicated by the priority function code is higher than the current task priority, the response message is sent to the first master device.
6. The method according to claim 4, characterized in that, The communication bus control method further includes: Obtain the status of the communication bus; If the duration of the communication bus being idle exceeds a duration threshold, the slave working mode is switched to the master working mode.
7. The method according to claim 6, characterized in that, The step of obtaining the status of the communication bus includes: Based on the bus occupancy message received from the first master device, it is determined that the communication bus is in an occupied state.
8. A single-host communication system, characterized in that, The single-host communication system includes: a communication bus, a first master device, a second master device, and at least one slave device, wherein the first master device, the second master device, and at least one slave device are connected through the communication bus; The first master device is configured to receive all data frames on the communication bus; Furthermore, the data frame is analyzed to identify an inquiry frame sent by the second master device to a target slave device among the at least one slave device; And, after delays t0 and t1, in response to the detected target slave device starting to send the response frame corresponding to the query frame, after the last bit of the response frame is transmitted on the communication bus, it is determined to enter the bus idle period. The t0 represents the time from the start of the query frame transmission to the completion of the transmission of the last bit on the communication bus, the t1 is the time for the target slave device to prepare the response frame after fully receiving and parsing the query frame, and the bus idle period is the time from the completion of the transmission of the last bit of the response frame on the communication bus to the preparation of polling the next slave device. In addition, during the bus idle period, a preset bus preemption message is broadcast through the communication bus; The second master device is configured to switch its working mode to slave working mode in response to the bus preemption message sent by the first master device, and send a response message to the first master device. The first master device is also configured to switch its operating mode to master operating mode upon receiving a response message from the second master device in response to the bus preemption message.
Citation Information
Patent Citations
Main-machine communication method, main machine and communication system
CN103116563A
Polling competition method, communication system and electronic equipment
CN117354085A
Bus control method, chip, bus architecture, electronic equipment and readable medium
CN119917435A