Circuits, methods, and network devices for simulating I2C communication using a single GPIO pin.

By designing the control unit and voltage divider unit in the I2C communication circuit, and using a single GPIO line to simulate the I2C protocol, the problem of insufficient hardware resources was solved, and normal I2C communication was achieved.

CN117112476BActive Publication Date: 2026-11-17CHINA MOBILE M2M +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210528920.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-16
Publication Date
2026-11-17
Estimated Expiration
2042-05-16

AI Technical Summary

Technical Problem

In situations where hardware resources are insufficient, existing technologies cannot simulate I2C protocol communication using a single GPIO line.

Method used

An I2C communication circuit was designed, including a control unit and a voltage divider unit. The control unit adjusts the resistance value of the voltage divider unit according to the SCL and SDA interface signals of the master I2C device, and the I2C protocol is simulated using a single GPIO line.

Benefits of technology

It enables I2C slave device communication through a single GPIO line, improving the utilization efficiency of hardware resources and supporting normal I2C communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117112476B_ABST
    Figure CN117112476B_ABST
Patent Text Reader

Abstract

This invention provides a circuit, method, and network device for simulating I2C device communication using a single GPIO line. The circuit includes a control unit and a voltage divider unit. The control unit is connected to the SCL and SDA interfaces of the master I2C device, respectively. The first terminal of the voltage divider unit is connected to the GPIO interface of the slave device, and the second terminal of the voltage divider unit is connected to the control unit. The control unit controls the resistance value of the voltage divider unit based on the signals output from the SCL and SDA interfaces of the master I2C device, thereby adjusting the voltage signal received by the GPIO interface of the slave device. This circuit achieves the technical effect of simulating I2C slave device communication using a single GPIO line.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and in particular to a circuit, method, and network device for communication using a single GPIO pin to simulate an I2C device. Background Technology

[0002] MCUs (Microcontroller Units) and communication chips come with a variety of peripheral interfaces of different types and quantities. These peripheral interfaces are used to communicate and exchange data with peripherals. The interfaces are divided into different types, such as SPI / UART / I2C / SDIO / ADC, etc. These interfaces are mapped through GPIO (General-purpose input / output) interfaces. As long as the chip itself maps these hardware interfaces to a GPIO that supports analog interfaces, it can be mapped to I2C, ADC (Analog to Digital Converter), or SPI (Serial Peripheral Interface) interfaces at any time.

[0003] Some MCUs or communication chips lack an I2C hardware interface or have insufficient hardware interfaces, forcing them to use GPIO to simulate the I2C protocol waveform for data communication. In existing technology, simulating the I2C protocol using GPIO requires two GPIO lines: one GPIO line to simulate the I2C SCL (I2C clock signal) and one GPIO line to simulate the SDA (I2C data signal line).

[0004] However, in some cases, the device lacks sufficient hardware resources and there are not enough GPIO lines available, making I2C communication impossible. Summary of the Invention

[0005] This invention proposes a circuit, method, and network device for simulating I2C communication using a single GPIO line, in order to solve the problem of how to simulate I2C protocol communication using a single GPIO line when hardware resources are insufficient.

[0006] To solve the above-mentioned technical problems, the present invention is implemented as follows:

[0007] In a first aspect, embodiments of the present invention provide an I2C communication circuit, the circuit comprising: a control unit and a voltage divider unit;

[0008] The control unit is connected to the SCL interface and SDA interface of the main I2C device, respectively.

[0009] The first end of the voltage divider unit is connected to the GPIO interface of the slave device, and the second end of the voltage divider unit is connected to the control unit;

[0010] The control unit is used to control the resistance value of the voltage divider unit according to the signals output from the SCL and SDA interfaces of the master I2C device, so as to adjust the voltage signal received from the GPIO interface of the slave device.

[0011] Optionally, the voltage divider unit includes: a first resistor, a second resistor, and a third resistor; the control unit includes a first controller and a second controller;

