Communication method and system based on I2C (Inter-Integrated Circuit) and electronic equipment

By switching the GPIO pin to SCL and SDA signal lines in I2C communication, the problem of GPIO resource tightness when the Slave device notifies the Master device for communication is solved, reducing hardware cost and PCB size.

CN120343050APending Publication Date: 2025-07-18LCFC HEFEI ELECTRONICS TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510472617.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-15
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In existing I2C communication, Slave devices need to notify the Master device to communicate through an additional INT pin, resulting in tight GPIO resources and increasing PCB size and hardware costs.

Method used

Communication between the master and slave devices is achieved by switching the general-purpose output pin GPO and the general-purpose input pin GPI in different states, and the additional INT pin requirement is avoided.

Benefits of technology

Solve the problem of tight GPIO resources, reduce hardware costs and avoid increase in PCB size.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120343050A_ABST
    Figure CN120343050A_ABST
Patent Text Reader

Abstract

The invention provides an I2C (Inter-Integrated Circuit)-based communication method and system and electronic equipment, and the method comprises the steps that master equipment firstly sets a GPO (General Purpose Optimization) into a low-level state, and slave equipment detects the low-level state of the GPO; the master device recovers the GPO to the high level state, the slave device responds to the GPO to recover to the high level state, and the master device and the slave device set the GPO to be SCL and set the GPI to be SDA at the same time; or, the slave device sets the GPI to be in the low-level state, and the master device detects and responds to the GPI to be in the low-level state, and sets the GPO to be in the low-level state; the slave device detects and responds to the condition that the GPO is set to be in the low-level state, and the GPI is set to be in the high-level state; the master device detects and responds to the high level state of the GPI to set the GPO to be in the high level state, the slave device detects and responds to the GPO to be in the high level state, and the master device and the slave device set the GPO to be SCL and set the GPI to be SDA at the same time; and the slave device communicates with the master device through the SCL and the SDA of the I2C to enter a communication stage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of communication technologies, and in particular, to an I2C-based communication method, system, and electronic device. Background Art

[0002] I2C (Inter-Integrated Circuit), as an efficient serial communication protocol, is widely used in laptop design for data interconnection between components and circuits. It only requires two signal lines (SCL serial clock and SDA serial data) to support communication among multiple devices. For example, it enables the EC (Embedded Controller) as the Master to actively transmit data to the Slave side. There is a GPIO (General-purpose input / output) pin between the Slave device and the EC set as the INT (Interrupt) pin. When the Slave device has data to send or requires a certain operation from the master device, it pulls down the INT pin (i.e., sets it to a low level) as a clear signal to notify the EC. The EC continuously monitors the status of the INT pin. Once it detects this signal, it will actively initiate communication with the slave device according to the I2C communication protocol. The communication process continues until the slave device completes its communication requirements and restores the INT pin to a high level, indicating the end of the communication.

[0003] However, with the popularization of AIPC and the increase in sensor devices, each Slave device usually needs to actively notify the Master to initiate communication through an additional INT pin (interrupt pin), which leads to a shortage of GPIO resources. In addition, the additional INT pin not only increases the PCB size but also increases the need for pull-up resistors; and when the number of GPIOs is insufficient to meet the requirements of current or future possible connected hardware components, it may be necessary to add a GPIO Expander or Sensor Hub, further increasing costs. Summary of the Invention

[0004] The present disclosure provides an I2C-based communication method, system, and electronic device to at least solve the above technical problems existing in the prior art.

[0005] According to a first aspect of the present disclosure, there is provided an I2C-based communication method, which is applied to a master device, and the method includes:

[0006] Initiate a first communication request to the slave device, triggering a first conversion condition, including: first setting the general-purpose output pin GPO to a low level state and then restoring it to a high level state; and setting the GPO as the serial clock signal line SCL of I2C, and setting the general-purpose input pin GPI as the serial data signal line SDA of the I2C; or,

[0007] Receive a second communication request from the slave device, triggering a second conversion condition, including: detecting and responding to the slave device setting the GPI to a low level state by setting the GPO to a low level state; detecting and responding to the slave device setting the GPI to a high level state by setting the GPO to a high level state; and setting the GPO as the SCL and setting the GPI as the SDA;

