A method for controlling an integrated circuit I2C bus for multiple master devices

By setting status bits and priority levels in the master devices of intelligent driving vehicles, the problems of arbitration failure and resource waste when multiple master devices compete for the I2C bus are solved, achieving more efficient bus resource utilization and communication reliability.

CN118277316BActive Publication Date: 2026-11-10BYD CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311318469.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-10
Publication Date
2026-11-10
Estimated Expiration
2043-10-10

AI Technical Summary

Technical Problem

In intelligent driving vehicles, when multiple master devices compete for the I2C bus, the existing arbitration mechanism may lead to arbitration failure, waste of resources, long arbitration time, and low efficiency.

Method used

By setting status bits and priority levels in the master device, the master device can read the status bits of other devices to determine the I2C bus occupancy status, and preempt or monitor bus usage according to the priority level, thus avoiding data conflicts and resource waste.

Benefits of technology

It improves the resource utilization of the I2C bus, ensures timely transmission of urgent tasks, and enhances the communication efficiency and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118277316B_ABST
    Figure CN118277316B_ABST
Patent Text Reader

Abstract

This application provides a method for controlling an integrated circuit I2C bus using multiple master devices, relating to the field of intelligent driving. The multiple master devices include at least a first master device and a second master device. Both the first and second master devices are equipped with status bits to indicate whether the master device is currently using the I2C bus. The method includes: the first master device determining whether the second master device is currently using the I2C bus; if the second master device is not using the I2C bus, or if the second master device is using the I2C bus and the first master device has a higher priority than the second master device, the first master device sets its status bit to indicate that it is using the I2C bus, and then uses the I2C bus to transmit data. According to the method provided in this application, the determination time can be reduced, the determination efficiency improved, and the I2C bus can be used more efficiently, thereby improving the system's resource utilization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of intelligent driving, and more particularly to a method for controlling a multi-master device integrated circuit I2C bus. Background Technology

[0002] Intelligent driving vehicles include multiple controllers, all connected to an inter-integrated circuit (I2C) bus. The I2C bus also connects to multiple slave devices, which can be, for example, different types of sensors. Each controller, acting as a master device, can send commands or data to the slave devices via the I2C bus. Only one master device can occupy the I2C bus at a time for data transmission. When multiple master devices need to use the I2C bus for data transmission, a contention for the bus arises.

[0003] See Figure 1 , Figure 1 This application provides a wiring diagram for an I2C bus in a multi-master mode. Figure 1 The system includes a first master device, a second master device, a first slave device, and a second slave device. These devices are connected and communicate via an I2C bus. The I2C bus consists of a serial clock line (SCL) and a serial data line (SDA). SCL provides the clock signal for data transmission between the devices, while SDA is used for the actual data transmission, including commands and addresses.

[0004] Currently, when multiple master devices compete for the I2C bus, an arbitration mechanism is used to select one master device to obtain the right to use the I2C bus. Other master devices then wait for the master device to finish transmitting data and release the I2C bus before competing for the right to use the I2C bus again.

[0005] However, the arbitration mechanism may fail in some special circumstances. Arbitration failure means that no master device can successfully obtain control of the I2C bus for a period of time, resulting in unnecessary waste of resources. In addition, the arbitration process requires multiple comparisons until the difference is detected before it can be determined which master device has the right to possess the I2C bus. The arbitration time is long and the arbitration efficiency is low. Summary of the Invention

[0006] This application provides a method for controlling an integrated circuit I2C bus with multiple master devices. By setting a status bit in the master device and setting a priority level for the master device's I2C bus control rights, the method has a shorter judgment time and higher efficiency in determining the ownership of the I2C bus compared with the traditional I2C bus arbitration mechanism, which enables the I2C bus to be used reasonably and improves the system's resource utilization.

[0007] In a first aspect, embodiments of this application provide a method for controlling a multi-master device integrated circuit I2C bus, including:

[0008] The first master device reads the status bit on the second master device, and the status bit on the second master device is used to indicate whether the second master device is occupying the I2C bus;

[0009] If the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the status bit on the first master device is set to the state of occupying the I2C bus, and the first master device uses the I2C bus to transmit data.

[0010] If the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is higher than that of the second master device, the first master device preempts the I2C bus and sets the status bit on the first master device to the state of occupying the I2C bus, and the first master device uses the I2C bus to transmit data.

