Master-slave device write operation communication method and communication system
By using shared addresses and identifier sets in I2C communication, the problem of wasted address resources from multiple slave devices is solved, efficient write data block processing is achieved, and system performance and communication efficiency are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-11
- Publication Date
- 2026-03-06
AI Technical Summary
In the I2C communication protocol, the address resources of multiple slave devices are consumed in a large way, and the traditional method requires multiple independent transactions to write data, which increases communication overhead and reduces system efficiency.
The master device sends a shared address and an identifier set. The target slave device identifies and writes data according to the identifier set in sequence. Multiple slave devices share the same address and are distinguished by the identifier, which avoids address waste and enables block processing of write data.
It increases the upper limit of the number of slave devices, reduces bus usage and latency, improves communication efficiency, and does not require additional hardware complexity and power consumption.
Smart Images

Figure CN121614431A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communications, and more specifically, to a master-slave device write operation communication method and communication system. Background Technology
[0002] The I2C (Inter-Integrated Circuit) protocol is a bus protocol that uses the I2C bus to communicate between master and slave devices. The I2C bus includes a serial clock line (SCL) and a serial data line (SDA). The I2C protocol is widely used in the embedded field due to its simple operation and low pin resource consumption.
[0003] In the I2C communication protocol, when a master device communicates with multiple slave devices, it typically needs to assign a unique address to each slave device. This leads to high address resource consumption, especially when there are many slave devices and the address space is limited. Furthermore, in traditional methods, if data needs to be written to multiple slave devices, the master device often needs to initiate multiple independent I2C transactions (each transaction targeting one slave device), which increases communication overhead, consumes bus bandwidth, and reduces system efficiency. Summary of the Invention
[0004] The purpose of this invention is to provide a master-slave device write operation communication method and system to improve the above-mentioned problems.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows: In a first aspect, embodiments of the present invention provide a master-slave device write operation communication method, applied to a master device, wherein the master device is connected to multiple slave devices via an I2C bus, the method comprising: After sending the start bit, the master device sends the shared address corresponding to the current write operation, so that the slave device on the I2C bus can confirm that it is the matching slave device corresponding to the shared address when its own address is the same as the shared address; The master device sequentially sends a write operation command, an identifier set, a write address, and write data. The identifier set includes at least one identifier of the participating slave device; So that the target slave device identifies its corresponding target data from the written data according to the identifier arrangement order in the identifier set and the target data length of each target slave device, and completes the writing of the target data based on its corresponding write address, wherein the target slave device is the matching slave device whose identifier belongs to the identifier set.
[0006] Secondly, embodiments of the present invention provide a master-slave device write operation communication method, applied to a slave device, wherein the slave device is connected to the master device via an I2C bus, and the method includes: When the slave device receives the start bit sent by the master device, it enters a listening and parsing state. When the slave device confirms that the shared address it is listening to is the same as its own address, it confirms that it is the matching slave device corresponding to the shared address; The matching slave device listens to the write operation commands and identifier sets sent by the master device. If its own identifier belongs to the identifier set, it confirms that it is the target slave device corresponding to the write operation command. The identifier set includes at least one identifier of the participating slave device; The target slave device continues to listen to the write address and write data sent by the master device. According to the identifier arrangement order in the identifier set and the target data length of each target slave device, it identifies the corresponding target data from the write data and completes the writing of the target data based on its corresponding write address.
[0007] Thirdly, embodiments of the present invention provide a master-slave device write operation communication method, applied to a communication system, the communication system including a master device and multiple slave devices, the master device being connected to the multiple slave devices via an I2C bus, the method comprising: When the master device needs to write data to the slave device, it sends a start bit; When the slave device receives the start bit sent by the master device, it enters a listening and parsing state. The master device sends the shared address corresponding to the current write operation; When the slave device confirms that the shared address it is listening to is the same as its own address, it confirms that it is the matching slave device corresponding to the shared address; The master device sequentially sends a write operation command and an identifier set, wherein the identifier set includes at least one identifier of a participating slave device; The matching slave device listens to the write operation commands and identifier sets sent by the master device. If its own identifier belongs to the identifier set, it confirms that it is the target slave device corresponding to the write operation command. The master device sequentially sends the write address and write data; The target slave device continues to listen to the write address and write data sent by the master device. According to the identifier arrangement order in the identifier set and the target data length of each target slave device, it identifies the corresponding target data from the write data and completes the writing of the target data based on its corresponding write address.
[0008] Fourthly, embodiments of the present invention provide a master-slave device communication system, the communication system including a master device and multiple slave devices, the master device being connected to the multiple slave devices via an I2C bus; The master device is used to send a start bit when it needs to write data to the slave device; The slave device is used to enter a listening and parsing state when it receives the start bit sent by the master device; The master device is used to send the shared address corresponding to the current write operation; The slave device is used to confirm that it is the matching slave device corresponding to the shared address when it confirms that the shared address it has been listening to is the same as its own address; The master device is used to send write operation commands and an identifier set in sequence, wherein the identifier set includes at least one identifier of a participating slave device; The matching slave device is used to listen to the write operation commands and identifier sets sent by the master device. If its own identifier belongs to the identifier set, it confirms that it is the target slave device corresponding to the write operation command. The master device is used to send the write address and write data sequentially; The target slave device is used to continue listening to the write address and write data sent by the master device, and to identify the target data corresponding to each target slave device from the write data according to the identifier arrangement order in the identifier set and the target data length of each target slave device, and to complete the writing of the target data based on its corresponding write address.
[0009] Compared to existing technologies, the present invention provides a master-slave device write operation communication method and system. The master device sends the shared address corresponding to the current write operation to enable slave devices on the I2C bus to confirm whether they are matching slave devices. The master device sequentially sends a write operation command, an identifier set, a write address, and write data. This allows the target slave device to identify its corresponding target data from the write data according to the identifier order in the identifier set and the target data length of each target slave device. The target slave device then completes the write of the target data based on its corresponding write address. The target slave device is a matching slave device whose identifier belongs to the identifier set. Multiple slave devices can share a single address, distinguished by identifiers, avoiding address resource waste and increasing the maximum number of deployable slave devices. Furthermore, within a single I2C transaction, write data can be processed in blocks based on the identifier order in the identifier set and the target data length of each target slave device, reducing bus occupancy and latency, and improving communication efficiency. The order and combination of slave devices can be dynamically specified without requiring additional mechanisms such as mapping tables, avoiding increased hardware complexity and power consumption for slave devices.
[0010] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0011] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a schematic diagram of the architecture of a master-slave device communication system provided in an embodiment of the present invention.
[0013] Figure 2 This is one of the flowcharts illustrating the master-slave device write operation communication method provided in an embodiment of the present invention.
[0014] Figure 3 This is the second flowchart illustrating the master-slave device write operation communication method provided in an embodiment of the present invention.
[0015] Figure 4 This is the third flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention.
[0016] Figure 5 This is the fourth flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention.
[0017] Figure 6 The fifth flowchart illustrates the master-slave device write operation communication method provided in this embodiment of the invention.
[0018] Figure 7 This is the sixth flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention.
[0019] Figure 8 This is the seventh flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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 embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0021] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0022] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0023] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0024] This invention provides a master-slave device communication system. Please refer to [link / reference]. Figure 1 , Figure 1 This is a schematic diagram of the architecture of a master-slave device communication system provided in an embodiment of the present invention. The communication system includes a master device and multiple slave devices, with the master device connected to the multiple slave devices via an I2C bus. During the pre-configuration phase, addresses and identifiers are assigned to each slave device in the communication system. It should be noted that this communication system allows multiple slave devices to share a single address, and each slave device is assigned a unique identifier, which can be, but is not limited to, an identity document (ID).
[0025] The master device has a first processing unit for handling I2C transactions, including writing data to and reading data from the slave device via the I2C bus. The slave device has a storage unit, a second processing unit, and registers. The storage unit can store the slave device's identifier and cache relevant data within I2C transactions, including write addresses, read addresses, the target data length for writing, and the target data length for reading. Registers can be used to store data, such as operating data or control commands from a motor controller in a camera. The second processing unit handles I2C transactions, including receiving data written by the master device via the I2C bus and sending feedback to the master device via the I2C bus regarding data it needs to read.
[0026] The master device is used to send a start bit when it needs to write data to the slave device.
[0027] The slave device is used to enter the listening and parsing state when it receives the start bit sent by the master device.
[0028] The master device is used to send the shared address corresponding to the current write operation.
[0029] The slave device is used to confirm that the shared address it is listening to is the matching slave device corresponding to the shared address when it confirms that the shared address is the same as its own address.
[0030] The master device is used to send write operation commands and an identifier set in sequence, wherein the identifier set includes at least one identifier of the participating slave device.
[0031] The matching slave device listens for write operation commands and identifier sets sent by the master device. If its own identifier belongs to the identifier set, it confirms that it is the target slave device corresponding to the write operation command.
[0032] The master device is used to send the write address and write data sequentially.
[0033] The target slave device continues to listen to the write address and write data sent by the master device. According to the sorting order of the identifiers in the identifier set and the target data length of each target slave device, it identifies the corresponding target data from the write data and completes the write of the target data based on the corresponding write address.
[0034] It should be noted that the master device can execute the master-slave write operation communication method described below to achieve the corresponding technical effect, and the slave device can execute the master-slave write operation communication method described below to achieve the corresponding technical effect. For brevity, details are omitted here; please refer to the relevant content in the method embodiments described above.
[0035] This invention also provides a master-slave device write operation communication method, applied to the master device. Please refer to [link / reference]. Figure 2 , Figure 2 This is one of the flowcharts illustrating a master-slave device write operation communication method provided in an embodiment of the present invention. The master-slave device write operation communication method includes S11, S12, and S13, which are described in detail below.
[0036] S11, when the master device needs to write data to the slave device, it sends a start bit.
[0037] The start bit is used to trigger the slave device on the I2C bus to start data listening and parsing.
[0038] S12, the master device sends the shared address corresponding to the current write operation.
[0039] By sending a shared address, a slave device on the I2C bus can confirm that it is the matching slave device corresponding to the shared address when its own address is the same as the shared address.
[0040] In one optional implementation, when sending the shared address corresponding to the current write operation, a write bit flag (R / W=0) is also sent. The write bit flag indicates that the current stage is the stage where the master device is sending data to the slave device. It should be noted that the write bit flag is not equivalent to the write operation.
[0041] Among them, the matching slave device has the same address as the shared address, and the number of matching slave devices can be greater than 1.
[0042] When a slave device detects a shared address, it checks if the address is the same as its own. If they are the same, it is confirmed that it is a matching slave device corresponding to the shared address. Only matching slave devices will continue to listen and parse subsequent content and receive the full stream data corresponding to the current write operation. Non-matching slave devices stop listening and parsing to reduce system power consumption.
[0043] When the shared address is the same as its own address, the slave device sends back an acknowledgment signal ACK via the I2C bus. It should be understood that when any slave device sends back an acknowledgment signal ACK, even if other slave devices send back a denial signal NACK, the I2C bus will ignore the denial signal NACK and only send back the acknowledgment signal ACK to the master device so that the master device can continue to send.
[0044] S13, the master device sequentially sends the write operation command, the identifier set, the write address, and the write data.
[0045] The identifier set includes at least one identifier of the participating slave device.
[0046] Optionally, a write operation command is sent in command byte C. The write operation command can be any one of the first type, the second type, and the third type. The first type of write operation command is represented as C=0x01~0x07, the second type of write operation command is represented as C=0x08, and the third type of write operation command is represented as C=0x0F. By sending the write operation command, all matching slave devices are brought into the write-ready state.
[0047] The identifier set may be, but is not limited to, a list of IDs, which includes at least one ID byte from the participating slave device.
[0048] The write address (reg) is the address in the register of the slave device, that is, the starting address of the register where the target data is written to the slave device. Optionally, it can be a 1-byte register starting address shared by all target slave devices, or it can be an N-byte register starting address, that is, each target slave device corresponds to a separate register starting address.
[0049] In one alternative implementation, the master device may send a stop bit after all written data has been sent.
[0050] By sending a write operation command, an identifier set, a write address, and write data, the target slave device identifies its corresponding target data from the write data according to the identifier arrangement order in the identifier set and the target data length of each target slave device, and completes the write of the target data based on its corresponding write address. After identifying the target data, the target slave device writes the target data to the corresponding register, and the starting address of the register is its corresponding write address. The target slave device is identified as a matching slave device belonging to the identifier set.
[0051] In the master-slave device write operation communication method provided in this embodiment of the invention, multiple slave devices can share a single address, distinguished by an identifier (e.g., ID), avoiding address resource waste and increasing the upper limit of the number of deployable slave devices. Furthermore, within a single I2C transaction, write data can be processed in blocks based on the identifier order in the identifier set and the target data length of each target slave device. Compared to requiring an I2C transaction for each slave device writing data, this reduces bus occupancy and latency, improving communication efficiency. Moreover, by adjusting the identifier order in the identifier set, the participation order and arbitrary combinations of slave devices can be dynamically specified, avoiding fixed bit strings or mapping dependencies. This makes the implementation more flexible and eliminates the need for additional mechanisms such as mapping tables, thus avoiding increased hardware complexity and power consumption of slave devices.
[0052] In one optional implementation, when the write operation command sent by the master device is a first type of write operation command, the target data lengths corresponding to all target slave devices are the same, and the target data lengths match the content of the first type of write operation command.
[0053] The target slave device can determine the target data length based on the content of the first type of write operation command.
[0054] The target slave device can determine the target data length corresponding to the content of different Type I write operation commands through a mapping relationship. Alternatively, if the Type I write operation command is represented as C=0x01~0x07, the lower 3 bits of the value can be taken as the target data length corresponding to the target slave device. Alternatively, if the Type I write operation command is represented as C=0x10, 0x20…0x70, the lower 3 bits of the value after dividing by 16 can be taken as the target data length corresponding to the target slave device.
[0055] In most scenarios, the length of a single data write is within 7 bytes. By implicitly containing data length information through command bytes of a limited type, and omitting the length of the target data to be sent separately, the length of communication data can be reduced and transmission efficiency can be improved.
[0056] Optionally, the first type of write operation command is any one of 0x01 to 0x07, and the target data length is the value of the lower 3 bits of the first type of write operation command.
[0057] It should be noted that S13, in which the master device sequentially sends the write operation command, the identifier set, the write address, and the write data, can be broken down into multiple sub-steps, as follows.
[0058] S131, the master device sends a write operation command.
[0059] S132, the master device sends the identifier set.
[0060] S133, Master device sends write address.
[0061] S135, the master device sends write data.
[0062] It should be understood that in some scenarios, the length of data written in a single operation may be large, and the first type of write operation command cannot meet the writing requirements for all data lengths. Therefore, this embodiment of the invention also provides an optional implementation method, please refer to... Figure 3 , Figure 3 This is a second flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention. When the write operation command sent by the master device is a second type of write operation command, the second type of write operation command is represented as C=0x08 or C=0x80, without specific limitations here. Before the master device sends the write data, the master-slave device write operation communication method further includes: S134A, as follows.
[0063] S134A, the master device sends the target data length so that all target slave devices can identify it.
[0064] At this point, all target devices need to write the same amount of data, which is the target data length. By adjusting the target data length, different data length writing requirements can be met, thus improving the compatibility of this communication method.
[0065] It should be noted that the master device may, but is not limited to, sending data in the following order: start bit → shared address (+ write bit) → write operation command → number of participating slave devices N → identifier set → write address → target data length L → write data → stop bit.
[0066] It should be understood that by sending the number of participating slave devices N, the slave devices can know that N is the number of identifier bytes in the identifier set; in the case of heterogeneous write addresses, N is the number of write address bytes; and when the target data lengths corresponding to different participating devices are different, N is the number of length bytes. Knowing the number of participating identifier bytes, address bytes, and length bytes, the slave devices can identify the byte type (belonging to participating identifier bytes, address bytes, or data length bytes, etc.) based on the content on the I2C bus, and thus obtain its corresponding sorting information, write address, and target data length, etc.
[0067] It should be understood that in some scenarios, different slave devices have different write data lengths. To meet the differentiated write data length requirements of different slave devices, this embodiment of the invention also provides an optional implementation method, please refer to... Figure 4 , Figure 4 This is the third flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention. When the write operation command sent by the master device is a third type of write operation command, the third type of write operation command is represented as C=0x0F or C=0xF0, without specific limitations here. Before the master device sends the write data, the master-slave device write operation communication method further includes: S134B, as follows.
[0068] S134B, the master device sends the target data length corresponding to each target slave device in the order of the identifiers in the identifier set, so that each target slave device can obtain its corresponding target data length in the order of the identifiers in the identifier set.
[0069] In this case, the write data length of different slave devices can be flexibly set, which can meet the needs of more scenarios and further improve the compatibility of the communication method.
[0070] Optionally, when the write operation command is a third type of write operation command and the master device does not send any target data length, each target slave device will use the preset length (default value) as its corresponding target data length.
[0071] When any two targets have different write addresses corresponding to the devices, this embodiment of the invention also provides an optional implementation method for how to achieve heterogeneous expansion to support different write addresses. Please refer to [link / reference]. Figure 5 , Figure 5 This is the fourth flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention. After the master device sends the identifier set, in step S133, the master device sends the write address, including step S133A, which is described in detail below.
[0072] The S133A master device sends the write addresses corresponding to each target slave device in sequence according to the identifier arrangement order in the identifier set.
[0073] This allows each target to obtain its corresponding write location from the device according to the identifier arrangement order in the identifier set.
[0074] If all target devices have the same write address, only one set of write addresses needs to be sent.
[0075] The master-slave device write operation communication method provided in this embodiment of the invention is applicable to different lengths, supports heterogeneous expansion, and improves system performance, such as synchronizing multiple chips in camera drivers.
[0076] Based on the preceding text, regarding the content in S132, this embodiment of the invention also provides an optional implementation method, please refer to the following text, S132, the master device sends an identifier set, including: S132A, as follows.
[0077] S132A: The master device sends the identifiers of participating slave devices in sequence according to the set order. After sending each identifier and receiving a confirmation signal from the slave device, it sends the identifier of the next participating slave device.
[0078] This ensures that if the matching slave device's own identifier matches the identifier of the participating slave devices, it is confirmed that the slave device is the target slave device corresponding to the write operation command.
[0079] Optionally, when the master device sends an identifier, all matching slave devices are in a listening and parsing state. When any matching slave device recognizes the identifier sent by the master device, it can send an acknowledgment signal back to the master device via the I2C bus, which can improve communication efficiency. Alternatively, when a matching slave device recognizes the identifier sent by the master device, it determines whether its own identifier is the same as the identifier sent by the master device. If they are the same, it sends an acknowledgment signal back to the master device via the I2C bus to ensure the accuracy of the communication result.
[0080] This invention also provides a master-slave device write operation communication method, applied to a slave device. Please refer to [link / reference]. Figure 6 , Figure 6 This is the fifth flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention. The master-slave device write operation communication method includes steps S21, S22, S23, S24, and S26, which are described in detail below.
[0081] S21, when the slave device receives the start bit sent by the master device, it enters the listening and parsing state.
[0082] Entering the listening and parsing state means that the slave device listens for and parses the data on the I2C bus.
[0083] S22, when a slave device confirms that the shared address it is listening to is the same as its own address, it confirms that the shared address is the matching slave device.
[0084] Optionally, the master device may send a write bit identifier synchronously with the shared address.
[0085] The matching slave device has the same address as the shared address. The number of matching slave devices can be greater than 1. It should be understood that only matching slave devices will continue to listen and parse subsequent content, while non-matching slave devices will stop listening and parsing in order to reduce system power consumption.
[0086] S23, match the write operation command and identifier set sent by the master device to the slave device. If the slave device's own identifier belongs to the identifier set, confirm that it is the target slave device corresponding to the write operation command.
[0087] The identifier set includes at least one identifier (ID) of the participating slave device.
[0088] It should be understood that the target device continues to listen for subsequent write addresses and write data.
[0089] S24, the target device continues to listen for the write address sent by the master device.
[0090] S26, the target slave device continues to listen to the write data sent by the master device, identifies the corresponding target data from the write data according to the identifier arrangement order in the identifier set and the target data length of each target slave device, and completes the target data writing based on its corresponding write address.
[0091] After the target device identifies the number of targets, it writes the target data into the corresponding register, and the starting address of the register is the corresponding write address.
[0092] In the master-slave device write operation communication method provided in this embodiment of the invention, multiple slave devices can share a single address, distinguished by an identifier (e.g., ID), avoiding address resource waste and increasing the upper limit of the number of deployable slave devices. Furthermore, within a single I2C transaction, write data can be processed in blocks based on the identifier order in the identifier set and the target data length of each target slave device. Compared to requiring an I2C transaction for each slave device writing data, this reduces bus occupancy and latency, improving communication efficiency. Moreover, by adjusting the identifier order in the identifier set, the participation order and arbitrary combinations of slave devices can be dynamically specified, avoiding fixed bit strings or mapping dependencies. This makes the implementation more flexible and eliminates the need for additional mechanisms such as mapping tables, thus avoiding increased hardware complexity and power consumption of slave devices.
[0093] Please refer to Figure 7 , Figure 7 This is a sixth flowchart illustrating the master-slave device write operation communication method provided in an embodiment of the present invention. When the write operation command is a first type of write operation command, the master-slave device write operation communication method further includes: S251, as detailed below.
[0094] S251, the target device identifies the content of the first type of write operation command and determines the corresponding target data length based on the content of the first type of write operation command.
[0095] All target slave devices have the same target data length, and this target data length matches the content of the first type of write operation command. The target slave device can determine the target data length corresponding to the content of different first type of write operation commands through a mapping relationship. Alternatively, if the first type of write operation command is represented as C=0x01~0x07, the lower 3 bits can be taken as the target data length corresponding to the target slave device. Alternatively, if the first type of write operation command is represented as C=0x10, 0x20…0x70, the lower 3 bits after dividing by 16 can be taken as the target data length corresponding to the target slave device.
[0096] Optionally, the first type of write operation command is any one of 0x01 to 0x07, and the target data length is the value of the lower 3 bits of the first type of write operation command.
[0097] Please continue to refer to this. Figure 7 In an optional implementation, when the write operation command is a second type of write operation command, the master-slave device write operation communication method further includes: S252, as follows.
[0098] S252, the target slave device listens to and identifies the length of the target data sent by the master device. The master device sends the length of the target data before sending the write data.
[0099] At this point, all targets have the same target data length corresponding to the devices.
[0100] Please continue to refer to this. Figure 7 In an optional implementation, when the write operation command is a third type of write operation command, the master-slave device write operation communication method further includes: S253, as follows.
[0101] S253, the target slave device listens to and identifies the target data length set on the I2C bus, and obtains the corresponding target data length according to the sorting order of the identifiers in the identifier set.
[0102] The target data length set is the set of target data lengths that the master device sends sequentially according to the identifier arrangement order in the identifier set.
[0103] In this case, the write data length of different slave devices can be flexibly set, which can meet the needs of more scenarios and further improve the compatibility of the communication method.
[0104] Please continue to refer to this. Figure 7 Regarding how to obtain the write address, this embodiment of the invention also provides an optional implementation method, S24, in which the target slave device continues to listen for the write address sent by the master device, including: S241, as follows.
[0105] S241, the target device listens to and identifies the write address set on the I2C bus, and obtains the write address according to the order of the identifiers in the identifier set.
[0106] The write address set is the set of write addresses that the master device sends sequentially according to the identifier order in the identifier set when the write addresses corresponding to any two target slave devices are different.
[0107] Based on the preceding text, regarding the content of S23, this embodiment of the invention also provides an optional implementation method, please refer to the following. S23, matching the write operation command and identifier set sent by the master device to the slave device, if its own identifier belongs to the identifier set, confirming that it is the target slave device corresponding to the write operation command, including: S231, specifically as follows.
[0108] S231, the matching slave device listens for and identifies the identifiers of participating slave devices sent sequentially by the master device in a set order. When its own identifier is the same as the identifier of the identified participating slave device, it confirms that it is the target slave device corresponding to the write operation command, and sends an acknowledgment signal back to the master device through the I2C bus so that the master device can continue to send the identifier of the next participating slave device.
[0109] Building upon the preceding text, this embodiment of the invention also provides an optional implementation method for how a slave device identifies its corresponding target data, as detailed below. The target slave device identifies its corresponding target data from the written data according to the identifier arrangement order in the identifier set and the target data length of each target slave device, including: S261, which is specifically described below.
[0110] S261, the target slave device determines its extraction point in the written data according to the target data length of each first type of device, and extracts the written data of the target data length from the extraction point as its corresponding target data.
[0111] Among them, the first type of device is other slave devices whose identifiers are arranged in a centralized manner before the target slave device, and the interval between the extraction point and the starting point of writing data is equal to the sum of the target data lengths of each first type of device.
[0112] This invention also provides a master-slave device write operation communication method, applied to a communication system. Please refer to [link / reference]. Figure 8 , Figure 8 This is the seventh flowchart illustrating the master-slave device write operation communication method provided in this embodiment of the invention. The slave device write operation communication method includes S31-S34 and S51-S54, which are described in detail below.
[0113] S31, when the master device needs to write data to the slave device, it sends a start bit.
[0114] S51: When the slave device receives the start bit sent by the master device, it enters the listening and parsing state.
[0115] S32, the master device sends the shared address corresponding to the current write operation.
[0116] S52, when a slave device confirms that the shared address it is listening to is the same as its own address, it confirms that the shared address is the matching slave device.
[0117] S33, the master device sequentially sends a write operation command and an identifier set, wherein the identifier set includes at least one identifier of the participating slave device.
[0118] S53: Match the write operation command and identifier set sent by the master device to the slave device. If the slave device's own identifier belongs to the identifier set, it is confirmed that it is the target slave device corresponding to the write operation command.
[0119] S34, the master device sends the write address and write data sequentially.
[0120] S54, the target slave device continues to listen to the write address and write data sent by the master device, identifies the corresponding target data from the write data according to the identifier arrangement order in the identifier set and the target data length of each target slave device, and completes the target data writing based on the corresponding write address.
[0121] It should be noted that the master-slave device write operation communication method applied to the communication system can include the content of the master-slave device write operation communication method applied to both the master device and the slave device, which will not be elaborated here.
[0122] The following is an example of a write operation between master and slave devices. Assume that the write operation command is the first type of write operation command C=0x02 (implying the target data length = 2), the number of participating slave devices N=3, the identifier set uses an ID list, ID list = [0x01, 0x02, 0x03], and all target slave devices (participating slave devices) have the same write address reg, reg=0x10.
[0123] Master device sends: Start bit → Shared address (+Write bit) → Write operation command C=0x02 → Number of participating slave devices N =3 → Identifier set [0x01,0x02,0x03] → Write address reg=0x10 → Write data → Stop bit.
[0124] The data written is a total of 6 bytes. 0x01 corresponds to the first 2 bytes extracted from the device and written to reg; 0x02 corresponds to the middle 2 bytes extracted from the device and written to reg; 0x03 corresponds to the last 2 bytes extracted from the device and written to reg.
[0125] In summary, the master-slave device write operation communication method and system provided by this invention involves the master device sending the shared address corresponding to the current write operation to enable slave devices on the I2C bus to confirm whether they are matching slave devices. The master device sequentially sends a write operation command, an identifier set, a write address, and write data, allowing the target slave device to identify its corresponding target data from the write data according to the identifier arrangement order in the identifier set and the target data length of each target slave device. The target slave device then completes the write of the target data based on its corresponding write address. The target slave device is a matching slave device whose identifier belongs to the identifier set. Multiple slave devices can share a single address, distinguished by identifiers, avoiding address resource waste and increasing the maximum number of deployable slave devices. Furthermore, within a single I2C transaction, write data can be processed in blocks based on the identifier arrangement order in the identifier set and the target data length of each target slave device, reducing bus occupancy and latency, and improving communication efficiency. The participation order and arbitrary combination of slave devices can be dynamically specified without requiring additional mechanisms such as mapping tables, avoiding increased hardware complexity and power consumption of slave devices.
[0126] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
[0127] 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.
Claims
1. A master-slave device write operation communication method characterized by, The application is applied to a master device connected with a plurality of slave devices through an I2C bus, and the method comprises the following steps: After sending a start bit, the master device sends a shared address corresponding to a current write operation, so that a slave device on the I2C bus confirms that it is a matching slave device corresponding to the shared address when its own address is the same as the shared address; The master device sends a write operation command, an identification set, a write address and write data in sequence; The identification set comprises at least one identification of a participating slave device; So that a target slave device identifies its corresponding target data from the write data according to the identification arrangement order in the identification set and the target data length of each target slave device, and completes the target data writing based on its corresponding write address, the target slave device being the matching slave device whose own identification belongs to the identification set.
2. The master-slave device write operation communication method of claim 1, wherein, When the write operation command sent by the master device is a first type of write operation command, the target data length of all target slave devices is the same, and the target data length matches the content of the first type of write operation command.
3. The master-slave device write operation communication method of claim 2, wherein, The first type of write operation command is any one of 0x01-0x07, and the target data length is the value of the low 3 bits in the first type of write operation command.
4. The master-slave device write operation communication method of claim 1, wherein, When the write operation command sent by the master device is a second type of write operation command, before the master device sends the write data, the method further comprises the following steps: The master device sends a target data length for all target slave devices to identify.
5. The master-slave device write operation communication method of claim 1, wherein, When the write operation command sent by the master device is a third type of write operation command, before the master device sends the write data, the method further comprises the following steps: The master device sends the target data length of each target slave device in sequence according to the identification arrangement order in the identification set, so that each target slave device obtains its corresponding target data length according to the identification arrangement order in the identification set.
6. The master-slave device write operation communication method according to any one of claims 1 to 5, wherein When the write address of any two target slave devices is different, after the master device sends the identification set, the method further comprises the following steps: The master device sends the write address of each target slave device in sequence according to the identification arrangement order in the identification set, so that each target slave device obtains its corresponding write address according to the identification arrangement order in the identification set.
7. The master-slave device write operation communication method according to any one of claims 1 to 5, wherein The master device sends the identification set, comprising the following steps: The master device sends the identification of a participating slave device in sequence according to a set order, and sends the identification of the next participating slave device after sending the identification each time and receiving an acknowledgement signal fed back by the slave device, so that the matching slave device confirms that it is a target slave device corresponding to the write operation command when its own identification is the same as the identification of the participating slave device.
8. A master-slave device write operation communication method characterized by comprising: The application is applied to a slave device connected with a master device through an I2C bus, and the method comprises the following steps: The slave device enters a listening and analyzing state when it obtains a start bit sent by the master device; The slave device confirms that it is a matching slave device corresponding to the shared address when it confirms that the shared address it listens to is the same as its own address; The matching slave device listens to a write operation command and an identification set sent by the master device, and if the identification of the matching slave device belongs to the identification set, the matching slave device confirms that it is a target slave device corresponding to the write operation command; The identification set includes at least one identification of a participating slave device; The target slave device continues to listen to a write address and write data sent by the master device, identifies corresponding target data from the write data according to an arrangement order of the identifications in the identification set and a target data length of each target slave device, and completes writing of the target data based on a corresponding write address.
9. The master-slave device write operation communication method of claim 8, wherein, When the write operation command is a first type of write operation command, the method further includes: The target slave device identifies content of the first type of write operation command, and determines a target data length corresponding to the target slave device according to the content of the first type of write operation command.
10. The master-slave device write operation communication method of claim 9, wherein, The first type of write operation command is any one of 0x01 to 0x07, and the target data length is a value of low 3 bits in the first type of write operation command.
11. The master-slave device write operation communication method of claim 8, wherein, When the write operation command is a second type of write operation command, the method further includes: The target slave device listens to and identifies a target data length sent by the master device, and the master device sends the target data length before sending write data.
12. The master-slave device write operation communication method of claim 8, wherein, When the write operation command is a third type of write operation command, the method further includes: The target slave device listens to and identifies a target data length set on an I2C bus, and obtains a target data length corresponding to the target slave device according to an arrangement order of identifications in the identification set; The target data length set is a set of target data lengths sent by the master device in turn according to the arrangement order of the identifications in the identification set.
13. The master-slave device write operation communication method according to any one of claims 8 to 12, wherein The method further includes: The target slave device listens to and identifies a write address set on the I2C bus, and obtains a write address according to the arrangement order of the identifications in the identification set; When write addresses corresponding to any two target slave devices are different, the write address set is a set of write addresses corresponding to each target slave device sent by the master device in turn according to the arrangement order of the identifications in the identification set.
14. The master-slave device write operation communication method according to any one of claims 8 to 12, wherein The matching slave device listens to a write operation command and an identification set sent by the master device, and if the identification of the matching slave device belongs to the identification set, the matching slave device confirms that it is a target slave device corresponding to the write operation command, including: The matching slave device listens to and identifies identifications of participating slave devices sent by the master device in turn according to a set order, and when the identification of the matching slave device is the same as the identified identifications of the participating slave devices, the matching slave device confirms that it is a target slave device corresponding to the write operation command, and feeds back a confirmation signal to the master device through the I2C bus, so that the master device continues to send an identification of a next participating slave device.
15. The master-slave device write operation communication method according to any one of claims 8 to 12, wherein The target slave device identifies corresponding target data from the write data according to an arrangement order of the identifications in the identification set and a target data length of each target slave device, including: The target slave device determines an extraction point in the write data according to the target data length of each first type of device, and extracts the write data of the target data length from the extraction point as the corresponding target data; The first type of device is other slave devices arranged in the identification set before the target slave device, and an interval from the extraction point to the start point of the write data is equal to a sum of target data lengths of each first type of device.
16. A master-slave device write operation communication method characterized by comprising: The application is applied to a communication system, and the communication system comprises a master device and a plurality of slave devices. The master device sends a start bit when it needs to write data to the slave device. The slave device enters a listening and parsing state when it acquires the start bit sent by the master device. The master device sends a shared address corresponding to a current write operation. The slave device confirms that it is a matching slave device corresponding to the shared address when it confirms that the shared address listened to is the same as the address of the slave device. The master device sends a write operation command and an identification set in sequence, wherein the identification set comprises at least one identification of a participating slave device. The matching slave device listens to the write operation command and the identification set sent by the master device, and confirms that it is a target slave device corresponding to the write operation command if the identification of the matching slave device belongs to the identification set. The master device sends a write address and write data in sequence. The target slave device continues to listen to the write address and write data sent by the master device, identifies target data corresponding to the target slave device from the write data according to an identification arrangement order in the identification set and a target data length of each target slave device, and completes the target data write based on the corresponding write address.
17. A master-slave device communication system, characterized by The communication system comprises a master device and a plurality of slave devices, and the master device is connected to the plurality of slave devices through an I2C bus. The master device is configured to send a start bit when it needs to write data to the slave device. The slave device is configured to enter a listening and parsing state when it acquires the start bit sent by the master device. The master device is configured to send a shared address corresponding to a current write operation. The slave device is configured to confirm that it is a matching slave device corresponding to the shared address when it confirms that the shared address listened to is the same as the address of the slave device. The master device is configured to send a write operation command and an identification set in sequence, wherein the identification set comprises at least one identification of a participating slave device. The matching slave device is configured to listen to the write operation command and the identification set sent by the master device, and confirm that it is a target slave device corresponding to the write operation command if the identification of the matching slave device belongs to the identification set. The master device is configured to send a write address and write data in sequence. The target slave device is configured to continue to listen to the write address and write data sent by the master device, identify target data corresponding to the target slave device from the write data according to an identification arrangement order in the identification set and a target data length of each target slave device, and complete the target data write based on the corresponding write address.
Citation Information
Patent Citations
Task processing method and device, electronic equipment and storage medium
CN116166408A
Communication method of master-slave system, master-slave system, electronic equipment and communication device
CN118349510A
Bus communications with multi-device messaging
US20160314087A1
Cited By
Master-slave device read operation communication method and communication system
CN121614432A