[0008] Communicate with the slave device via the SCL and SDA of the I2C to enter the communication stage.

[0009] In an implementable manner, before initiating communication with the slave device or responding to the communication request of the slave device, the master device is in a waiting stage;

[0010] In the waiting stage, the SCL and SDA are configured as general-purpose input / output pins GPIO.

[0011] In an implementable manner, after completing communication with the slave device, restore the GPO to its initial state, and the master device enters the waiting stage.

[0012] In an implementable manner, when the number of communication failures via the I2C exceeds a preset number during the communication stage, reset the signal lines of the I2C.

[0013] According to a second aspect of the present disclosure, there is provided a communication method based on I2C, which is applied to a slave device, and the method includes:

[0014] Receive a first communication request from a master device, triggering a first conversion condition, including: detecting that the master device first sets the GPO to a low level state, waiting for and responding to the master device restoring the GPO to a high level state, setting the GPO as the SCL of the I2C, and setting the GPI as the SDA of the I2C; or,

[0015] Send a second communication request to the master device, triggering a second conversion condition, including: setting the GPI to a low level state; detecting and responding to the master device setting the GPO to a low level state by setting the GPI to a high level state; detecting and responding to the master device setting the GPO to a high level state by setting the GPO as the SCL and setting the GPI as the SDA;

[0016] Communicate with the master device via the SCL and SDA to enter the communication phase.

[0017] In one possible implementation, after completing the communication with the master device, the GPI is restored to an initial state, and the slave device enters a waiting phase.

[0018] According to a third aspect of the present disclosure, there is provided an I2C-based communication system, the system comprising a master device and at least one slave device, including:

[0019] The master device initiates a first communication request to the slave device to trigger a first conversion condition, including: the master device first sets the GPO to a low level state, and the slave device detects the low level state of the GPO; the master device restores the GPO to a high level state, and the slave device responds to the GPO being restored to a high level state, and the master device and the slave device simultaneously set the GPO to SCL and set the GPI to SDA; or,

[0020] The slave device initiates a second communication request to the master device to trigger a second conversion condition, including: the slave device sets the GPI to a low level state, the master device detects and responds to the GPI being in a low level state, and sets the GPO to a low level state; the slave device detects and responds to the GPO being set to a low level state, and sets the GPI to a high level state; the master device detects and responds to the GPI being set to a high level state, and sets the GPO to a high level state, the slave device detects and responds to the GPO being set to a high level state, and the master device and the slave device simultaneously set the GPO to the SCL and the GPI to the SDA;

[0021] The slave device communicates with the master device via the SCL and SDA of the I2C and enters the communication phase.

[0022] In one possible implementation, when the master device and the slave device simultaneously initiate a communication request to each other, it includes:

[0023] The master device initiates a third communication request to the slave device, triggering a third conversion condition to enter a communication phase;

[0024] The slave device temporarily stores the pending event in the cache and responds to the third communication request to enter the communication phase;

[0025] After completing the communication, the master device and the slave device enter a waiting phase;

[0026] The slave device sends a fourth communication request to the master device, triggering a fourth conversion condition to enter a communication phase;

[0027] In response to the fourth communication request, the master device enters the communication phase to process the event to be processed;

[0028] After the communication is completed, the master device and the slave device enter the waiting phase.

[0029] In an implementable manner, the master device sends a third communication request to the slave device, triggers a third conversion condition, and enters the communication phase; the slave device temporarily stores the event to be processed in the buffer, and at the same time, in response to the third communication request, enters the communication phase, including:

[0030] The master device sets the GPO to a low level state; the slave device detects and responds to the low level state of the GPO, and sets the GPI to a low level state; the master device and the slave device simultaneously set the GPO to the SCL and the GPI to the SDA; the master device and the slave device communicate through the SCL and the SDA and enter the communication phase;

[0031] The slave device sends a fourth communication request to the master device, triggers a fourth conversion condition, and enters the communication phase; the master device enters the communication phase to process the event to be processed in response to the fourth communication request, including:

[0032] The slave device sets the GPI to a low level state, the master device detects and responds to the low level state of the GPI, and sets the GPO to a low level state; the master device and the slave device simultaneously set the GPO to the SCL and the GPI to the SDA, and the master device and the slave device communicate through the SCL and the SDA and enter the communication phase.

[0033] According to a fourth aspect of the present disclosure, there is provided an electronic device, including:

[0034] At least one processor; and

[0035] A memory communicatively connected to the at least one processor; wherein,

[0036] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in the present disclosure.

[0037] According to a fifth aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the method described in the present disclosure.

[0038] The I2C-based communication method, system, and electronic device of the present disclosure enable communication requests between the master device and the slave device to be triggered in two ways. One is that the master device actively initiates a communication request. First, the master device sets GPO to a low level state, and the slave device detects the low level state of GPO. The master device restores GPO to a high level state. In response to the restoration of GPO to a high level state, the master device and the slave device simultaneously set GPO to SCL and set the general-purpose input pin GPI to SDA. The other way is that the slave device actively sends a communication request to the master device. The slave device sets GPI to a low level state. The master device detects and responds to the low level state of GPI by setting GPO to a low level state. The slave device detects and responds to the setting of GPO to a low level state by setting GPI to a high level state. The master device detects and responds to the high level state of GPI by setting GPO to a high level state. The slave device detects and responds to the setting of GPO to a high level state. The master device and the slave device simultaneously set GPO to SCL and set GPI to SDA. In this way, the communication system not only solves the problem of tight GPIO resources, but also avoids the need to increase the PCB size and pull-up resistors, reducing the hardware cost.

[0039] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it used to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features, and advantages of the exemplary embodiments of the present disclosure will become readily understandable. In the drawings, several embodiments of the present disclosure are shown in an exemplary rather than restrictive manner, where:

[0041] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.

[0042] Figure 1 Shows the implementation process schematic of the I2C-based communication method according to an embodiment of the present disclosure Figure 1 ;

[0043] Figure 2 Shows the implementation process schematic of the I2C-based communication method according to an embodiment of the present disclosure Figure 2 ;

[0044] Figure 3 Shows the structural schematic diagram of the I2C-based communication system according to an embodiment of the present disclosure;

[0045] Figure 4 Shows the implementation process schematic of the I2C-based communication method according to an embodiment of the present disclosure Figure 3 ;

[0046] Figure 5 The figure shows the implementation process of the I2C-based communication method according to the embodiments of the present disclosure. Figure 4 ;

[0047] Figure 6 The figure shows the schematic diagram of the composition structure of an electronic device according to the embodiments of the present disclosure. Detailed implementation manners

[0048] To make the objectives, features, and advantages of the present disclosure more obvious and understandable, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative efforts shall fall within the protection scope of the present disclosure.

[0049] To more efficiently utilize the limited GPIO resources, the GPIO pins of the present disclosure are designed with an Alternative function (special function mode or multiplexing function). In the standard GPIO mode, the pins can be configured with basic functions such as input, output, pull-up, and pull-down. However, the Alternate function allows these pins to be reconfigured as specific peripheral interfaces, such as interfaces for communication protocols such as I2C, SPI, and UART, or pins for functions such as timers, interrupts, PWM (pulse width modulation), ADC (analog-to-digital converter), and SMBUS.

[0050] Based on the GPIO pins with the Alternate function, the present disclosure provides an I2C-based communication method, which is applied to a master device, such as Figure 1 As shown, the method includes:

[0051] Step 101: Initiate a first communication request to the slave device, triggering a first conversion condition, including: first setting the general-purpose output pin GPO to a low level state and then restoring it to a high level state; and setting GPO as the serial clock signal line SCL of I2C and setting the general-purpose input pin GPI as the serial data signal line SDA of I2C.