[0011] As can be seen in this embodiment, a status bit is set in each master device to indicate whether the master device is occupying the I2C bus. By reading the status bits of other master devices, it can be determined whether the I2C bus is idle. Compared with the I2C bus arbitration mechanism, this application avoids data corruption and signal loss that may occur when multiple master devices transmit data on the I2C bus simultaneously. The I2C bus occupancy status can be determined solely by the status bit, avoiding resource waste and ensuring that the resources on the I2C bus are used rationally. In addition, pre-setting the priority access level of the I2C bus in the master device allows master devices with urgent tasks to transmit data more promptly. Compared with the traditional I2C bus arbitration mechanism, the determination of I2C bus ownership is faster and more efficient.

[0012] Based on the first aspect, in possible implementations, the method further includes:

[0013] When the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is lower than that of the second master device, the first master device monitors the status bit on the second master device. When the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the first master device sets the status bit on the first master device to the state of occupying the I2C bus and uses the I2C bus to transmit data.

[0014] As can be seen in this embodiment, when the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is lower than that of the second master device, the first master device can effectively avoid conflicts caused by multiple master devices using the I2C bus at the same time by monitoring the status bit of the second master device in real time, thereby improving the reliability and efficiency of I2C bus transmission.

[0015] Based on the first aspect, in possible implementations, the method further includes:

[0016] An interrupt routine is started before the first master device uses the I2C bus to transmit data; the interrupt routine is disabled after the first master device uses the I2C bus to transmit data.

[0017] As can be seen in this embodiment, starting the interrupt routine before the first master device uses the I2C bus to transmit data ensures timely response to requests from other devices to the bus, monitors signal changes or priority requests on the bus, and can immediately trigger the corresponding interrupt handling function once a relevant event occurs. Disabling the interrupt routine after data transmission is complete restores normal system operation, releases processor resources, and avoids unnecessary interrupt handling overhead. By properly configuring the timing of interrupt routine startup and shutdown, the system's real-time performance, responsiveness, and resource utilization can be improved.

[0018] Based on the first aspect, in a possible implementation, after the first master device uses the I2C bus to transmit data, the method further includes:

[0019] The first master device sets the status bit on the first master device to a state where the I2C bus is not occupied.

[0020] Based on the first aspect, in possible implementations, the method further includes:

[0021] The first master device obtains the priority level of the second master device from the I2C bus, and the priority level of the second master device is sent to the I2C bus by the second master device.

[0022] As can be seen in this embodiment, the first master device obtains the priority level of the second master device from the I2C bus. This means that the first master device can obtain important information about other master devices and make decisions based on this information. By understanding the priority level of the second master device, the first master device can determine the priority of other master devices on the bus, thereby following priority rules during data transmission and ensuring that high-priority devices can use the bus in a timely manner and meet their communication needs. This mechanism can improve the overall communication efficiency and fairness of the system, avoiding the problem of low-priority devices occupying the bus for a long time, causing high-priority devices to be unable to communicate in a timely manner.

[0023] Based on the first aspect, in possible implementations, the method further includes:

[0024] The first master device is a microcontroller (MCU), and the second master device is a system-on-a-chip (SoC); or, the first master device is a SoC, and the second master device is a microcontroller (MCU).

[0025] Secondly, embodiments of this application provide a device for controlling a multi-master device integrated circuit I2C bus. The device is applied to a first master device, and the multi-master device includes at least the first master device and a second master device. Both the first master device and the second master device are provided with a status bit, which is used to indicate whether the master device is currently occupying the I2C bus. The device includes:

[0026] The read module is used to read the status bits on the second master device, which are used to indicate whether the second master device is currently occupying the I2C bus.

[0027] The write module and the transmission module are configured such that, when the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the write module is used to set the status bit on the first master device to be occupying the I2C bus, and the transmission module is used to transmit data using the I2C bus.

[0028] When the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is higher than that of the second master device, the write module is used to set the status bit on the first master device to the state of occupying the I2C bus, and the transmission module is used to preempt the I2C bus and use the I2C bus to transmit data.

[0029] Based on the second aspect, among the possible implementation methods:

[0030] When the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is lower than that of the second master device, the read module is further configured to monitor the status bit on the second master device. When the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the write module is configured to set the status bit on the first master device to the state of occupying the I2C bus, and the transmission module is configured to use the I2C bus to transmit data.

[0031] Based on the second aspect, among the possible implementation methods:

[0032] An interrupt module is used to start an interrupt routine before the first master device uses the I2C bus to transmit data;

[0033] The interrupt module is also used to disable the interrupt routine after the first master device transmits data using the I2C bus.

[0034] Based on the second aspect, in a possible implementation, the write module is used for:

[0035] After the first master device transmits data using the I2C bus, the write module is used to set the status bit on the first master device to a state where the I2C bus is not occupied.