[0012] The first controller includes a control electrode, a first electrode, and a second electrode. The control electrode of the first controller is connected to the SCL interface of the main I2C device. The first electrode of the first controller is connected to the second end of the first resistor. The second electrode of the first controller is connected to the second end of the third resistor.

[0013] The second controller includes a control electrode, a first electrode, and a second electrode. The control electrode of the second controller is connected to the SDA interface of the main I2C device. The first electrode of the second controller is connected to the second end of the second resistor. The second electrode of the second controller is connected to the second end of the third resistor.

[0014] The first end of the first resistor, the first end of the second resistor, and the first end of the third resistor are connected in parallel and then connected to the GPIO interface of the slave device.

[0015] Optionally, the I2C communication circuit further includes a mode adjustment unit, which includes a third controller:

[0016] The third controller includes a control electrode, a first electrode, and a second electrode. The control electrode of the third controller is connected to the GPIO interface of the slave device, the first electrode of the third controller is connected to the SDA interface of the master I2C device, and the second electrode of the third controller is grounded.

[0017] Optionally, the voltage divider unit further includes a fourth resistor, the first end of which is connected to the first power supply, and the second end of which is connected to the first end of the first resistor, the second resistor, and the third resistor.

[0018] Optionally, the first controller, the second controller, and the third controller are all MOS transistors.

[0019] Optionally, the first controller, the second controller, and the third controller are all PMOS transistors, with the first terminal being the source, the second terminal being the drain, and the controller being the gate.

[0020] Optionally, the resistance value of the third resistor is less than the resistance value of the first resistor, which in turn is less than the resistance value of the second resistor.

[0021] Secondly, embodiments of the present invention provide a communication method for an I2C communication circuit, the method being applied to a slave device, the slave device including a GPIO interface, the GPIO interface being connected as described in any of the embodiments of the present invention, the method comprising:

[0022] Detect the voltage of the GPIO interface;

[0023] Data is transmitted with the master device based on the detected voltage.

[0024] Optionally, the step of transmitting data with the master device based on the detected voltage includes:

[0025] In analog mode, when the voltage of the GPIO interface is detected to be a voltage that meets the start condition, it is determined that data needs to be received from the master device;

[0026] Obtain the corresponding bit value based on the detected voltage of the GPIO interface;

[0027] When the voltage of the GPIO interface is detected to be the voltage corresponding to the stop signal, the data transmission is determined to be complete.

[0028] Optionally, when the first controller and the second controller are PMOS transistors, and the resistance value of the third resistor is less than the resistance value of the first resistor, which in turn is less than the resistance value of the second resistor:

[0029] The step of obtaining the corresponding bit value based on the detected voltage signal after data reception begins includes:

[0030] When the voltage detected at the GPIO is V4, the received bit value is 1;

[0031] When the voltage detected at the GPIO is V3, the received bit value is 0;

[0032] When the voltage detected at the GPIO is lower than V3, one bit of data is transmitted.

[0033] V4 > V3.

[0034] Optionally, the I2C communication circuit further includes: a mode adjustment unit, the mode adjustment unit including a third controller, the third controller including a control electrode, a first electrode and a second electrode, the control electrode of the third controller being connected to the GPIO interface of the slave device, the first electrode of the third controller being connected to the SDA interface of the master I2C device, and the second electrode of the third controller being grounded;

[0035] The method further includes: switching the device's GPIO interface to output mode after each set of preset bits of data has been received;

[0036] In output mode, the GPIO interface sends an acknowledgment signal to the SDA interface of the master device through the third controller;

[0037] After the response signal is sent, the slave device's GPIO switches to analog mode and continues to receive data until the stop signal is received.

[0038] Thirdly, embodiments of the present invention provide a network device, including: a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, it implements the steps of the communication method of the I2C communication circuit described in the second aspect above.

[0039] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the communication method of the I2C communication circuit described in the second aspect.