[0052] In this example, the master device, i.e., the Master device, is the device that occupies the dominant and controlling position in the communication network or device interconnection environment. It has the ability to initiate communication sessions, manage communication processes, and send instructions or data to slave devices (Slave devices or peripheral devices), such as embedded controllers, etc. The slave device, i.e., the Slave device, usually refers to the device that receives instructions or data from the master device in a communication or control system. It is in a subordinate position and responds passively to the requests of the master device, and performs corresponding operations or tasks according to these requests, such as input / output devices, etc.

[0053] In this example, in step 101, the master device actively initiates a communication request to the slave device. Specifically, the master device first sets the pin of the GPO to a low level state through control and waits for the slave device to detect it, and then restores the GPO to a high level state. This process serves as a signal to trigger the first conversion condition. After the trigger condition is met, the master device configures the GPO as the SCL of I2C to provide a clock signal in the subsequent communication process to synchronize the data transmission between the master device and the slave device; and configures another general-purpose input pin GPI as the SDA of I2C to transmit actual data signals. In this way, when the first conversion condition is triggered, the master device completes the switching from the GPIO mode to the I2C mode.

[0054] Or,

[0055] Step 102: Receive the second communication request from the slave device, trigger the second conversion condition, including: detecting and responding to the slave device setting the GPI to a low level state by setting the GPO to a low level state; detecting and responding to the slave device setting the GPI to a high level state by setting the GPO to a high level state; and setting the GPO as SCL and setting the GPI as SDA.

[0056] In this example, in some application scenarios, the slave device needs to actively exchange data or update the status with the master device. At this time, the slave device will initiate a communication request, i.e., the second communication request, to notify the master device to prepare for data communication.

[0057] The master device judges the communication request of the slave device by detecting the state of GPI in its GPIO interface. Specifically: when the slave device sets the GPI to a low level state, the master device will detect this change and correspondingly set its GPO to a low level state. Subsequently, when the slave device sets the GPI to a high level state, the master device also detects and correspondingly sets its GPO to a high level state. This process serves as a signal to trigger the second conversion condition. After the trigger condition is met, the master device sets the GPO as SCL and sets the GPI as SDA. In this way, when the second conversion condition is triggered, the master device completes the switching from the GPIO mode to the I2C mode.

[0058] Step 103: Communicate with the slave device via the SCL and SDA of I2C to enter the communication stage.

[0059] In this example, after successfully switching the pin functions, the master device and the slave device can perform standard I2C communication via SCL and SDA, including processes such as sending a start condition, an address byte, data bytes, and receiving an acknowledgment signal, and enter the communication stage. In the communication stage, the master device is responsible for sending data to the slave device or receiving data from the slave device, and this process follows the regulations of the I2C communication protocol.

[0060] In one example, before initiating communication with the slave device or responding to the communication request of the slave device, the master device is in a waiting stage; in the waiting stage, SCL and SDA are configured as general-purpose input / output pins GPIO.

[0061] In this example, in the waiting stage, the master device is in an idle state, ready to receive a communication request from the slave device or ready to initiate communication with the slave device. In this stage, SCL and SDA are configured as general-purpose input / output pins GPIO, perform basic functions in the standard GPIO mode, and at the same time detect the communication request of the slave device.

[0062] In one example, after completing communication with the slave device, restore the GPO to its initial state, and the master device enters the waiting stage.

[0063] In this example, after completing communication with the slave device, the master device will enter the recovery stage. In this stage, the GPO will be restored to its initial state, which can be used to perform basic functions in the standard GPIO mode, or be set to a specific level state according to the needs of the system. At the same time, the master device will also re-enter the waiting stage, ready to receive the next communication request from the slave device or initiate a new communication.

[0064] In one example, when the number of communication failures via I2C exceeds the preset number during the communication stage, reset the signal lines of I2C.

[0065] In this example, the situations of communication failure include: 1. The slave device is unable to respond immediately while handling other things. In I2C communication, if the slave device is unable to respond to the communication request of the master device in a timely manner due to being busy with other tasks, then the communication will fail. 2. During the transmission process, the receiving end receives data that it cannot understand. In I2C communication, for example, if the data sent by the master device does not conform to the protocol specifications, or the slave device is unable to parse the received data (such as incorrect data format, unknown command code, etc.), then the slave device cannot respond correctly, resulting in communication failure, and vice versa.

