Master-slave device read operation communication method and communication system
By using shared addresses and identifier ordering in I2C communication, the problems of address resource waste and multiple transactions in I2C communication are solved, achieving efficient data transmission from slave devices and improving system efficiency and flexibility.
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, when a master device communicates with multiple slave devices, address resources are consumed in large quantities, and traditional methods require initiating multiple independent transactions, which increases communication overhead and reduces system efficiency.
The master device sends a shared address and a write bit flag, then sequentially sends a read operation command and a participation flag to participate in the slave device's cached address reading; then it sends a repeat start bit and a read bit flag to participate in the slave device's data feedback according to the flags.
Multiple slave devices share an address, reducing address resource waste, increasing the upper limit of the number of devices, reducing bus occupation and latency, improving communication efficiency, enabling flexible slave device order and combination, and avoiding fixed bit strings or mapping dependencies.
Smart Images

Figure CN121614432A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communications, and more specifically, to a master-slave device read 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 read from 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 read operation communication method and communication 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 read 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 and write bit identifier corresponding to the current read operation, and then sends the read operation command, N participation identifiers and the read address in sequence; so that the participating slave devices can obtain and cache their corresponding read addresses, wherein the participating slave device is a slave device whose own address matches the shared address and whose own identifier is the same as at least one participation identifier; The master device sends a repeat start bit, the shared address corresponding to the current read operation, and a read bit identifier; so that the participating slave device, according to the order of its own identifier among N participating identifiers, feeds back the target data to the master device, wherein the target data is the data corresponding to the read address in the participating slave device.
[0006] Secondly, embodiments of the present invention provide a master-slave device read 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 a slave device detects a shared address that is the same as its own address, it confirms that the slave device is the matching slave device corresponding to the shared address. The matching slave device listens to the read operation command, N participation identifiers and read address sent by the master device. When its own identifier is the same as any of the participation identifiers, it determines that it is the participating slave device corresponding to the read operation command, and obtains and caches its corresponding read address. When the participating slave device detects the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier sent by the master device, it feeds back the target data to the master device according to the sorting of its own identifier among the N participating identifiers. The target data is the data corresponding to the read address in the participating slave device.
[0007] Thirdly, embodiments of the present invention provide a master-slave device read 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 read data from 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 and write bit identifier corresponding to the current read operation; When a slave device detects a shared address that is the same as its own address, it confirms that the slave device is the matching slave device corresponding to the shared address. The master device sequentially sends a read operation command, N participation identifiers, and the read address; The matching slave device listens to the read operation command, N participation identifiers and read address sent by the master device. When its own identifier is the same as any of the participation identifiers, it determines that it is the participating slave device corresponding to the read operation command, and obtains and caches its corresponding read address. The master device sends the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier; When the participating slave device hears the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier sent by the master device, it feeds back the target data to the master device according to the sorting of its own identifier among the N participating identifiers. The target data is the data corresponding to the address read from the participating device.
[0008] Fourthly, embodiments of the present invention provide a master-slave device read operation 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 read data from 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 and write bit identifier corresponding to the current read operation; The slave device is used to confirm that it is the matching slave device corresponding to the shared address when the shared address it is listening to is the same as its own address; The master device is used to sequentially send a read operation command, N participation identifiers, and the read address; The matching slave device is used to listen to the read operation command, N participation identifiers and read address sent by the master device. When its own identifier is the same as any of the participation identifiers, it is determined to be the participating slave device corresponding to the read operation command, and its corresponding read address is obtained and cached. The master device is used to send the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier; The participating slave device is used to send the target data back to the master device according to the order of its own identifier among N participating identifiers when it hears the repeat start bit, the shared address corresponding to the current read operation and the read bit identifier sent by the master device. The target data is the data corresponding to the address read from the participating device.
[0009] Compared to existing technologies, the master-slave device read operation communication method and system provided in this invention, after sending a start bit, the master device sends the shared address and write bit identifier corresponding to the current read operation, and sequentially sends the read operation command, N participation identifiers, and the read address; so that participating slave devices can obtain and cache their corresponding read addresses; the master device sends a repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier; so that participating slave devices can feed back the target data to the master device according to the order of their own identifiers among the N participation identifiers. Multiple slave devices can share a single address, distinguished by identifiers (e.g., IDs), avoiding address resource waste and increasing the upper limit of the number of deployable slave devices. Furthermore, within a single I2C transaction, read data can be sent in blocks based on the order of participation identifiers, reducing bus occupancy and latency compared to each slave device requiring an I2C transaction for reading data, thus improving communication efficiency. Moreover, by adjusting the identifier order, the participation order and arbitrary combinations of slave devices can be dynamically specified, avoiding fixed bit strings or mapping dependencies, making the implementation more flexible and eliminating the need for additional mechanisms such as mapping tables, thus avoiding increased hardware complexity and power consumption of 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 read operation communication method provided in an embodiment of the present invention.
[0014] Figure 3 This is the second flowchart illustrating the master-slave device read operation communication method provided in an embodiment of the present invention.
[0015] Figure 4 This is the third flowchart illustrating the master-slave device read operation communication method provided in this embodiment of the invention.
[0016] Figure 5 This is the fourth flowchart illustrating the master-slave device read operation communication method provided in this embodiment of the invention.
[0017] Figure 6 The fifth flowchart illustrates the master-slave device read operation communication method provided in this embodiment of the invention.
[0018] Figure 7 This is the sixth flowchart illustrating the master-slave device read operation communication method provided in this embodiment of the invention.
[0019] Figure 8 This is the seventh flowchart illustrating the master-slave device read 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, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, 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. Without further limitations, 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 said element.
[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 address, read address, target length for writing, target length for reading, and their corresponding identifier order. 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 data it needs to read back to the master device via the I2C bus.
[0026] The master device sends a start bit when it needs to read data from 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 and write bit identifier corresponding to the current read 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 the shared address is the same as its own address.
[0030] The master device is used to send read operation commands, N participation identifiers, and the read address in sequence.
[0031] The matching slave device is used to listen for the read operation command sent by the master device, N participation identifiers and the read address. When its own identifier is the same as any of the participation identifiers, it is determined to be the participating slave device corresponding to the read operation command, and its corresponding read address is obtained and cached.
[0032] The master device is used to send the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier.
[0033] When a participating slave device detects the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier sent by the master device, it feeds back the target data to the master device according to the order of its own identifier among N participating identifiers.
[0034] The target data refers to the data corresponding to the address read from the device.
[0035] It should be noted that the master device can execute the master-slave read operation communication method described below to achieve the corresponding technical effect, and the slave device can execute the master-slave read 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.
[0036] This invention also provides a master-slave device read operation communication method, applied to a master device. Please refer to [link / reference]. Figure 2 , Figure 2 This is one of the flowcharts illustrating a master-slave device read operation communication method provided in an embodiment of the present invention. The master-slave device read operation communication method includes S11, S12, and S13, which are described in detail below.
[0037] S11, When the master device needs to read data from the slave device, it sends a start bit.
[0038] The Start bit is used to trigger the slave device on the I2C bus to start data listening and parsing.
[0039] S12, the master device sends the shared address and write bit identifier corresponding to the current read operation, and then sends the read operation command, N participation identifiers and the read address in sequence.
[0040] By sending a shared address, a write bit identifier, an operation command, N participation identifiers, and a read address, participating slave devices can obtain and cache their corresponding read addresses. A participating slave device is a slave device whose own address matches the shared address (it can be, but is not limited to, being the same), and whose own identifier is the same as at least one participation identifier.
[0041] The write bit flag R / W=0 indicates that the master device is transmitting the read address reg and the sorting information of N participant identifiers to the participating slave devices. The participant identifiers are the identifiers of the participating slave devices, and N is greater than or equal to 1.
[0042] When all participating slave devices have the same read address, the master device only needs to send one read address, which is shared by all participating slave devices. When any two participating slave devices have different read addresses, a heterogeneous address approach can be adopted, where the master device sends N read addresses respectively, and the participating slave devices determine their corresponding read addresses based on the order of their own identifiers among the N participating identifiers.
[0043] S13, the master device sends the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier.
[0044] The Repeated Start bit is used to indicate that the operation corresponding to the write bit flag has ended, and the read bit flag R / W=1 indicates that the master device needs to read the data corresponding to the read address reg of the participating slave device.
[0045] By sending a repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier, the participating slave devices can send the target data back to the master device according to the order of their own identifiers among N participating identifiers.
[0046] The target data is the data corresponding to the address read from the device. The length of the target data can be the default length or a specified length sent by the master device. The read address can be understood as the starting address for reading the target data.
[0047] In the master-slave device read 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, read data can be sent in blocks based on the order of participation identifiers. Compared to each slave device requiring an I2C transaction for reading data, this reduces bus occupancy and latency, improving communication efficiency. Moreover, by adjusting the identifier order, 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.
[0048] It should be understood that the master device receives and stores the target data fed back by each participating slave device. When the master device receives the target data fed back by the first N-1 participating slave devices, it sends back an ACK signal via the I2C bus to enable the next participating slave device to send back the target data. When the master device receives the target data fed back by the Nth participating slave device, it sends back a NACK signal and a Stop bit via the I2C bus to notify all slave devices that the read operation has ended.
[0049] Regarding the signal timing in the master-slave device read operation communication method, this embodiment of the invention also provides an optional implementation method, please refer to the following.
[0050] The master device sends the start bit (Start) → The master device sends the shared address and write bit identifier (R / W) → The slave device sends the acknowledgment signal (ACK) → The master device sends the read operation command → The slave device sends the acknowledgment signal (ACK) → The master device sends the number of participating slave devices (N) → The slave device sends the acknowledgment signal (ACK) → The master device sends the first participating identifier → The slave device sends the acknowledgment signal (ACK) → The master device sends the second participating identifier → The slave device sends the acknowledgment signal (ACK) → The master device sends the Nth participating identifier → The slave device sends the acknowledgment signal (ACK) → The master device sends the read address (reg) → The slave device sends the acknowledgment signal (ACK) → The master device sends the repeat start bit (Repeated Start) → The master device sends the shared address and write bit identifier (R / W) → The slave device sends the acknowledgment signal (ACK) → The first participating slave device sends the target data → The master device sends the acknowledgment signal (ACK) → The second participating slave device sends the target data → The master device sends the acknowledgment signal (ACK) → The Nth participating slave device sends the target data → The master device sends the denial signal (NACK) and the stop bit (Stop).
[0051] 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 participation identifier bytes, the number of read address bytes when the read addresses are heterogeneous, and the number of length bytes when the target data lengths corresponding to different participating devices are different. Knowing the number of participation identifier bytes, address bytes, and length bytes, the slave devices can identify the byte type (participation identifier bytes, address bytes, or data length bytes, etc.) based on the content on the I2C bus, and thus obtain its corresponding sorting information, read address, and target length.
[0052] In one optional implementation, when the read operation command sent by the master device is a first type of read operation command, all participating slave devices have the same target length, and the target length matches the content of the first type of read operation command. The target length is the length of the target data fed back by the participating slave devices to the master device (also called the target data length).
[0053] Participating slave devices can determine the target length corresponding to the content of different Type I read operation commands through a mapping relationship. Alternatively, if a Type I read operation command is represented as C=0x01~0x07, the lower 3 bits of that value can be taken as the target length corresponding to the participating slave device. Or, if a Type I read operation command is represented as C=0x10, 0x20…0x70, the lower 3 bits of the result after dividing by 16 can be taken as the target length corresponding to the participating slave device.
[0054] In most scenarios, the length of a single data read is within 7 bytes. By implicitly containing data length information through command bytes of a limited type and omitting the target length to be sent separately, the length of communication data can be reduced and transmission efficiency can be improved.
[0055] Optionally, the first type of read operation command is any one of 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 and 0x70, and the target length is the value of the lower 3 bits after dividing the first type of read operation command by 16.
[0056] It should be noted that in S12, the master device sends the shared address and write bit identifier corresponding to the current read operation, and sequentially sends the read operation command, N participation identifiers and the read address. This can be broken down into multiple sub-steps, as follows.
[0057] S121, the master device sends the shared address and write bit identifier corresponding to the current read operation.
[0058] S122, the master device sends a read operation command.
[0059] S123, the master device sends N participation identifiers.
[0060] S124, Master device sends read address.
[0061] It should be understood that in some scenarios, the data length to be read in a single I2C transaction may be large, and the first type of read operation command cannot meet all data length reading requirements. Therefore, this embodiment of the invention also provides an optional implementation method, please refer to... Figure 3 , Figure 3 This is the second flowchart illustrating the master-slave device read operation communication method provided in this embodiment of the invention. When the read operation command sent by the master device is a second type of read operation command, the second type of read operation command is represented as C=0x80 or C=0x08, without specific limitations here. After the master device sends the read address, the master-slave device read operation communication method further includes: S125A, which is described in detail below.
[0062] S125A, the master device sends the target length for all participating slave devices to identify.
[0063] It should be noted that when the master device sends a type 2 read operation command, even if the number of participating slave devices N is greater than 1, there is only one length byte. In this case, all participating slave devices need to return the same data length, which is the target length. By adjusting the target length, different data length reading requirements can be met, thus improving the compatibility of this communication method.
[0064] It should be understood that in some scenarios, different slave devices require different data lengths. To meet the differentiated 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 read operation communication method provided in this embodiment of the invention. When the read operation command sent by the master device is a third type of read operation command, the third type of read operation command is represented as C=0xF0 or C=0x0F, without specific limitations here. After the master device sends the read address, the master-slave device read operation communication method further includes: S125B, which is described in detail below.
[0065] S125B, the master device sends the target length corresponding to the participating slave device in the order of the N participating identifiers, so that each participating slave device can obtain its corresponding target length according to the order of its own identifier in the N participating identifiers.
[0066] Optionally, N length bytes are sent, where the value in the nth length byte is the target length corresponding to the Nth participating slave device. In this case, the read data length of different slave devices can be flexibly set, which can meet the needs of more scenarios and further improve the compatibility of this communication method.
[0067] Optionally, when the read operation command is a third type of read operation command and the master device does not send any target length, each participating slave device will use the preset length as its corresponding target length.
[0068] When any two participating slave devices have different read addresses, this embodiment of the invention also provides an optional implementation method for how to achieve heterogeneous expansion to support different read addresses. Please refer to [link / reference]. Figure 5 , Figure 5 This is the fourth flowchart illustrating the master-slave device read operation communication method provided in this embodiment of the invention. S124, the master device sends the read address, including: S124A, which is described in detail below.
[0069] S124A, the master device sends the read address corresponding to each participating slave device in sequence according to the arrangement order of N participating identifiers.
[0070] This allows each participating slave device to obtain its corresponding read address according to its own identifier's order among N participating identifiers. Optionally, the master device sends N address bytes, where the value in the nth address byte is the read address corresponding to the Nth participating slave device.
[0071] If all participating slave devices have the same read address, only one set of read addresses needs to be sent.
[0072] Based on the preceding text, regarding the content in S123, this embodiment of the invention also provides an optional implementation method, please refer to [link / reference needed]. Figure 5 S123, the master device sends N participation identifiers, including: S123A, which is described in detail below.
[0073] S123A: The master device sends participation identifiers sequentially according to the set order. After sending each participation identifier and receiving a confirmation signal from the slave device, it sends the next participation identifier.
[0074] This ensures that when a slave device's own address matches the shared address and its own identifier is the same as the participant identifier, it is confirmed as the participating slave device corresponding to the read operation command.
[0075] Optionally, when the master device sends the participation identifier, all slave devices matching the shared address are in a listening and parsing state. When any matching slave device recognizes the participation identifier sent by the master device, it can send an acknowledgment signal back to the master device via the I2C bus, thus improving communication efficiency. Alternatively, when a matching slave device recognizes the participation identifier sent by the master device, it checks whether its own identifier is the same as the participation identifier. If they are the same, it sends an acknowledgment signal back to the master device via the I2C bus, ensuring the accuracy of the communication result.
[0076] This invention also provides a master-slave device read 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 read operation communication method provided in this embodiment of the invention. The master-slave device read operation communication method includes steps S21, S22, S23, and S25, which are described in detail below.
[0077] S21, when the slave device receives the start bit sent by the master device, it enters the listening and parsing state.
[0078] Entering the listening and parsing state means that the slave device listens for and parses the data on the I2C bus.
[0079] S22, when a slave device detects a shared address that is the same as its own address, it confirms that the slave device is the matching slave device corresponding to the shared address.
[0080] Optionally, the master device will synchronously send a write bit flag with the shared address. A write bit flag R / W=0 indicates that the master device is transmitting the read address reg to the participating slave devices. When the shared address is the same as its own address, the slave device sends an acknowledgment signal ACK via the I2C bus. It should be understood that when any slave device sends an acknowledgment signal ACK, even if other slave devices send a denial signal NACK, the I2C bus will ignore the denial signal NACK and only send the acknowledgment signal ACK back to the master device, allowing the master device to continue transmitting.
[0081] 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.
[0082] S23, match the read operation command, N participation identifiers and read address sent by the master device by the slave device. When its own identifier is the same as any of the participation identifiers, determine that it is the participating slave device corresponding to the read operation command, and obtain and cache its corresponding read address.
[0083] S25, when the participating slave device hears the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier sent by the master device, it feeds back the target data to the master device according to the order of its own identifier among the N participating identifiers.
[0084] The Repeated Start bit is used to indicate that the operation corresponding to the write bit flag has ended. The read bit flag R / W=1 indicates that the master device needs to read the data corresponding to the read address reg of the participating slave device. The target data is the data corresponding to the read address in the participating slave device. The length of the target data can be the default length or the specified length sent by the master device. The read address can be understood as the starting address for reading the target data.
[0085] In the master-slave device read 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, read data can be sent in blocks based on the order of participation identifiers. Compared to each slave device requiring an I2C transaction for reading data, this reduces bus occupancy and latency, improving communication efficiency. Moreover, by adjusting the identifier order, 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.
[0086] Please refer to Figure 7 , Figure 7 This is a sixth flowchart illustrating the master-slave device read operation communication method provided in an embodiment of the present invention. When the read operation command is a first type of read operation command, the master-slave device read operation communication method further includes: S241, as detailed below.
[0087] S241, the device identifies the content of the first type of read operation command and determines its corresponding target length based on the content of the first type of read operation command.
[0088] Optionally, the first type of read operation command is any one of 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 and 0x70, and the target length is the value of the lower 3 bits after dividing the first type of read operation command by 16.
[0089] Please continue to refer to this. Figure 7 In an optional implementation, when the read operation command is a second type of read operation command, the master-slave device read operation communication method further includes: S242, as follows.
[0090] S242, participates in listening to and identifying the target length sent by the master device.
[0091] Specifically, the master device sends the target length before sending the repeat start bit. Due to protocol uniformity, the master device can send the target length after sending the read address, and the target lengths of the N participating slave devices are unified.
[0092] Please continue to refer to this. Figure 7 In an optional implementation, when the read operation command is a third type of read operation command, the master-slave device read operation communication method further includes: S243, as follows.
[0093] S243, the participating device listens to and identifies N target lengths on the I2C bus, and obtains the corresponding target length according to the sorting of its own identifier among the N participating identifiers.
[0094] Among them, the N target lengths are sent by the master device in the order of the N participating identifiers, and the target lengths of the N participating slave devices are not uniform.
[0095] Building upon the preceding text, this embodiment of the invention also provides an optional implementation method for how the participating slave device obtains its corresponding read address, as detailed below. The master-slave device read operation communication method further includes: S23A, as detailed below.
[0096] S23A participates in listening to and identifying N read addresses on the I2C bus from the slave device, and obtains the corresponding read address according to the sorting of its own identifier among the N participating identifiers.
[0097] Among them, the N read addresses are the N read addresses sent by the master device in the order of the N participation identifiers when the read addresses corresponding to any two participating slave devices are different.
[0098] 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 read operation command, N participation identifiers, and read address sent by the master device to the slave device, and determining that it is the participating slave device corresponding to the read operation command when its own identifier is the same as any of the participation identifiers, includes: S231, specifically as follows.
[0099] S231, the matching slave device listens to and identifies the participation identifiers sent by the master device in a set order. When its own identifier is the same as the identified participation identifier, it confirms that it is the participating slave device corresponding to the read operation command, and sends an acknowledgment signal to the master device through the I2C bus so that the master device can continue to send the next participation identifier.
[0100] Building upon the preceding information, this embodiment of the invention also provides an optional implementation method for the content in S25, as detailed below. S25: When the participating slave device detects the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier sent by the master device, it feeds back the target data to the master device according to the order of its own identifier among the N participating identifiers. This includes: S25A, which is specifically described below.
[0101] S25A: The participating slave device counts the total length of the target data returned by all participating slave devices in this I2C transaction. When the total length matches the sorting of its own identifier among the N participating identifiers, it returns the corresponding target data to the master device.
[0102] Specifically, when the total length is equal to the sum of the target lengths of each of the first-class devices, the total length is determined to match the order of its own identifier among the N participating identifiers. The first-class devices are the other slave devices whose order among the N participating identifiers is before the participating slave devices.
[0103] It should be noted that each participating device needs to release its SDA after completing the target data feedback.
[0104] This invention also provides a master-slave device read 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 read operation communication method provided in this embodiment of the invention. The slave device read operation communication method includes S31-S34 and S51-S54, which are described in detail below.
[0105] S31, when the master device needs to read data from the slave device, it sends a start bit.
[0106] S51: When the slave device receives the start bit sent by the master device, it enters the listening and parsing state.
[0107] S32, the master device sends the shared address and write bit identifier corresponding to the current read operation.
[0108] S52: When a slave device detects a shared address that is the same as its own address, it confirms that the slave device is the matching slave device corresponding to the shared address.
[0109] S33, the master device sequentially sends a read operation command, N participation identifiers and the read address.
[0110] S53 matches the read operation command, N participation identifiers and read address sent by the master device to the slave device. When its own identifier is the same as any of the participation identifiers, it is determined to be the participating slave device corresponding to the read operation command, and its corresponding read address is obtained and cached.
[0111] S34, the master device sends the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier.
[0112] S54: When a participating slave device hears the repeat start bit, the shared address corresponding to the current read operation, and the read bit identifier sent by the master device, it feeds back the target data to the master device according to the order of its own identifier among the N participating identifiers.
[0113] The target data refers to the data corresponding to the address read from the device.
[0114] It should be noted that the master-slave device read operation communication method applied to the communication system can include the content of the master-slave device read operation communication method applied to both the master device and the slave device, which will not be elaborated here.
[0115] The following is an example of a read operation for master-slave devices. Assume the read operation command is a first type of read operation command C=0x80, the number of participating slave devices N=2, the identifier set uses an ID list, ID list=[0x04,0x05], all participating slave devices have the same write address reg, reg=0x20, and the target length L=9.
[0116] After the master device sends the repeat start bit and read bit flag, it reads 18 bytes of target data. Among them, the slave device 0x04 reads 9 bytes of data starting from reg=0x20 as its corresponding target data and feeds it back to the master device. Then the slave device 0x05 reads 9 bytes of data starting from reg=0x20 as its corresponding target data and feeds it back to the master device.
[0117] In summary, the master-slave device read operation communication method and system provided by this invention involves the master device sending a shared address and write bit identifier corresponding to the current read operation after sending a start bit, and then sequentially sending a read operation command, N participation identifiers, and a read address; enabling participating slave devices to acquire and cache their corresponding read addresses; the master device then sends a repeat start bit, the shared address corresponding to the current read operation, and a read bit identifier; enabling participating slave devices to feed back target data to the master device according to the order of their own identifiers among the N participation identifiers. Multiple slave devices can share a single address, distinguished by identifiers (e.g., IDs), avoiding address resource waste and increasing the maximum number of deployable slave devices. Furthermore, within a single I2C transaction, read data can be sent in blocks based on the order of participation identifiers, reducing bus occupancy and latency compared to each slave device requiring an I2C transaction for reading data, thus improving communication efficiency. Moreover, by adjusting the identifier order, the participation order and arbitrary combinations of slave devices can be dynamically specified, avoiding fixed bit strings or mapping dependencies, making the implementation more flexible and eliminating the need for additional mechanisms such as mapping tables, thus avoiding increased hardware complexity and power consumption of slave devices.
[0118] 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.
[0119] 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 read operation communication method characterized by comprising: 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 read operation and a write bit identifier, and sequentially sends a read operation command, N participation identifiers and a read address, so that the participating slave devices obtain and cache the read address corresponding thereto, wherein the participating slave devices are slave devices whose own address matches the shared address and whose own identifier is the same as at least one participation identifier; The master device sends a repeated start bit, a shared address corresponding to a current read operation and a read bit identifier, so that the participating slave devices feed back target data to the master device according to the order of their own identifier in the N participation identifiers, wherein the target data is the data corresponding to the read address in the participating slave devices.
2. The master-slave device read operation communication method of claim 1, wherein, When the read operation command sent by the master device is a first type of read operation command, the target length corresponding to all participating slave devices is the same, and the target length matches the content of the first type of read operation command, wherein the target length is the length of the target data fed back by the participating slave devices to the master device.
3. The master-slave device read operation communication method of claim 2, wherein, The first type of read operation command is any one of 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 and 0x70, and the target length is the value of the lower 3 bits after the first type of read operation command is divided by 16.
4. The master-slave device read operation communication method of claim 1, wherein, When the read operation command sent by the master device is a second type of read operation command, after the master device sends the read address, the method further comprises the following steps: The master device sends a target length for all participating slave devices to identify.
5. The master-slave device read operation communication method of claim 1, wherein, When the read operation command sent by the master device is a third type of read operation command, after the master device sends the read address, the method further comprises the following steps: The master device sends the target length corresponding to the participating slave devices in the order of the arrangement of the N participation identifiers, so that each participating slave device obtains the target length corresponding thereto according to the order of its own identifier in the N participation identifiers.
6. The master-slave device read operation communication method according to any one of claims 1 to 5, wherein When the read addresses corresponding to any two participating slave devices are different, the master device sends the read address, comprising the following steps: The master device sends the read address corresponding to each participating slave device in the order of the arrangement of the N participation identifiers, so that each participating slave device obtains the read address corresponding thereto according to the order of its own identifier in the N participation identifiers.
7. The master-slave device read operation communication method according to any one of claims 1 to 5, wherein The master device sends N participation identifiers, comprising the following steps: The master device sends the participation identifiers in a set order, and sends the next participation identifier after each time of sending the participation identifier and receiving the confirmation signal fed back by the slave device, so that the slave device confirms that it is the participating slave device corresponding to the read operation command when its own address matches the shared address and its own identifier is the same as the participation identifier.
8. A master-slave device read 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 obtaining the start bit sent by the master device; The slave device confirms that it is the matching slave device corresponding to the shared address when the shared address listened to is the same as its own address; The matching slave device listens to a read operation command, N participant identifiers and a read address sent by the master device, and determines that it is a participant slave device corresponding to the read operation command when its own identifier is the same as any participant identifier, and acquires and caches the corresponding read address; The participant slave device feeds back target data to the master device according to the ordering of its own identifier in the N participant identifiers when it listens to the repeated start bit, the shared address corresponding to the current read operation and the read bit identifier sent by the master device, wherein the target data is the data corresponding to the read address of the participant slave device.
9. The master-slave device read operation communication method of claim 8, wherein, When the read operation command is a first type of read operation command, the method further comprises: The participant slave device identifies the content of the first type of read operation command, and determines the corresponding target length according to the content of the first type of read operation command.
10. The master-slave device read operation communication method of claim 9, wherein, The first type of read operation command is any one of 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 and 0x70, and the target length is the value of the low 3 bits after the first type of read operation command is divided by 16.
11. The master-slave device read operation communication method of claim 8, wherein, When the read operation command is a second type of read operation command, the method further comprises: The participant slave device listens to and identifies the target length sent by the master device, and the master device sends the target length before sending the repeated start bit.
12. The master-slave device read operation communication method of claim 8, wherein, When the read operation command is a third type of read operation command, the method further comprises: The participant slave device listens to and identifies N target lengths on the I2C bus, and acquires the corresponding target length according to the ordering of its own identifier in the N participant identifiers; Wherein, the N target lengths are N target lengths sent by the master device in the order of arrangement of the N participant identifiers.
13. The master-slave device read operation communication method according to any one of claims 8 to 12, wherein The method further comprises: The participant slave device listens to and identifies N read addresses on the I2C bus, and acquires the corresponding read address according to the ordering of its own identifier in the N participant identifiers; Wherein, the N read addresses are N read addresses sent by the master device in the order of arrangement of the N participant identifiers when the read addresses corresponding to any two participant slave devices are different.
14. The master-slave device read operation communication method according to any one of claims 8 to 12, wherein The matching slave device listens to a read operation command, N participant identifiers and a read address sent by the master device, and determines that it is a participant slave device corresponding to the read operation command when its own identifier is the same as any participant identifier, including: The matching slave device listens to and identifies the participant identifiers sent by the master device in the set order, and confirms that it is the participant slave device corresponding to the read operation command when its own identifier is the same as the identified participant identifier, and feeds back a confirmation signal to the master device through the I2C bus, so that the master device continues to send the next participant identifier.
15. The master-slave device read operation communication method according to any one of claims 8 to 12, wherein The participant slave device feeds back target data to the master device according to the ordering of its own identifier in the N participant identifiers, including: The participant slave device counts the total length of the target data fed back by all participant slave devices in this I2C transaction, and feeds back the corresponding target data to the master device when the total length matches the ordering of its own identifier in the N participant identifiers; Wherein, when the total length is equal to the sum of the target lengths of each first type device, the total length is determined to match its own identification in the order of N participating identifications, and the first type device is other slave device whose order in the N participating identifications is before the participating slave device.
16. A master-slave device read 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 is connected with the plurality of slave devices through an I2C bus, and the method comprises the following steps: The master device sends a start bit when reading data in the slave device is needed; The slave device enters a listening and parsing state when the start bit sent by the master device is acquired; The master device sends a shared address corresponding to a current read operation and a write bit identification; The slave device confirms that it is the matching slave device corresponding to the shared address when the shared address listened to is the same as its own address; The master device sends a read operation command, N participating identifications and a read address in sequence; The matching slave device listens to the read operation command, N participating identifications and the read address sent by the master device, and determines that it is the participating slave device corresponding to the read operation command when its own identification is the same as any participating identification, acquires and caches the read address corresponding thereto; The master device sends a repeated start bit, a shared address corresponding to a current read operation and a read bit identification; The participating slave device feeds back target data to the master device according to the order of its own identification in the N participating identifications when the repeated start bit, the shared address corresponding to the current read operation and the read bit identification sent by the master device are listened to. The target data is the data corresponding to the read address in the participating slave device.
17. A master-slave device read operation communication system, characterized by, The communication system comprises a master device and a plurality of slave devices, the master device is connected with the plurality of slave devices through an I2C bus; The master device is used for sending a start bit when reading data in the slave device is needed; The slave device is used for entering a listening and parsing state when the start bit sent by the master device is acquired; The master device is used for sending a shared address corresponding to a current read operation and a write bit identification; The slave device is used for confirming that it is the matching slave device corresponding to the shared address when the shared address listened to is the same as its own address; The master device is used for sending a read operation command, N participating identifications and a read address in sequence; The matching slave device is used for listening to the read operation command, N participating identifications and the read address sent by the master device, and determining that it is the participating slave device corresponding to the read operation command when its own identification is the same as any participating identification, acquiring and caching the read address corresponding thereto; The master device is used for sending a repeated start bit, a shared address corresponding to a current read operation and a read bit identification; The participating slave device is used for feeding back target data to the master device according to the order of its own identification in the N participating identifications when the repeated start bit, the shared address corresponding to the current read operation and the read bit identification sent by the master device are listened to. The target data is the data corresponding to the read address in the participating slave device.
Citation Information
Patent Citations
Memory system in which extended function can easily be set
CN103403803A
I2C (Inter-Integrated Circuit) bus address conflict preventable communication device
CN103793352A
Command processing method and device, computer equipment and storage medium
CN118642999A
Method, system and equipment for reading and writing data based on I2C (Inter-Integrated Circuit) bus
CN119513009A
Master-slave device write operation communication method and communication system
CN121614431A