[0040] The beneficial effects of the technical solution provided by the embodiments of the present invention include at least the following: An I2C communication circuit is provided, the circuit comprising: a control unit and a voltage divider unit; the control unit is connected to the SCL interface and SDA interface of the master I2C device respectively; a first end of the voltage divider unit is connected to the GPIO interface of the slave device, and a second end of the voltage divider unit is connected to the control unit; the control unit is used to control the resistance value of the voltage divider unit according to the signals output by the SCL interface and SDA interface of the master I2C device, so as to adjust the voltage signal received by the GPIO interface of the slave device; the above circuit can achieve the technical effect of simulating I2C slave device communication through a single GPIO line. Attached Figure Description

[0041] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:

[0042] Figure 1 This is a schematic diagram of an I2C communication circuit structure provided in an embodiment of the present invention;

[0043] Figure 2 This is a schematic diagram of another I2C communication circuit structure provided in an embodiment of the present invention;

[0044] Figure 3A flowchart of an I2C communication method provided in an embodiment of the present invention;

[0045] Figure 4 A flowchart of another I2C communication method provided in an embodiment of the present invention;

[0046] Figure 5 A schematic diagram of the structure of a network device provided in an embodiment of the present invention;

[0047] Figure 6 This is a schematic diagram illustrating the data transmission level changes of the I2C communication method provided in this embodiment of the invention.

[0048] Figure 7 This is a schematic diagram of an I2C communication circuit and its voltage divider unit structure provided in an embodiment of the present invention.

[0049] Icon description:

[0050] M1 - First controller, M11 - First pole of the first controller, M12 - Second pole of the first controller;

[0051] M2 - First controller, M21 - First pole of the first controller, M22 - Second pole of the first controller;

[0052] M3 - First controller, M31 - First pole of the first controller, M32 - Second pole of the first controller;

[0053] R1 - first resistor, R2 - second resistor, R3 - third resistor, R4 - fourth resistor. The 1 and 2 markings above and below the resistors indicate the first and second terminals of the resistor.

[0054] S1 first input terminal, S2 second input terminal, S3 third input terminal;

[0055] L1 - Master device, L2 - Slave device. Detailed Implementation

[0056] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0057] Please refer to Figure 7 The present invention provides an I2C communication circuit, the circuit including a control unit M and a voltage divider unit R;

[0058] The control unit M is connected to the SCL interface and SDA interface of the main I2C device, respectively.

[0059] The first end of the voltage divider unit R is connected to the GPIO interface of the slave device, and the second end of the voltage divider unit R is connected to the control unit M;

[0060] The control unit M is used to control the resistance value of the voltage divider unit R according to the signals output from the SCL interface and SDA interface of the master I2C device, so as to adjust the voltage signal received from the GPIO interface of the slave device.

[0061] Optional, please refer to Figure 1 , Figure 1 This diagram illustrates an I2C communication circuit structure according to an embodiment of the present invention. The voltage divider unit includes a first resistor R1, a second resistor R2, and a third resistor R3. The control unit includes a first controller M1 and a second controller M2. The first controller M1 includes a control electrode M13, a first electrode M11, and a second electrode M12. The control electrode of the first controller M1 is connected to the SCL interface of the host I2C device. The first electrode M11 of the first controller M1 is connected to the second end of the first resistor R1, and the second electrode M12 of the first controller M1 is connected to the second end of the third resistor R3.

[0062] The second controller M2 includes a control electrode M23, a first electrode M21, and a second electrode M22. The control electrode of the second controller M2 is connected to the SDA interface of the main I2C device. The first electrode M21 of the second controller M2 is connected to the second end of the second resistor R2. The second electrode M22 of the second controller M2 is connected to the second end of the third resistor R3.

[0063] The first end of the first resistor R1, the first end of the second resistor R2, and the first end of the third resistor R3 are connected in parallel and then connected to the GPIO interface of the slave device.

[0064] Optionally, the I2C communication circuit further includes a mode adjustment unit, which includes a third controller:

[0065] The third controller M3 includes a control pole M33, a first pole M31, and a second pole M32. The control pole M33 of the third controller M3 is connected to the GPIO interface of the slave device, the first pole M31 of the third controller is connected to the SDA interface of the master I2C device, and the second pole M32 of the third controller is grounded.

