A master-slave communication method based on IIC communication protocol

By setting the master-slave communication line to OD gate mode and using software to control signal synchronization, the problem of low communication efficiency between the master and slave was solved, enabling direct access to the IIC slave chip and real-time data acquisition, thus improving communication efficiency.

CN116204483BActive Publication Date: 2026-11-20PINGHU KEPU LASER TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310257521.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-13
Publication Date
2026-11-20
Estimated Expiration
2043-03-13

AI Technical Summary

Technical Problem

In existing technologies, communication between the master and slave devices is inefficient, data cannot be acquired in real time, and methods such as disassembling the casing and using jumper wires or data forwarding can easily damage the product or prevent direct access to the GUI of the IIC slave chip.

Method used

By setting the data and clock lines of the master and slave devices to OD gate mode and connecting them to a high level when not in operation, master-slave communication is achieved through software control signal synchronization.

Benefits of technology

It improves signal transmission efficiency, avoids product damage, and enables direct access to IIC slave chips and real-time data acquisition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116204483B_ABST
    Figure CN116204483B_ABST
Patent Text Reader

Abstract

The application discloses a master-slave communication method based on IIC communication protocol, which comprises the following steps: in the initial state, setting the host data line SDA, the host clock line SCL, the slave data line sda and the slave clock line scl as the OD door mode; in the non-working state, the host data line SDA, the host clock line SCL, the slave data line sda and the slave clock line scl are all in the high level state; and the data lines and the clock lines of the host and the slave are connected with the VCC end through the pull-up resistor respectively. The application directly accesses the internal IIC slave chip through the product external interface, which is similar to the flying wire method, and the signal transmission efficiency is improved through the communication mode. The IIC bus has only two signal lines in total, one is the bidirectional serial data line SDA, and the other is the serial clock line SCL. The SDA and the SCL are bidirectional, the data lines of all devices on the IIC bus are connected to the SDA line, and the clock lines of all devices on the IIC bus are connected to the SCL line.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communications, and more particularly to a master-slave communication method based on the IIC communication protocol. Background Technology

[0002] With the development of the times, the deepening of informatization, and the popularization of Internet of Things (IoT) technology, master-slave communication is increasingly being used in various industries, such as industrial control, medical care, and electronics. Master-slave communication typically involves one master (monitoring equipment) and multiple slaves (monitored devices). Information sent by the master can be transmitted to multiple slaves or a designated slave, while information sent by the slaves can only be transmitted to the master. Slave devices cannot communicate directly with each other.

[0003] In most cases, communication between the master and slave devices involves the IIC slave chip being housed within a casing. The only external interface is typically a few pins of the MCU. When accessing the IIC slave chip, there are generally two methods: one is by removing the casing and using jumper wires; the other is by using the MCU for data forwarding. The disadvantage of removing the casing and using jumper wires is that it can easily cause irreversible damage to the product and is time-consuming and laborious. The disadvantage of data forwarding is that it cannot obtain current data in real time and cannot directly access the chip using the IIC slave chip's built-in GUI. This leads to a decrease in communication efficiency between the master and slave devices. Summary of the Invention

[0004] The purpose of this invention is to provide a master-slave communication method based on the IIC communication protocol. This method allows direct access to the internal IIC slave chip via an external interface, employing an approximate flying wire method to improve signal transmission efficiency by changing the communication mode. The IIC bus has only two signal lines: a bidirectional serial data line (SDA) and a serial clock line (SCL). Both SDA and SCL are bidirectional. The data lines of each device on the IIC bus are connected to the SDA line, and the clock lines of each device on the IIC bus are connected to the SCL line.

[0005] To achieve the above objectives, the present invention is implemented through the following technical means.

[0006] A master-slave communication method based on the IIC communication protocol includes, In the initial state, the master data line SDA, the master clock line SCL, and the slave data line sda ​​and the slave clock line scl are set to OD gate mode; Furthermore, in the non-working state, the aforementioned host data line SDA, host clock line SCL, and slave data line sda ​​and slave clock line scl are all in a high-level state; Furthermore, the data lines and clock lines of both the master and slave devices are connected to the high-level VCC terminal via pull-up resistors.

[0007] In a preferred embodiment of the present invention, in OD gate mode, when the signal is high, the master or slave device is in an input state; in OD gate mode, when the signal is low, the master or slave device is in an output state.