[0066] When the number of communication failures exceeds a certain range, the master device will reset the signal lines of I2C. The master device can configure SCL and SDA to a low level state and maintain it for a period of time, and then the initiator can initiate communication again.

[0067] The present disclosure also provides an I2C-based communication method, which is applied to a slave device, as Figure 2 shown, the method includes:

[0068] Step 201: Receive a first communication request from the master device, triggering a first conversion condition, including: detecting that the master device first sets GPO to a low level state, waiting for and responding to the master device to restore GPO to a high level state, and setting GPO to SCL of I2C and GPI to SDA of I2C.

[0069] In this example, corresponding to step 101, the slave device receives a first communication request from the master device: the slave device first detects that the master device sets GPO to a low level state and remains in a waiting state until the master device restores GPO to a high level state, then resets GPO to SCL in I2C communication and simultaneously sets the general-purpose GPI to SDA in I2C communication.

[0070] Or,

[0071] Step 202: Send a second communication request to the master device, triggering a second conversion condition, including: setting GPI to a low level state; detecting and responding to the master device setting GPO to a low level state; detecting and responding to the master device setting GPO to a high level state, setting GPO to SCL, and setting GPI to SDA.

[0072] In this example, corresponding to step 102, the slave device first sets GPI to a low level state and waits for the detection and response of the master device; subsequently, after the slave device detects that the master device sets GPO to a low level state, it sets GPI to a high level state and continues to wait for the detection and response of the master device; after the slave device detects that the master device restores GPO to a high level state, it simultaneously converts GPO and GPI to SCL and SDA in I2C communication respectively.

[0073] Step 203: Communicate with the master device through SCL and SDA and enter the communication stage.

[0074] In this example, after successfully switching the pin functions, the master device and the slave device can perform standard I2C communication through SCL and SDA and enter the communication stage. Through SCL and SDA, the two can perform data transmission and reception to achieve the communication purpose.

[0075] In one example, after communication with the master device is completed, the GPI is restored to its initial state and the slave device enters the waiting phase.

[0076] In this example, after communication with the master device is completed, the slave device enters the recovery phase. In this phase, the GPI is restored to its initial state and can be used to perform basic functions in the standard GPIO mode or set to a specific level state according to the needs of the system. At the same time, the slave device also re-enters the waiting phase, ready to receive the next communication request from the master device or initiate a new communication.

[0077] The present disclosure also provides an I2C-based communication system, as Figure 3 shown, the system includes a master device and at least one slave device, including:

[0078] The master device initiates a first communication request to the slave device, triggering a first conversion condition, as Figure 4 shown, including: the master device first sets the GPO to a low level state, and the slave device detects the low level state of the GPO; the master device restores the GPO to a high level state, and the slave device responds to the GPO being restored to a high level state. The master device and the slave device simultaneously set the GPO to SCL and set the general-purpose input pin GPI to SDA.

[0079] In this example, the process of the master device actively sending a communication request to the slave device: the master device first sets the GPO to a low level state, indicating that the master device is ready to initiate communication. The slave device detects the low level state of the GPO, indicating that it has received the communication requirement of the master device and is waiting. The master device then restores the GPO to a high level state. The slave device responds to the high level state of the GPO and, together with the master device, sets the GPO to SCL and the GPI to SDA. At this time, the system is ready to enter the formal I2C communication phase.

[0080] Or,

[0081] The slave device initiates a second communication request to the master device, triggering a second conversion condition, as Figure 5 shown, including: the slave device sets the GPI to a low level state, the master device detects and responds to the GPI being at a low level state and sets the GPO to a low level state; the slave device detects and responds to the GPO being set to a low level state and sets the GPI to a high level state; the master device detects and responds to the high level state of the GPI and sets the GPO to a high level state. The slave device detects and responds to the GPO being set to a high level state. The master device and the slave device simultaneously set the GPO to SCL and the GPI to SDA.