[0066] Optionally, the voltage divider unit R further includes a fourth resistor R4, the first end of which is connected to the first power supply S1, and the second end of which is connected to the first ends of the first resistor R1, the second resistor R2, and the third resistor R3.

[0067] Optionally, the first controller M1, the second controller M2, and the third controller M3 are all MOS transistors.

[0068] Optionally, the first controller M1, the second controller M2, and the third controller M3 are all PMOS transistors, with the first terminal being the source, the second terminal being the drain, and the controller terminal being the gate.

[0069] Optionally, the resistance value of the third resistor is less than the resistance value of the first resistor, which in turn is less than the resistance value of the second resistor.

[0070] For example, refer to Figure 2 The diagram shows the structure of the I2C communication circuit where the first controller M1, the second controller M2, and the third controller M3 are all MOS transistors. R1 is 200K, R2 is 400K, R3 is 600K, R4 is 200K, S1 is 3.6V, S2 is 1.8V, and S3 is 1.8V. The first terminals M11, M21, and M31 of the controllers are all source terminals, and the control terminals M13, M23, and M33 of the controllers are all gate terminals.

[0071] refer to Figure 3 This invention illustrates a communication method for an I2C communication circuit, applicable to a slave device. The slave device includes a GPIO interface, which is connected as described in any embodiment of this invention. The method includes:

[0072] Step 31: Detect the voltage of the GPIO interface;

[0073] Step 32: Data is transmitted with the master device based on the detected voltage.

[0074] Specifically, data transmission can be achieved by measuring the voltage changes at the GPIO interface of the I2C device. Different voltages and voltage changes correspond to different signals and data according to preset parameters.

[0075] Optional, see reference Figure 4 The step of transmitting data with the master device based on the detected voltage includes:

[0076] Step 321: In analog mode, when the voltage of the GPIO interface is detected to be a voltage that meets the start condition, it is determined that data needs to be received from the master device.

[0077] Step 322: Obtain the corresponding bit value based on the detected voltage of the GPIO interface;

[0078] Step 323: When the voltage of the GPIO interface is detected to be the voltage corresponding to the stop signal, the data transmission is determined to be over.

[0079] For example, the starting condition is that when SCL is high, the level of SDA suddenly changes from high to low; causing the voltage detected from the GPIO of the I2C to decrease, such as... Figure 2 For example, the voltage level detected at the GPIO of the I2C changes abruptly from 1.8V to 1.54V.

[0080] For example, the stop signal is when SCL is high, and the level of SDA suddenly changes from low to high. For instance... Figure 2 For example, the voltage level changes abruptly from 1.54V to 1.8V.

[0081] Optionally, when the first controller and the second controller are PMOS transistors, and the resistance value of the third resistor is less than the resistance value of the first resistor, which in turn is less than the resistance value of the second resistor:

[0082] The step of obtaining the corresponding bit value based on the detected voltage signal after data reception begins includes:

[0083] When the voltage detected at the GPIO is V4, the received bit value is 1;

[0084] When the voltage detected at the GPIO is V3, the received bit value is 0;

[0085] When the voltage detected at the GPIO is lower than V3, one bit of data is transmitted.

[0086] V4 > V3.

[0087] Specifically, by maintaining a specific relationship between R1, R2, and R3, the parallel connection relationship between R1, R2, R3, and R4 can be different under different state combinations of the first and second controllers, thereby resulting in different voltages detected from the GPIO of the device. By presetting different rules for different voltage states, it can be used to simulate I2C communication, such as voltage change 1 - corresponding to the start of communication, voltage change 2 - bit value 1, voltage change 3 - bit value 0, voltage change 4 - communication ends, etc. Specifically, when the voltage detected at the GPIO is lower than V3, one bit of data is transmitted. If, during voltage detection, the control unit controls the device's GPIO interface to detect other voltage signals lower than V3 besides V4 and V3, such as V2 and V1, where V4 > V3 > V2 > V1, an interval voltage signal lower than V3 (such as V1 or V2) can be detected after each bit of data is transmitted. When the voltage signal received from the device's GPIO interface changes directly between V3 and V4 without any interval voltage signal, it indicates that a start signal or stop signal has been received.