[0036] Based on the second aspect, in a possible implementation, the acquisition module is used for:

[0037] The first master device obtains the priority level of the second master device from the I2C bus, and the priority level of the second master device is sent to the I2C bus by the second master device.

[0038] Based on the second aspect, in possible implementations, the first master device is a microcontroller (MCU) and the second master device is a system-on-a-chip (SoC); or, the first master device is a SoC and the second master device is a microcontroller (MCU).

[0039] The functional modules in the second aspect are used to implement the methods described in the first aspect and the possible implementations of the first aspect.

[0040] Thirdly, embodiments of this application provide an apparatus for a multi-master device control integrated circuit I2C bus, including a memory and a processor. The memory is used to store instructions, and the processor is used to execute the instructions stored in the memory to implement the method described in the first aspect and any possible implementation of the first aspect.

[0041] Fourthly, embodiments of this application provide a readable storage medium including program instructions that, when executed by the controller, cause the controller to perform the method described in the first aspect and any possible implementation thereof.

[0042] Fifthly, this application provides a computer program product, including program instructions, which, when executed by a controller, performs the methods described in the first aspect and any possible implementation thereof. The computer program product may be a software installation package; when the methods provided by any possible design of the first aspect are required, the computer program product may be downloaded and executed on the controller to implement the methods described in the first aspect and any possible implementation thereof.

[0043] Sixthly, embodiments of this application provide a vehicle including a first master device, a second master device, and an I2C bus, wherein the first master device is used to perform the method described in the first aspect and any possible implementation thereof. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of this application or the background art, the accompanying drawings used in the embodiments of this application or the background art will be described below.

[0045] Figure 1 This is a wiring diagram of an I2C bus in a multi-master mode provided in this application;

[0046] Figure 2 This is a schematic diagram of a system architecture provided in this application;

[0047] Figure 3 This is a flowchart illustrating a method for controlling a multi-master device integrated circuit I2C bus according to this application;

[0048] Figure 4 This is a flowchart illustrating the process of data transmission using the I2C bus by the master device provided in this application;

[0049] Figure 5 This is a schematic diagram of the structure of a multi-master device control integrated circuit I2C bus device provided in this application;

[0050] Figure 6 This is a schematic diagram of the structure of another multi-master device control integrated circuit I2C bus device provided in this application;

[0051] Figure 7 This is a schematic diagram of a vehicle structure provided in this application. Detailed Implementation

[0052] The embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0053] It should be noted that the terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the application. The singular forms “a,” “the,” and “the” used in the embodiments of this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.

[0054] It should be noted that, when used in this specification and the appended claims, the term "comprising" and any variations thereof are intended to cover a non-exclusive inclusion. For example, a system, product, or apparatus that comprises a series of units / devices is not limited to the units / devices listed, but may optionally include units / devices not listed, or may also optionally include other units / devices inherent in such products or apparatuses.

[0055] It should also be understood that the term "if" can be interpreted, depending on the context, as "when," "once," "in response to determination," "in response to detection," or "in the case of."

[0056] This application provides a method for controlling the I2C bus of a multi-master device integrated circuit. Before introducing the method for controlling the I2C bus of a multi-master device integrated circuit provided in this application, the system architecture involved in the method will be introduced first.

[0057] See Figure 2 , Figure 2 This application provides a schematic diagram of a system architecture. The system includes a first master device, a second master device, a first slave device, a second slave device, and an I2C bus. The I2C bus includes SDA and SCL lines. Each device has SCL and SDA pins, which are connected to corresponding pins on the I2C bus. For example, the SCL pin on the first master device is connected to the SCL line on the I2C bus via a connecting line, and the SDA pin on the first master device is also connected to the SDA line on the I2C bus via a connecting line. The connection methods for other master and slave devices are similar.

[0058] The first master device can be a microcontroller unit (MCU), and the second master device can be a system on a chip (SOC); alternatively, the first master device can be an SOC, and the second master device can be an MCU. The first slave device can be a first sensor, and the second slave device can be a second sensor.

[0059] The first master device has a W pin, which indicates whether the first master device is currently using the I2C bus. For example, it can be configured so that when the status bit of the W pin on the first master device is "1", it indicates that the first master device is using the I2C bus, and when the status bit of the W pin on the first master device is "0", it indicates that the first master device is not using the I2C bus. Similarly, the second master device has a W pin, which indicates whether the second master device is currently using the I2C bus. In one example, it can also be configured so that when the W pin is "0", it indicates that the master device currently using the I2C bus is using the I2C bus, and when the status bit of the W pin is "1", it indicates that the master device currently using the I2C bus is not using the I2C bus.