[0082] In this example, the process of the slave device actively sending a communication request to the master device is as follows: The slave device first sets GPI to a low level state to initiate a communication request to the master device. The master device detects the low level state of GPI and responds to this request by setting GPO to a low level state, indicating that it has received the communication request from the slave device. The slave device detects the low level state of GPO, receives the confirmation from the master device that its request has been received, and then sets GPI to a high level state. The master device detects the high level state of GPI and responds to this change by setting GPO to a high level state. The slave device detects the high level state of GPO and, together with the master device, sets GPO to SCL and GPI to SDA. At this time, the system is ready to enter the formal I2C communication stage.

[0083] The slave device and the master device communicate through SCL and SDA of I2C and enter the communication stage.

[0084] A communication system based on I2C according to the present disclosure. In this system, the communication request between the master device and the slave device can be triggered in two ways. One is that the master device actively initiates a communication request. The master device first sets GPO to a low level state, and the slave device detects the low level state of GPO; the master device restores GPO to a high level state, and the slave device responds to the restoration of GPO to a high level state. The master device and the slave device simultaneously set GPO to SCL and set the general input pin GPI to SDA. The other way is that the slave device actively sends a communication request to the master device. The slave device sets GPI to a low level state, and the master device detects and responds to the low level state of GPI by setting GPO to a low level state; the slave device detects and responds to GPO being set to a low level state by setting GPI to a high level state; the master device detects and responds to the high level state of GPI by setting GPO to a high level state, and the slave device detects and responds to GPO being set to a high level state. The master device and the slave device simultaneously set GPO to SCL and set GPI to SDA. In this way, this communication system not only solves the problem of tight GPIO resources, but also avoids the need to increase the PCB size and pull-up resistors, reducing the hardware cost.

[0085] In one example, when the master device and the slave device simultaneously initiate a communication request to each other, it includes: The master device initiates a third communication request to the slave device, triggering a third conversion condition and entering the communication stage; the slave device temporarily stores the event to be processed in the buffer and, at the same time, responds to the third communication request and enters the communication stage; after the communication is completed, the master device and the slave device enter the waiting stage; the slave device sends a fourth communication request to the master device, triggering a fourth conversion condition and entering the communication stage; the master device responds to the fourth communication request and enters the communication stage to process the event to be processed; after the communication is completed, the master device and the slave device enter the waiting stage.

[0086] In this example, since the communication of the master device is carried out in a Loop (cycle) manner, that is, after a communication is completed, the master device will first return to the inspection stage to check if there is a new communication requirement. If so, the master device will initiate a communication request again to conduct a new round of communication with the slave device.

[0087] Therefore, for the complex situation where both the master device and the slave device initiate communication requests simultaneously, the master device needs to initiate a third communication request first to trigger the third conversion condition and enter the communication stage. Before or after detecting the master device's request simultaneously, the slave device has already prepared to initiate a communication request to the master device. However, due to the master device's request arriving first, the slave device needs to temporarily store the event to be processed in the internal cache and respond to the master device's third communication request to enter the communication stage.

[0088] After the master device and the slave device complete the first communication, they enter the waiting stage. At this time, in order to process the previously stored event to be processed, the slave device will initiate a fourth communication request to the master device, trigger the fourth conversion condition, and enter the communication stage. The master device responds to this request and enters the communication stage to process the event to be processed or conduct other necessary data exchanges, and the master and slave devices communicate again. After completing the second communication, both the master device and the slave device enter the waiting stage again to wait for the next communication request.

[0089] In one example, the master device initiates a third communication request to the slave device, triggers the third conversion condition, and enters the communication stage. The slave device temporarily stores the event to be processed in the cache and simultaneously responds to the third communication request to enter the communication stage, including: the master device sets GPO to a low level state; the slave device detects and responds to the low level state of GPO and sets GPI to a low level state; the master device and the slave device simultaneously set GPO to SCL and GPI to SDA; the master device and the slave device communicate through SCL and SDA and enter the communication stage.

[0090] In this example, the implementation process of the master device initiating a third communication request to the slave device, triggering the third conversion condition, and the master and slave devices entering the communication stage includes: the master device first sets GPO to a low level state; the slave device detects the low level state of GPO and responds to this signal by setting GPI to a low level state; then, the master device and the slave device simultaneously set GPO to SCL and GPI to SDA, preparing to enter the communication stage for the first communication.