[0088] Optionally, the I2C communication circuit further includes: a mode adjustment unit, the mode adjustment unit including a third controller, the third controller including a control electrode, a first electrode and a second electrode, the control electrode of the third controller being connected to the GPIO interface of the slave device, the first electrode of the third controller being connected to the SDA interface of the master I2C device, and the second electrode of the third controller being grounded;

[0089] The method further includes:

[0090] After receiving a preset number of bits of data in a row, the device will switch to output mode via its GPIO interface.

[0091] In output mode, the GPIO interface sends an acknowledgment signal to the SDA interface of the master device through the third controller;

[0092] After the response signal is sent, the slave device's GPIO switches to analog mode and continues to receive data until the stop signal is received.

[0093] Specifically, by presetting different scenarios, the specific data transmission rules for GPIO-simulated I2C communication can be adjusted, such as transmission rate, bit value, start signal, stop signal, ACK acknowledgement signal, etc.

[0094] Specifically, depending on the parameters supported by different I2C master devices, the number of bits can be preset, such as preset to switch the device's GPIO interface to output mode after receiving eight consecutive bits of data; or it can be 4, 16, or 32 bits of data.

[0095] When the slave device finishes receiving a preset number of bits of data, it switches its GPIO interface to output mode. The slave device sends an acknowledgment signal, which makes it easier for the master device to monitor the data reception status of the slave device. When an abnormal data reception occurs, it can be detected in time and retransmitted.

[0096] For details, please refer to Figure 2 The diagram illustrates an I2C communication circuit structure, further illustrating the I2C communication circuit and communication method provided in this embodiment of the invention:

[0097] Figure 2 The diagram shows the structure of the I2C communication circuit where the first controller M1, the second controller M2, and the third controller M3 are all MOS transistors. R1 is 200K, R2 is 400K, R3 is 600K, R4 is 200K, S1 is 3.6V, S2 is 1.8V, and S3 is 1.8V. The first terminals M11, M21, and M31 of the controllers are all source terminals, and the control terminals M13, M23, and M33 of the controllers are all gate terminals.

[0098] Specifically, let's take a transmission rate of 100K as an example. One clock cycle is 10µs, and half a cycle is 5µs. The sampling rate of the I2C device's digital-to-analog converter (ADC) is 2MSPS, which means sampling once every 500ns, or once every µs. At least 5 samples can be taken every half cycle. Regardless of high or low levels, ideally, once SCL and SDA determine the high and low levels, the data sampled at the analog GPIO should remain unchanged. Considering errors, if 4 out of 5 samples have the same value, it can be considered valid. Of course, during sampling, error factors are taken into account; for example, the determination of 1.8V is between 1.78-1.82V, meaning that anything within this range is considered 1.8V. This double guarantee ensures the reliability of data transmission.

[0099] Specifically, Figure 2 The voltage signals output by SCL and SDA of the main device L1 have only four combinations: high-high V4, high-low V3, low-high V2, and low-low V1.

[0100] When the SCL output of the master I2C device L1 is low and the SDA output is high, the first controller M1 is turned on and the second controller M2 is turned off. At this time, R1 and R3 are connected in parallel. R1 = 200K and R3 = 400K are connected in parallel, which equals 133K. At this time, the voltage at the GPIO of the I2C device L2 is 3.6V*(133 / (133+200)) = 1.44V (1.42V-1.46V), and V2 = 1.44V.

[0101] When the SCL and SDA outputs of the master I2C device L1 are low, the first controller M1 and the second controller M2 are turned on. At this time, R1, R2, and R3 are connected in parallel. R1 = 200K, R2 = 400K, and R3 = 600K, which together equal 109K. At this time, the voltage at the GPIO of the I2C device L2 is 3.6V * (109 / (109 + 200)) = 1.27V (1.25V - 1.29V), and V1 = 1.27V.