[0060] The first master device has an R pin, which is used to read the status bit of the W pin on the second master device. Similarly, the second master device has an R pin, which is used to read the status bit of the W pin on the first master device. For example, when the status bit of the W pin on the second master device is "1" (the second master device is using the I2C bus), the first master device can read through the R pin that the second master device is using the I2C bus at this moment.

[0061] Both the first and second master devices have registers, and the state of the W pin can be implemented / controlled through these registers. For example, the register typically stores a binary value representing the W pin status bit of the master device, and the W pin status bit can be changed by writing to the register.

[0062] When three master devices are connected to the vehicle's I2C bus, including the first master device, the second master device, and the third master device, the third master device can read the status bit of the first master device's W pin through the R pin, and the third master device can also read the status bit of the second master device's W pin through the R pin.

[0063] In the field of intelligent driving, the vehicle's I2C bus may include a greater number of master devices and a greater or lesser number of slave devices. The first master device and the second master device are merely examples and do not constitute a limitation of the present application. The first master device and the second master device may also be other control devices, which are not limited in this application.

[0064] See Figure 3 , Figure 3This application provides a flowchart illustrating a method for controlling a multi-master device integrated circuit I2C bus, the method including but not limited to the following description.

[0065] S101, The first master device reads the status bit on the second master device.

[0066] Before the first master device reads the status bits on the second master device, both the first and second master devices register with the I2C bus. The registration information includes the address and priority level of the first / second master device. The address uniquely identifies the first / second master device on the I2C bus, ensuring they can be correctly identified and addressed. The priority level determines their access priority when occupying the I2C bus. By registering with the I2C bus, the first and second master devices can coordinate and manage their access to the I2C bus. This application does not specifically limit the registration information.

[0067] When the second master device transmits data, it will set the W pin status bit in the second master device to be in use of the I2C bus. This W pin can be... Figure 2 The W pin in the I2C bus. When the first master device wants to transmit data on the I2C bus, it first reads the status bit of the W pin on the second master device through the R pin on the first master device to determine whether the second master device is using the I2C bus. For example... Figure 2 As shown, the R pin of the first master device and the W pin of the second master device are connected via a signal line. The status bit of the W pin of the second master device can be read from the R pin of the first master device through this signal line. Similarly, the R pin of the second master device and the W pin of the first master device are also connected via a signal line, and the status bit of the W pin of the first master device can be read from the R pin of the second master device through this signal line. Likewise, when the second master device wants to perform data transmission on the I2C bus, it will first read the status bit of the W pin of the first master device through the R pin of the second master device to determine whether the first master device is currently using the I2C bus.

[0068] In one embodiment, before transmitting data, the MCU writes the status bit 1 of the W pin to the corresponding position of the register address. At this time, the SOC also wants to transmit data on the I2C bus. The SOC requests the status bit of the MCU's W pin from the MCU through the R pin of the SOC. The MCU can obtain the status bit 1 of the MCU's W pin by reading the register address. Then the SOC knows that the MCU is occupying the I2C bus.

[0069] S102, The first master device determines whether the second master device is currently using the I2C bus.

[0070] In another embodiment, when the W pin status bit of the first master device is 1, it indicates that the first master device is occupying the I2C bus; when the R pin status bit of the first master device is 1, it indicates that the second master device is occupying the I2C bus. Similarly, when the W pin status bit of the second master device is 1, it indicates that the second master device is occupying the I2C bus; when the R pin status bit of the second master device is 1, it indicates that the first master device is occupying the I2C bus. For example, when the first master device reads that the status bit of the second master device is 0 through the R pin, it means that the second master device is not occupying the I2C bus, and the first master device executes S103; when the first master device reads that the status bit of the second master device is 1 through the R pin, it means that the second master device is occupying the I2C bus, and the first master device executes S104.

[0071] S103. If the second master device does not occupy the I2C bus, the first master device sets the status bit on the first master device to occupy the I2C bus and uses the I2C bus to transmit data.

[0072] When the first master device reads the status bit flag on the second master device through the R pin and finds that the second master device is not using the I2C bus, it means that the second master device is not using the I2C bus to transmit data. At this time, the I2C bus is in an idle state. The first master device sets the status bit on the first master device to the state of using the I2C bus, and then uses the I2C bus to transmit data.

[0073] The following describes the process of the first master device transmitting data using the I2C bus.