[0008] In a preferred embodiment of the present invention, in the working state, the clock signal is initiated by the host, and the data signal is initiated by the host or slave respectively.

[0009] In a preferred embodiment of the present invention, when the host clock line SCL is high, there are only two data changes: START signal and STOP signal. In these two cases, the data is controlled by the host, and the host signal is synchronized to the slave signal.

[0010] In a preferred embodiment of the present invention, when the host terminal SCL is high, the scl terminal is set to high, and the level signal collected by the SDA terminal is continuously synchronized to the sda ​​terminal.

[0011] In a preferred embodiment of the present invention, when the host clock line SCL is low, SDA and sda need to be set high first. Then, the SDA and sda input signals are read. If terminal A is low, the data line signal is synchronized to terminal B. During the period when SCL is low, the signal at terminal A may invert; therefore, the signal at terminal A needs to be continuously monitored. If it goes high, it needs to be synchronized high to terminal B. (Terminal A can be SDA or sda, and terminal B represents the opposite end of terminal A.) Specifically, when reading the host clock line SCL as low, the host data line SDA and the slave data line sda ​​need to be set high first. At this time, three situations may occur: The first method is to read the input signals of the host data line SDA and the slave data line sda ​​at this time. If the input of the host data line SDA is low and the input of the slave data line sda ​​is high, then set the slave data line sda ​​to output low and continuously monitor the input signal of the host data line SDA. If it becomes high, then it is necessary to set the slave data line sda ​​to output high. The second method is to read the SDA and sda input signals at this time. If the sda ​​input is low and the SDA input is high, then set SDA to output low and continuously monitor the sda ​​input signal. If it becomes high, then SDA needs to be set to output high. The third option is to read the SDA and sda input signals at this time. If the SDA input is low and the sda ​​input is high, no operation is performed.

[0012] In a preferred embodiment of the present invention, the voltage at the VCC terminal can be any voltage, determined according to the actual working environment; preferably, the voltage at the VCC terminal is 3.3V. Attached Figure Description

[0013] Figure 1 This refers to the actual wiring method used in operation; Figure 2 This invention is for the purpose of obtaining the invention. Figure 1 Equivalent result diagram; Figure 3 This is a flowchart of the process of the present invention. Detailed Implementation

[0014] The present invention will now be described in detail with reference to the embodiments shown in the accompanying drawings. However, it should be noted that these embodiments are not intended to limit the present invention. Equivalent changes or substitutions in function, method, or structure made by those skilled in the art based on these embodiments are all within the scope of protection of the present invention.

[0015] Reference Figure 1 , Figure 2 As shown, the internal IIC slave chip is accessed directly through the product's external interface, using an approximate flying wire method, and the code... Figure 2 Equivalent to Figure 1 , specifically: Reference Figure 3 As shown, a master-slave communication method based on the IIC communication protocol includes, In the initial state, the host data line SDA, the host clock line SCL, and the slave data line sda ​​and the slave clock line scl are set to OD gate mode; Furthermore, in the non-working state, the aforementioned host data line SDA, host clock line SCL, and slave data line sda ​​and slave clock line scl are all in a high-level state; Furthermore, the data lines and clock lines of both the master and slave devices are connected to the high-level VCC terminal via pull-up resistors.

[0016] Make full use of the software settings to achieve data transmission and communication between the master and slave machines.

[0017] Specifically: ①According to the IIC protocol, the clock and data are in open-drain output mode and are high when not in communication mode. Therefore, it is necessary to set both the master and slave ends to high during initialization.

[0018] ②According to the IIC protocol, when the clock is high, there are only two possible data changes (START signal and STOP signal). In both cases, the data must be controlled by the master. Therefore, it is only necessary to synchronize the master signal to the slave.

[0019] ③ According to the IIC protocol, when the clock is low, data may be controlled by either the master or the slave. Therefore, when the clock enters a low level, First, set both ends to high. Then, read the input status at both ends. The end with a low input indicates which end is currently controlling the data. Then, synchronize the data at the other end to low. Since the master-slave data switch occurs when the clock is low, the data line level may change multiple times when the clock is low. Next, simply loop to check the relationship between the set value and the input value. When one side's set value is high and the read value is low, it can be determined that the data is controlled by that direction. At this time, synchronize to the other end. If neither side has this situation, it means that both sides of the data line are high at this time, and the program updates both sides to high.