[0102] When the SCL and SDA outputs of the master I2C device L1 are high, both the first controller M1 and the first controller M2 are off. At this time, R3 = 200K and there is no parallel connection. The voltage at the GPIO of the I2C device L2 is 3.6V*(200 / (200+200)) = 1.8V (1.78V-1.82V), and V1 = 1.8V.

[0103] When the SCL output of the master I2C device L1 is high and the SDA output is low, the first controller M1 is off and the first controller M2 is on. At this time, R2 and R3 are connected in parallel, with R3 = 200K and R2 = 600K in parallel, which equals 150K. The voltage at the GPIO of the I2C device L2 is 3.6V * (150 / (150 + 200)) = 1.54V (1.52V - 1.56V), and V2 = 1.8V.

[0104] As can be seen above, the ADC of the I2C device can acquire the voltage levels in the four scenarios described above. Before data transmission, both SCL and SDA of the master I2C device output high levels, and the voltage acquired from the GPIO of the I2C device is 1.8V. It is worth noting that in this embodiment, the GPIO interface of the I2C device can be multiplexed as an ADC, thereby enabling analog communication of I2C signals through a single GPIO line.

[0105] When the start condition is generated, the master I2C device outputs a high level on SCL, and the output on SDA suddenly changes from high to low. At this time, the voltage level detected at the GPIO interface of the I2C device suddenly changes from 1.8V to 1.54V.

[0106] After the initial conditions are met, the SCL output of the master I2C device will change from high to low. Based on the four scenarios above, regardless of the change in the SDA output level of the master I2C device, the level detected at the GPIO interface of the I2C device will never exceed 1.54V (it will only be 1.27V or 1.44V), so this can be ignored. Only the level detected at the GPIO interface of the I2C device when the SCL output of the master I2C device is high needs to be considered. When a level of 1.8V is detected at the GPIO interface of the I2C device, it indicates that both the SCL and SDA outputs of the master I2C device are high, and the first bit received is 1. When a level of 1.54V is detected at the GPIO interface of the I2C device, it indicates that the SCL output of the master I2C device is high, the SDA output is low, and the first bit received is 0.

[0107] When the voltage level detected at the GPIO interface of the I2C device drops below 1.54V, it indicates that the first bit has been successfully received. Subsequent bit receptions follow the same logic.

[0108] When the preset number of bits has been received, such as 8 bits, the GPIO of the I2C device quickly switches to output mode and outputs a low level.

[0109] When the GPIO of the slave I2C device outputs a low level, the third controller M3 is turned on, outputting a level to the SDA terminal of the master I2C device as a reception data response signal. After the ACK response is completed, the GPIO of the slave I2C device quickly switches to an analog mode. When it is detected at the GPIO interface of the slave I2C device that the level switches from 1.54V to 1.8V, it indicates that a stop signal sent by the master I2C device is received, and the data transmission is completed.

[0110] Specifically, during data transmission, the level signals detected at the GPIO include several cases of 1.27V, 1.44V, 1.54V and 1.8V, with reference to Figure 6 which shows a schematic diagram of level changes during data transmission. The SCL interface of the master device can output a high level or a low level, and the SDA interface of the master device can output a high level or a low level, Figure 6 the data transmitted in is 10001100, Figure 6 the level situation in is:

[0111] SCL-SDA: high-high = 1.8V, high-low = 1.54V, low-high = 1.44V, low-low = 1.27V.

[0112] The level changes throughout the process are as follows:

[0113] (1.8V to 1.54V)→(1.27V to 1.44V)→1.8V→(1.44V to 1.27V)→1.54V→1.27V→1.54V→1.27V→1.54V→(1.27V to 1.44V)→1.8V→1.44V→1.8V→(1.44V to 1.27V)→1.54V→1.27V→1.54V→1.27V→(1.54V to 1.8V);

[0114] For ease of description, the level signal changes and reception are referenced in Table 1:

[0115] Table 1: Level Signal Changes and Reception