[0074] See Figure 4 , Figure 4 This application provides a flowchart of a master device using the I2C bus to transmit data. The process of the first master device transmitting data using the I2C bus includes: the first master device sending a start signal to the I2C bus, the first master device sending a slave device address to the I2C bus, the first master device receiving an acknowledgment signal from the slave device, the first master device sending data to the slave device, and the first master device sending a stop signal to the I2C bus.

[0075] S1031, The first master device sends a start signal to the I2C bus.

[0076] The first master device switches the SDA line from high to low while keeping the SCL line high, indicating a start signal. After sending the start signal, the I2C bus is considered to be in a non-idle state.

[0077] S1032, The first master device sends an address frame to the I2C bus.

[0078] After the first master device sends the start signal, it needs to send an address frame to the SDA line to select the slave device to communicate with. The address frame is 8 bits of binary data. 7 bits of the address frame are the address of the slave device, and 1 bit is the R / W bit (read / write flag). The R / W bit is set by sending 0 or 1. The R / W bit indicates whether the first master device is reading or writing data.

[0079] S1033, The first master device receives the response signal sent by the slave device.

[0080] After the master device sends the address frame, it releases the SDA line and waits for the slave device to send an acknowledgment signal. Upon receiving the address frame, the slave device compares its own address with the address frame. If the addresses match, the slave device sends an acknowledgment signal, indicating that it is ready to communicate. If the addresses do not match or the slave device cannot process the request, it does not send an acknowledgment signal but keeps the SDA line high, letting the master device know that communication has failed. The acknowledgment signal is generated on the edge of the clock cycle, when the SDA line is pulled low by the slave device, and the master device reads the state of the SDA line on the same clock edge. If the acknowledgment signal is low, it indicates that the slave device has received the address.

[0081] S1034, The first master device sends data to the slave device.

[0082] When the master device sends data to the slave device, the data is transmitted in multiple bytes. Each byte consists of 8 bits of binary data, with the most significant bit being the first bit sent (MSB) and the least significant bit being the last bit sent (LSB). The data transmission process includes: the master device writes the data bits one by one onto the SDA line while keeping the SCL line high. First, the MSB is sent to the SDA line, and then a clock signal is generated to drive the state of the SCL line; the slave device reads the state of the SDA line on the clock edge and acknowledges the received bit. The master device continues to send the next bit until all bits have been sent. After sending the last bit, the master device releases the SDA line and waits for the slave device to send an acknowledgment signal. The data reception process includes: the master device reads the data bits on the SDA line on the falling edge of the clock; the master device sends an acknowledgment signal, which can be a low-level pulse, to inform the slave device that it has successfully received the data bit. If more data needs to be received, the master device repeats the above steps, reading the next data bit and sending an acknowledgment signal.

[0083] S1035, The first master device sends a stop signal to the I2C bus.

[0084] If data transmission is complete, the first master device sends a stop signal to the I2C bus. The first master device first ensures the SCL line is high, then switches the SDA line from low to high. The first master device then releases the SDA line, allowing the slave devices to detect the stop signal.

[0085] Optionally, the process of the first master device transmitting data to the I2C bus can be implemented using interrupts. For example, the interrupt routine can be enabled before sending the start signal and disabled after sending the stop signal.

[0086] After the first master device finishes transmitting data, it sets the status bit of the W pin on the first master device to the state of not occupying the I2C bus. Optionally, in one implementation, if the data transmission is implemented through an interrupt, the first master device sets the status bit of the W pin on the first master device to the state of not occupying the I2C bus after disabling the interrupt routine.

[0087] S104. If the second master device is occupying the I2C bus, the first master device determines whether the priority level of the first master device is higher than the priority level of the second master device.

[0088] The priority levels of the first and second master devices are pre-set. Priority levels can be set using variables or configuration items in the software code of both the first and second master devices. For example, during the initialization phase, each master device can be assigned a priority level; a higher value indicates a higher priority, or a lower value indicates a higher priority. This application does not specifically limit the meaning of the priority level values.

[0089] If the status bit on the second master device indicates that the second master device is occupying the I2C bus, the first master device can further compare its priority level with that of the second master device to determine whether it can preempt the I2C bus. When the priority level of the first master device is higher than that of the second master device, the first master device can preempt the I2C bus and gain control of the I2C bus; when the priority level of the first master device is lower than that of the second master device, the second master device gains control of the I2C bus.

[0090] Before comparing the priority levels of the first master device and the second master device, the first master device can obtain the priority level of the second master device through the I2C bus. When the second master device registers with the I2C bus, it will register its priority level with the I2C bus.