[0091] In one example, a fourth communication request is sent from the slave device to the master device, triggering a fourth conversion condition and entering the communication stage; in response to the fourth communication request, the master device enters the communication stage to process the pending events, including: the slave device sets GPI to a low level state, and the master device detects and responds to the low level state of GPI by setting GPO to a low level state; the master device and the slave device simultaneously set GPO to SCL and GPI to SDA, and the master device and the slave device communicate through SCL and SDA, entering the communication stage.

[0092] In this example, after the master device initiates and completes the first communication with the slave device and ends, the slave device sends a fourth communication request to the master device, triggering a fourth conversion condition, and the master and slave devices enter the communication stage again. The specific implementation process includes: the slave device first sets GPI to a low level state as a signal for the start of the second communication; the master device detects the low level state of GPI and responds to this signal by setting GPO to a low level state as well. Then, the master device and the slave device simultaneously set GPO to SCL and GPI to SDA, preparing to enter the communication stage for the second communication to process the pending events.

[0093] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.

[0094] Figure 6 A schematic block diagram of an example electronic device 800 that can be used to implement the embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0095] As Figure 6 shown, the electronic device 800 includes a computing unit 801, which can execute various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 802 or the computer program loaded from the storage unit 808 into the random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other through a bus 804. The input / output (I / O) interface 805 is also connected to the bus 804.

[0096] Multiple components in device 800 are connected to I / O interface 805, including: input unit 806, such as a keyboard, mouse, etc.; output unit 807, such as various types of displays, speakers, etc.; storage unit 808, such as a disk, optical disc, etc.; and communication unit 809, such as a network card, modem, wireless communication transceiver, etc. Communication unit 809 allows device 800 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunications networks.

[0097] Computing unit 801 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of computing unit 801 include but are not limited to a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Computing unit 801 executes the various methods and processes described above, such as the I2C-based communication method. For example, in some embodiments, the I2C-based communication method can be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed onto device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by computing unit 801, one or more steps of the I2C-based communication method described above can be executed. Alternatively, in other embodiments, computing unit 801 can be configured to execute the I2C-based communication method in any other suitable way (e.g., by means of firmware).

[0098] The various embodiments of the systems and techniques described above in this document can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor, and can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit the data and instructions to the storage system, the at least one input device, and the at least one output device.

[0099] The program code for implementing the methods of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general purpose computer, a special purpose computer, or other programmable data processing device, such that the program codes, when executed by the processor or controller, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0100] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0101] In order to provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0102] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), and the Internet.

[0103] A computer system can include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, a server of a distributed system, or a server incorporating blockchain.

[0104] It should be understood that various forms of the processes shown above can be used, steps can be reordered, added, or deleted. For example, the steps recited in this disclosure can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this is not limited herein.

[0105] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" can explicitly or implicitly include at least one of such features. In the description of this disclosure, "a plurality" means two or more, unless otherwise specifically defined.

[0106] As described above, the above are only specific embodiments of this disclosure, but the protection scope of this disclosure is not limited thereto. Any person skilled in the art within the technical scope disclosed in this disclosure can easily think of changes or substitutions, which should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be subject to the protection scope of the claims.

Claims

1. A communication method based on I2C, characterized in that, The method is applied to a master device, and the method includes: Sending a first communication request to a slave device to trigger a first conversion condition, including: first setting a general-purpose output pin GPO to a low level state and then restoring it to a high level state; and setting the GPO as a serial clock signal line SCL of I2C and setting a general-purpose input pin GPI as a serial data signal line SDA of the I2C; or, Receiving a second communication request from the slave device to trigger a second conversion condition, including: detecting and responding to the slave device setting the GPI to a low level state and setting the GPO to a low level state; detecting and responding to the slave device setting the GPI to a high level state and setting the GPO to a high level state; and setting the GPO as the SCL and setting the GPI as the SDA; Communicating with the slave device through the SCL and SDA of the I2C to enter a communication phase.