[0116] signal changes take over (1.8V to 1.54V) → (1.27V to 1.44V) → Start signal 1.8V → (1.44V to 1.27V) → 1 1.54V→1.27V→ 0 1.54V→1.27V→ 0 1.54V → (1.27V to 1.44V) → 0 1.8V→1.44V→ 1 1.8V → (1.44V to 1.27V) → 1 1.54V→1.27V→ 0 1.54V→1.27V→ 0 (1.54V to 1.8V) Stop signal

[0117] Wherein the level changes marked by "→" above vary with the changes of SCL clock edges (rising edge and falling edge). The level changes marked by "to" above are changes caused by the SDA level changing while the SCL level remains unchanged.

[0118] The (1.8V to 1.54V) change is the start level, and the (1.54V to 1.8V) change is the stop signal.

[0119] In the I2C protocol, data is only sampled at the moment when SCL is at a high level, for the data on SDA; according to this rule, Figure 6The data collected from the level change graph is: starting level 1000 1100 stop signal.

[0120] Except for the start and stop bits, there were no instances of a 1.8V to 1.54V or a 1.54V to 1.8V mutation.

[0121] Therefore, when the GPIO interface detects a sudden change in voltage from 1.54V to 1.8V, it indicates that a stop signal has been received from the master I2C device, and data transmission is complete.

[0122] Similarly, before data transmission begins, when the GPIO interface detects a sudden change in voltage from 1.8V to 1.54V, it indicates that a start signal has been received, and data reception begins from the next voltage signal. When the communication mode is switched to master-read-slave-write mode, after the master I2C device sends the start signal and address data, the slave I2C device sends back an ACK acknowledgement signal and then begins sending data. The communication rate can be determined based on the previous interactions, such as 100Kbps or 400Kbps, or other rates. For example, after sending the ACK acknowledgement, there might be a 2.5µs delay before sending the required data. If a 1 needs to be sent, a high level is sent back to the I2C device; if a 0 needs to be sent, a low level is sent back. After sending 8 bits, the system switches to analog ADC mode, and the slave I2C device waits to receive an ACK level of 1.54V (SCL high, SDA low). This process continues until a communication stop signal is received from the master device.

[0123] Specifically, the I2C slave device involved in the I2C communication circuit provided in this application embodiment has an ADC interface and a GPIO interface. The GPIO interface is a GPIO interface multiplexed with an ADC, enabling the I2C circuit to switch between two modes. Specifically, reading is performed in analog GPIO mode. In this solution, the analog mode of GPIO refers to ADC mode, where GPIO can be multiplexed as an ADC, and ADC is an analog quantity. Writing and sending signals are performed in output mode.

[0124] In summary, the communication method of the I2C communication circuit provided in this embodiment of the invention allows the I2C device to receive data from the master I2C device and send data to the master I2C device, thereby achieving the purpose of simulating GPIO and communicating with the standard I2C bus through a single GPIO line.

[0125] Please refer to Figure 4The present invention also provides a network device 40, including a processor 41, a memory 42, and a computer program stored in the memory 42 and executable on the processor 41. When the computer program is executed by the processor 41, it implements the various processes of the communication method embodiment of the I2C communication circuit described above and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0126] This invention also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the various processes of the communication method embodiments of the I2C communication circuit described above, achieving the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0127] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0128] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0129] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.

Claims

1. An I2C communication circuit, characterized in that, include: Control unit and voltage divider unit; The control unit is connected to the SCL interface and SDA interface of the main I2C device, respectively. The first end of the voltage divider unit is connected to the GPIO interface of the slave device, and the second end of the voltage divider unit is connected to the control unit; The control unit is used to control the resistance value of the voltage divider unit according to the signals output from the SCL interface and SDA interface of the master I2C device, so as to adjust the voltage signal received from the GPIO interface of the slave device; The voltage divider unit includes: a first resistor, a second resistor, and a third resistor; the control unit includes a first controller and a second controller; The first controller includes a control electrode, a first electrode, and a second electrode. The control electrode of the first controller is connected to the SCL interface of the main I2C device. The first electrode of the first controller is connected to the second end of the first resistor. The second electrode of the first controller is connected to the second end of the third resistor. The second controller includes a control electrode, a first electrode, and a second electrode. The control electrode of the second controller is connected to the SDA interface of the main I2C device. The first electrode of the second controller is connected to the second end of the second resistor. The second electrode of the second controller is connected to the second end of the third resistor. The first end of the first resistor, the first end of the second resistor, and the first end of the third resistor are connected in parallel and then connected to the GPIO interface of the slave device.