[0091] In another embodiment, master device A and master device B are connected to the same I2C bus, with master device A having a priority level of 2 and master device B having a priority level of 1. At a certain moment, master device B is occupying the I2C bus, and a status bit indicates that master device B is occupying the bus. When master device A needs to transmit data on the I2C bus, it obtains master device B's priority level of 1 through the I2C bus and compares it to determine that master device A has a higher priority level than master device B.

[0092] S105. If the second master device is occupying the I2C bus and the priority level of the first master device is higher than that of the second master device, the first master device sets its status bit to occupy the I2C bus, preempts the I2C bus, and uses the I2C bus to transmit data.

[0093] If the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is higher than that of the second master device, the first master device preempts the I2C bus, and the second master device loses its right to occupy the I2C bus. Specifically, when the second master device is transmitting data, its W pin indicates that it is occupying the I2C bus, and its R pin indicates that it is not occupying the I2C bus. At this time, the first master device compares its priority level with that of the second master device. If the first master device's priority level is higher than that of the second master device, the first master device will set its W pin status bit to indicate that it is occupying the I2C bus. If the second master device detects that the first master device's status bit is occupying the I2C bus through its R pin during transmission, it means that the second master device's priority level is lower than that of the first master device. Therefore, the second master device will release the I2C bus, thus enabling the first master device to preempt the I2C bus. This application does not specifically limit the method by which the first master device preempts the I2C bus. After the first master device preempts the I2C bus, it enables the interrupt routine and executes steps S1031 to S1035 to transmit data on the I2C bus.

[0094] In another embodiment, there are two master devices, A and B, both connected to the same I2C bus, with A having a higher priority than B. At a certain moment, device B is using the I2C bus and transmitting data. At this time, device B's W pin status is set to indicate that it is using the I2C bus, while its read interface status is set to indicate that it is not using the I2C bus. At this moment, device A needs to access the I2C bus and, based on its higher priority than device B, attempts to preempt the I2C bus. Device A checks device B's W pin status and finds it set to indicate that it is using the I2C bus. Device A determines from this status that device B is using the I2C bus and that device A has a higher priority. Therefore, device A sets its own W pin status to indicate that it is using the I2C bus and initiates an interrupt routine to perform the corresponding steps for data transmission. During data transmission, device B detects that device A's W pin status is in the "using the I2C bus" state through its read interface. Based on this status, device B determines that device A has a higher priority and releases its access to the I2C bus. Thus, device A successfully preempts the I2C bus and can use it for data transmission.

[0095] S106. When the second master device is occupying the I2C bus and the priority level of the first master device is lower than that of the second master device, the first master device monitors the status bits on the second master device.

[0096] When the status bit on the second master device indicates that the second master device is occupying the I2C bus, the first master device compares its priority level with that of the second master device. If its priority level is lower than that of the second master device, the first master device cannot preempt the I2C bus and needs to monitor the status bit on the second master device. When the status bit on the second master device indicates that the second master device is not occupying the I2C bus, it means that the second master device is not transmitting data on the I2C bus. At this time, the first master device sets the status bit of its W pin to the state of occupying the I2C bus, enables the interrupt routine, and executes steps S1031 to S1035 to transmit data on the I2C bus.

[0097] In another implementation, firstly, the first master device enables the interrupt routine; then, the first master device reads the status bit of the W pin on the second master device through the R pin on the first master device. If the status bit of the W pin on the second master device indicates that the second master device is not occupying the I2C bus, and if the status bit of the W pin on the second master device indicates that the second master device is occupying the I2C bus and the first master device has a higher priority level than the second master device, the first master device sets the W pin status bit to the state of occupying the I2C bus; next, the first master device performs data transmission on the I2C bus; finally, after the data transmission is completed, the first master device disables the interrupt routine and sets the W pin status bit to the state of not occupying the I2C bus.

[0098] The method embodiments of this application are described using the first master device and the second master device as examples. In actual applications, there may be more master devices connected to the I2C bus. For example, there may be three or more master devices connected to the I2C bus. In the case of three or more master devices connected to the I2C bus, a method similar to that of this application can be adopted, that is, the occupancy right of the I2C bus can be determined by setting status bits and priority levels on the master devices.

[0099] This application saves judgment time, improves judgment efficiency, and avoids resource waste by adding a W pin and setting corresponding status bits in the master device, and adding an R pin to read the status bits of other master devices and determine whether other master devices are occupying the I2C bus. This ensures that the resources on the I2C bus can be used rationally. By setting the I2C bus priority level in the master device, it ensures that each master device can use the I2C bus in an orderly manner according to its needs, enabling timely transmission of critical tasks, thereby improving system performance and reliability.