2. The method according to claim 1, wherein Before sending a communication request to the slave device or responding to a communication request from the slave device, the master device is in a waiting phase; In the waiting phase, the SCL and SDA are configured as general-purpose input / output pins GPIO.

3. The method according to claim 1, wherein After completing communication with the slave device, restoring the GPO to its initial state, and the master device enters the waiting phase.

4. The method according to claim 1, wherein When the number of communication failures through the I2C exceeds a preset number during the communication phase, reset the signal lines of the I2C.

5. A communication method based on I2C, characterized in that, The method is applied to a slave device, and the method includes: Receiving a first communication request from a master device to trigger a first conversion condition, including: detecting that the master device first sets the GPO to a low level state, waiting for and responding to the master device restoring the GPO to a high level state, setting the GPO as the SCL of the I2C, and setting the GPI as the SDA of the I2C; or, Sending a second communication request to the master device to trigger a second conversion condition, including: setting the GPI to a low level state; detecting and responding to the master device setting the GPO to a low level state and setting the GPI to a high level state; detecting and responding to the master device setting the GPO to a high level state, setting the GPO as the SCL, and setting the GPI as the SDA; Communicating with the master device through the SCL and SDA to enter a communication phase.

6. The method according to claim 5, wherein After completing communication with the master device, restoring the GPI to its initial state, and the slave device enters the waiting phase.

7. An I2C-based communication system, the system includes a master device and at least one slave device, including: The master device sends a first communication request to the slave device to trigger a first conversion condition, including: the master device first sets the GPO to a low level state, and the slave device detects the low level state of the GPO; the master device restores the GPO to a high level state, the slave device responds to the restoration of the GPO to a high level state, and the master device and the slave device simultaneously set the GPO as the SCL and set the GPI as the SDA; or, The slave device initiates a second communication request to the master device, triggering a second conversion condition, including: the slave device sets the GPI to a low level state, the master device detects and responds to the GPI being in the low level state, and sets the GPO to a low level state; the slave device detects and responds to the GPO being set to the low level state, and sets the GPI to a high level state; the master device detects and responds to the high level state of the GPI and sets the GPO to a high level state, the slave device detects and responds to the GPO being set to the high level state, and the master device and the slave device simultaneously set the GPO to the SCL and the GPI to the SDA; The slave device communicates with the master device through the SCL and SDA of the I2C and enters the communication phase.

8. The system according to claim 7, characterized in that, When the master device and the slave device simultaneously initiate communication requests to each other, including: The master device initiates a third communication request to the slave device, triggering a third conversion condition and entering the communication phase; The slave device temporarily stores the event to be processed in the buffer and simultaneously responds to the third communication request and enters the communication phase; After completing the communication, the master device and the slave device enter the waiting phase; The slave device sends a fourth communication request to the master device, triggering a fourth conversion condition and entering the communication phase; The master device responds to the fourth communication request and enters the communication phase to process the event to be processed; After completing the communication, the master device and the slave device enter the waiting phase.

9. The system according to claim 8, wherein The master device initiates a third communication request to the slave device, triggering a third conversion condition and entering the communication phase; The slave device temporarily stores the event to be processed in the buffer and simultaneously responds to the third communication request and enters the communication phase, including: The master device sets the GPO to a low level state; the slave device detects and responds to the low level state of the GPO and sets the GPI to a low level state; the master device and the slave device simultaneously set the GPO to the SCL and the GPI to the SDA; the master device communicates with the slave device through the SCL and SDA and enters the communication phase; The slave device sends a fourth communication request to the master device, triggering a fourth conversion condition and entering the communication phase; the master device responds to the fourth communication request and enters the communication phase to process the event to be processed, including: The slave device sets the GPI to a low level state, the master device detects and responds to the low level state of the GPI and sets the GPO to a low level state; the master device and the slave device simultaneously set the GPO to the SCL and the GPI to the SDA, and the master device communicates with the slave device through the SCL and SDA and enters the communication phase.

10. An electronic device, characterized in that, Including: At least one processor; And A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method according to any one of claims 1-4 or 5-6.