[0020] Specifically, first set SDA and sda high. Then read the SDA and sda input signals. If terminal A is low, synchronize the data line signal to terminal B. While SCL is low, the signal at terminal A may invert. In this case, it is necessary to continuously monitor the signal at terminal A. If it goes high, it needs to be synchronized high to terminal B again. (Terminal A can be either SDA or sda, and terminal B represents the opposite end of terminal A.) Specifically, when reading the host clock line SCL as low, the host data line SDA and the slave data line sda ​​need to be set high first. At this time, three situations may occur: The first method is to read the input signals of the host data line SDA and the slave data line sda ​​at this time. If the input of the host data line SDA is low and the input of the slave data line sda ​​is high, then set the slave data line sda ​​to output low and continuously monitor the input signal of the host data line SDA. If it becomes high, then it is necessary to set the slave data line sda ​​to output high. The second method is to read the SDA and sda input signals at this time. If the sda ​​input is low and the SDA input is high, then set SDA to output low and continuously monitor the sda ​​input signal. If it becomes high, then SDA needs to be set to output high. The third option is to read the SDA and sda input signals at this time. If the SDA input is low and the sda ​​input is high, no operation is performed.

[0021] Notes: 1. In open-drain output mode, a high level is equivalent to the input state, also known as releasing the bus, and a low level is equivalent to directly grounding, also known as pulling the bus low.

[0022] 2. Controlled by a certain end, indicating that a certain end pulls the bus low.

[0023] The detailed descriptions listed above are merely specific descriptions of feasible embodiments of the present invention, and are not intended to limit the scope of protection of the present invention. All equivalent embodiments or modifications made without departing from the spirit of the present invention should be included within the scope of protection of the present invention.

[0024] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

[0025] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.

Claims

1. A master-slave communication method based on the IIC communication protocol, wherein the communication method directly accesses the internal IIC slave chip through the product's external interface, without requiring disassembly, wiring, or MCU data forwarding; characterized in that, include, In the initial state, the master data line SDA, the master clock line SCL, and the slave data line sda ​​and the slave clock line scl are set to OD gate mode; Furthermore, in the non-working state, the aforementioned host data line SDA, host clock line SCL, and slave data line sda ​​and slave clock line scl are all in a high-level state; Furthermore, the data lines and clock lines of both the master and slave devices are connected to the VCC terminal via pull-up resistors. By using software settings, data transmission and communication between the master and slave machines are achieved; specifically: ①According to the IIC protocol, the clock and data are in open-drain output mode and are high when not in communication mode. Therefore, both the master and slave ends are set to high during initialization. ②According to the IIC protocol, when the clock is high, there are only two data changes: START signal and STOP signal. In these two cases, the data is controlled by the master, so it is only necessary to synchronize the master signal to the slave. ③ According to the IIC protocol, when the clock is low, data may be controlled by either the master or the slave. Therefore, when the clock enters a low level, First, set both ends to high. Then, read the input status at both ends. The end with a low input indicates which end is currently controlling the data. Then, synchronize the data at the other end to low. Since the master-slave data switch occurs when the clock is low, the data line level may change multiple times when the clock is low. Next, simply loop to check the direct relationship between the set value and the input value. When one side's set value is high and the read value is low, it can be determined that the data is controlled by that side. At this time, synchronize to the other end. If neither side has this situation, it means that both sides of the data line are high at this time, and the program updates both sides to high. Specifically, first set SDA and sda high. Then read the SDA and sda input signals. If the SDA input of the master data line is low and the sda ​​input of the slave data line is high, then set the sda ​​output of the slave data line to low and continuously monitor the SDA input signal of the master data line. If it goes high, then the sda ​​output of the slave data line needs to be set to high. If the input at the sda ​​terminal is low and the input at the SDA terminal is high, then SDA is set to output low, and the input signal at the sda ​​terminal is continuously monitored. If it goes high, then SDA needs to be set to output high.

2. The master-slave communication method based on the IIC communication protocol according to claim 1, characterized in that, In operation, clock signals are initiated by the master unit, while data signals are initiated by either the master or slave unit.

3. The master-slave communication method based on the IIC communication protocol according to claim 1, characterized in that, The voltage at the VCC terminal is 3.3V.

Citation Information

Patent Citations

  • Software simulation rapid communication protocol

    CN102929830A

  • Bus device and data read-write circuit

    CN114253898A

  • Interface circuit for AD conversion

    CN215956370U