2. The I2C communication circuit according to claim 1, characterized in that, The I2C communication circuit further includes a mode adjustment unit, which includes a third controller: The third controller includes a control electrode, a first electrode, and a second electrode. The control electrode of the third controller is connected to the GPIO interface of the slave device, the first electrode of the third controller is connected to the SDA interface of the master I2C device, and the second electrode of the third controller is grounded.

3. The I2C communication circuit according to claim 1, characterized in that, The voltage divider unit further includes a fourth resistor, the first end of which is connected to the first power supply, and the second end of which is connected to the first, second, and third resistors.

4. The I2C communication circuit according to claim 2, characterized in that, The first controller, the second controller, and the third controller are all MOS transistors.

5. The I2C communication circuit according to claim 4, characterized in that, The first controller, the second controller, and the third controller are all PMOS transistors, with the first terminal being the source, the second terminal being the drain, and the controller being the gate.

6. The I2C communication circuit according to claim 1, characterized in that, The resistance value of the third resistor is less than the resistance value of the first resistor, which in turn is less than the resistance value of the second resistor.

7. A communication method for an I2C communication circuit, characterized in that, The method is applied to a slave device, the slave device including a GPIO interface, the GPIO interface being circuit-connected as described in any one of claims 1 to 6, the method comprising: Detect the voltage of the GPIO interface; Data is transmitted with the master I2C device based on the detected voltage.

8. The communication method of the I2C communication circuit according to claim 7, characterized in that, The data transmission with the main I2C device based on the detected voltage includes: In analog mode, when the voltage of the GPIO interface is detected to be a voltage that meets the start condition, it is determined that data needs to be received from the main I2C device. Obtain the corresponding bit value based on the detected voltage of the GPIO interface; When the voltage of the GPIO interface is detected to be the voltage corresponding to the stop signal, the data transmission is determined to be complete.

9. The communication method of the I2C communication circuit according to claim 8, characterized in that, When the first controller and the second controller are PMOS transistors, and the resistance value of the third resistor is less than the resistance value of the first resistor, which in turn is less than the resistance value of the second resistor: Once data reception begins, the corresponding bit values ​​are obtained based on the detected voltage signal, including: When the voltage detected at the GPIO is V4, the received bit value is 1; When the voltage detected at the GPIO is V3, the received bit value is 0; When the voltage detected at the GPIO is lower than V3, one bit of data is transmitted. V4 > V3.

10. The communication method of the I2C communication circuit according to claim 8, characterized in that, The I2C communication circuit further includes: a mode adjustment unit, the mode adjustment unit including a third controller, the third controller including a control electrode, a first electrode and a second electrode, the control electrode of the third controller being connected to the GPIO interface of the slave device, the first electrode of the third controller being connected to the SDA interface of the master I2C device, and the second electrode of the third controller being grounded; The method further includes: After receiving a preset number of bits of data in a row, the device will switch to output mode via its GPIO interface. In output mode, the GPIO interface sends an acknowledgment signal to the SDA interface of the main I2C device through the third controller; After the response signal is sent, the slave device's GPIO switches to analog mode and continues to receive data until the stop signal is received.

11. A network device, characterized in that, include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the communication method of the I2C communication circuit as described in any one of claims 7 to 10.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the communication method of the I2C communication circuit as described in any one of claims 7 to 10.

Citation Information

Patent Citations

  • Circuit and method for achieving GPIO function on serial peripheral interface device

    CN107480090A

  • Method and system for single-line inter-integrated circuit (I2C) bus

    US20140310436A1