[0100] This application provides a device for controlling a multi-master device integrated circuit I2C bus, see [link to relevant documentation]. Figure 5 , Figure 5 This is a schematic diagram of a device 500 for a multi-master device control integrated circuit I2C bus provided in this application. The device 500 can be used for... Figure 3 The first master device, apparatus 500, in the method embodiment includes:

[0101] The read module 510 is used to read the status bits on the second master device, which are used to indicate whether the second master device is occupying the I2C bus.

[0102] When the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the write module 530 is used to set the status bit on the first master device to the state of occupying the I2C bus, and the transmission module 540 is used to transmit data using the I2C bus.

[0103] When the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is higher than that of the second master device, the write module 530 is used to set the status bit on the first master device to the state of occupying the I2C bus, and the transmission module 540 is used to preempt the I2C bus and use the I2C bus to transmit data.

[0104] In a possible implementation, if the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is lower than that of the second master device, the read module 510 is further configured to monitor the status bit on the second master device. If the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the write module 530 is configured to set the status bit on the first master device to the state of occupying the I2C bus, and the transmission module 540 is configured to transmit data using the I2C bus.

[0105] In a possible implementation: the interrupt module 550 is used for:

[0106] The interrupt routine is started before the first master device uses the I2C bus to transmit data;

[0107] After the first master device transmits data using the I2C bus, disable the interrupt routine.

[0108] In a possible implementation, module 530 is used for:

[0109] After the first master device transmits data using the I2C bus, the write module 530 is used to set the status bit on the first master device to the state of not occupying the I2C bus.

[0110] In a possible implementation, module 520 is used for:

[0111] The first master device obtains the priority level of the second master device from the I2C bus. The priority level of the second master device is sent to the I2C bus by the second master device.

[0112] In possible implementations, the first master device is a microcontroller (MCU) and the second master device is a system-on-a-chip (SoC); or, the first master device is a SoC and the second master device is a microcontroller (MCU).

[0113] Figure 5 The various functional modules in it are used to implement Figures 3 to 4 For details of the steps in the method implementation examples, please refer to [link / reference]. Figures 3 to 4 The descriptions of relevant content in the method embodiments will not be repeated here for the sake of brevity.

[0114] This application also provides a device for controlling a multi-master device integrated circuit I2C bus, see [link to relevant documentation]. Figure 6 , Figure 6 This is a schematic diagram of a device 600 for a multi-master device control integrated circuit I2C bus provided in this application. This device is used to implement... Figures 3 to 4 In the embodiment of the method described, the device 600 includes a processor 610, a communication interface 620, and a memory 630. The processor 610, communication interface 620, and memory 630 can be interconnected via an internal bus 640, or they can communicate via wireless transmission or other means.

[0115] Taking a connection via bus 640 as an example, bus 640 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. Bus 640 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0116] Processor 610 may consist of at least one general-purpose processor, such as a CPU, or a combination of a CPU and hardware chips. The hardware chips may be application-specific integrated circuits (ASICs), programmable logic devices (PLDs), or combinations thereof. The PLDs may be complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), generic array logic (GALs), or any combination thereof. Processor 610 executes various types of digital storage instructions, such as software or firmware programs stored in memory 630, enabling device 600 to provide a wide range of services.

[0117] The memory 630 is used to store program code, and its execution is controlled by the processor 610 to perform the above-mentioned tasks. Figures 1 to 3 The steps described in the embodiments can be referred to the relevant descriptions of the embodiments shown above, and will not be repeated here.

[0118] The memory 630 may include volatile memory, such as RAM; the memory 630 may also include non-volatile memory, such as ROM or flash memory; the memory 630 may also include a combination of the above types.

[0119] The communication interface 620 can be a wired interface (e.g., an Ethernet interface), an internal interface (e.g., a high-speed serial computer expansion bus (PCIE) bus interface), a wired interface (e.g., an Ethernet interface), or a wireless interface (e.g., a cellular network interface or a wireless LAN interface), for communicating with other devices or modules.

[0120] The processor 610 and communication interface 620 in the device 600 can implement the functions and / or various steps and methods described in the above-mentioned method embodiments, which will not be elaborated here for the sake of brevity. The read module 510, write module 530, and interrupt module 550 in the device 500 can be located in the processor 610 of the device 600; the acquisition module 520 and transmission module 540 can be located in the communication interface 620 of the device 600.

[0121] It needs to be explained that, Figure 6 This is merely one possible implementation of an embodiment of this application. In practical applications, the controller may include more or fewer components, and no limitation is made here. For any content not shown or described in the embodiments of this application, please refer to the relevant descriptions in the foregoing method embodiments; they will not be repeated here.

[0122] This application provides a vehicle, such as Figure 7 As shown, Figure 7 This application provides a schematic diagram of a vehicle 700 structure. The vehicle 700 includes a first master device 710, a second master device 720, an I2C bus 730, a first slave device 740, and a second slave device 750. The first master device 710, the second master device 720, the first slave device 740, and the second slave device 750 are connected via the I2C bus 730. The first master device can be... Figure 5 The device 500 can also be Figure 6 The device 600 and the vehicle 700 are used to achieve... Figures 3 to 4 The various steps described in the method embodiments.

[0123] This application also provides a readable storage medium including program instructions that, when executed by a processor, perform some or all of the steps described in the above embodiments of the heat pump air conditioning control method.

[0124] This application also provides a computer program product, including program instructions, which, when executed by a controller, cause the controller to perform some or all of the steps described in the above embodiments of the heat pump air conditioning control method.

[0125] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0126] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, as a computer program product. The computer program product may contain code. When the computer program product is read and executed by a computer, some or all of the steps of the method described in the above method embodiments can be implemented. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium, or a semiconductor medium, etc.

[0127] The steps in the method of this application embodiment can be adjusted, merged, or deleted in order according to actual needs; the units in the device of this application embodiment can be divided, merged, or deleted according to actual needs.

[0128] The embodiments of this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A method for controlling an integrated circuit I2C bus for multiple master devices, characterized in that, The multi-master device includes at least a first master device and a second master device. Both the first master device and the second master device are provided with a status bit, which indicates whether the master device is currently occupying the I2C bus. The method includes: The first master device reads the status bits on the second master device; If the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the status bit on the first master device is set to the state of occupying the I2C bus, and the first master device uses the I2C bus to transmit data. If the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is higher than that of the second master device, the first master device sets its status bit to the state of occupying the I2C bus, the first master device preempts the I2C bus to make the second master device release the I2C bus, and the first master device uses the I2C bus to transmit data.

2. The method as described in claim 1, characterized in that, The method further includes: When the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is lower than that of the second master device, the first master device monitors the status bit on the second master device. When the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the first master device sets the status bit on the first master device to the state of occupying the I2C bus and uses the I2C bus to transmit data.

3. The method as described in claim 1 or 2, characterized in that, The method further includes: An interrupt routine is started before the first master device uses the I2C bus to transmit data; the interrupt routine is disabled after the first master device uses the I2C bus to transmit data.

4. The method according to any one of claims 1 to 3, characterized in that, After the first master device uses the I2C bus to transmit data, the following is also included: The first master device sets the status bit on the first master device to a state where the I2C bus is not occupied.

5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: The first master device obtains the priority level of the second master device from the I2C bus, and the priority level of the second master device is sent to the I2C bus by the second master device.

6. The method according to any one of claims 1 to 5, characterized in that, The first master device is a microcontroller (MCU), and the second master device is a system-on-a-chip (SoC); or, the first master device is a SoC, and the second master device is a microcontroller (MCU).

7. A device for controlling a multi-master device integrated circuit I2C bus, characterized in that, Applied to a first master device, the multi-master device includes at least the first master device and a second master device, both the first master device and the second master device are provided with a status bit, the status bit being used to indicate whether the master device is currently occupying the I2C bus, the device includes: The read module is used to read the status bits on the second master device, which are used to indicate whether the second master device is currently occupying the I2C bus. The write module and the transmission module are configured such that, when the status bit on the second master device indicates that the second master device is not occupying the I2C bus, the write module is used to set the status bit on the first master device to be occupying the I2C bus, and the transmission module is used to transmit data using the I2C bus. When the status bit on the second master device indicates that the second master device is occupying the I2C bus, and the priority level of the first master device is higher than that of the second master device, the write module is used to set the status bit on the first master device to be occupying the I2C bus, and the transmission module is used to preempt the I2C bus, the second master device releases the I2C bus, and the first master device uses the I2C bus to transmit data.

8. A device for controlling a multi-master device integrated circuit I2C bus, characterized in that, The method includes a memory and a processor, the memory being used to store instructions, and the processor being used to execute the instructions stored in the memory to implement the method as claimed in any one of claims 1 to 6.

9. A readable storage medium, characterized in that, Includes program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1 to 6.

10. A vehicle, characterized in that, It includes a first master device, a second master device, and an I2C bus, wherein the first master device is the first master device as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and device for solving conflict of multiple hosts on I2C bus

    CN101894088A

  • Arbitration method and system of I2C (Inter-Integrated Circuit) bus

    CN107766267A