Communication method and device adopting 1-WIRE bus
By adjusting the high-level proportion of data to be sent in 1-WIRE bus communication, the problem of power outage of slave devices is solved, ensuring the stability and continuity of communication.
Patent Information
- Application Number
- CN202411255624.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-12-13
AI Technical Summary
When using the 1-WIRE bus for data transmission, if the built-in capacitor of the slave device is insufficient and the low-level discharge is greater than the high-level charging, it may cause the slave device to lose power, communication interruption and status reset.
According to the situation where 0 and 1 are written in the data to be sent, the host adjusts the high-level proportion of the data to be sent through preset rules to generate the target data to be sent to avoid power loss from the slave device. The method includes inversely writing 0 and writing 1 in the valid data set, inserting a high level, or inserting a preset high level with continuous writing 0 to ensure the charge and discharge balance of the slave device.
It effectively avoids power outage of slave devices, prevents communication interruption and status reset between the host and slave devices, and ensures the continuity and stability of communication.
Smart Images

Figure CN119127772A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer communication technology, and in particular to a communication method and device using a 1-WIRE bus. Background Art
[0002] With the development of technology and economy, computers are becoming more and more popular in people's social life, and their application fields are becoming more and more extensive. Generally, a computer includes a host and a slave device. Among them, the host includes core components such as the central processing unit, memory, and hard disk, and completes most of the computer's calculations. The slave device communicates with the host through various buses to assist the host in completing computing tasks such as input, output, network connection, and encryption.
[0003] According to the bus type, the bus can be divided into single bus, dual bus and multi-bus. Among them, since the single bus has only one signal line, it has the advantages of fewer connecting lines, low cost and simple hardware design. At the same time, the single bus also supports one master and multiple slaves (that is, multiple slave devices are connected to one host). These advantages make the single bus widely used in the communication between slave devices such as sensors and security chips and hosts.
[0004] At present, a single bus that has been widely used is the 1-WIRE (one wire serial communication) bus. The 1-WIRE bus is an asynchronous half-duplex serial transmission bus that supports a one-master-multiple-slave system. Among them, the single bus signals transmitted between the host and the slave device using the 1-WIRE bus communication include: reset pulse, presence pulse, write 0, write 1, read 0 and read 1. Specifically, the host and the slave device are initialized by reset pulse and presence pulse, and then data is transmitted by write 0, write 1, read 0 and read 1. In particular, in the process of data transmission using the 1-WIRE bus, the signal line is used not only for data transmission, but also for powering the slave device. Specifically, when the signal line is at a high level, the slave device is charged; when the signal line is at a low level, the slave device is discharged.
[0005] Unfortunately, the inventors discovered during the process of implementing the present invention that, during data transmission using the 1-WIRE bus, if the low-level discharge is greater than the high-level charge (such as the presence of multiple consecutive write-0 processes), if the capacity of the built-in capacitor of the slave device is insufficient, it is possible that the built-in capacitor of the slave device will be completely discharged, thereby causing the slave device to lose power, communication interruption, and slave device status reset. Summary of the invention
[0006] The embodiments of the present invention aim to solve one of the technical problems in the related art at least to a certain extent.
[0007] To this end, an embodiment of the present invention discloses a communication method and device using a 1-WIRE bus. When the host determines that a slave device will lose power based on the situation of writing 0 and 1 in the data to be sent, the host adjusts the proportion of high levels in the data to be sent to avoid power failure of the slave device.
[0008] In a first aspect, an embodiment of the present invention provides a communication method using a 1-WIRE bus, which is applied to a host and a slave device using the 1-WIRE bus for communication, and the method includes: When the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to the preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power; wherein the target data to be sent includes a valid indication bit, and the valid indication bit is used to indicate that the target data to be sent is obtained by the host adjusting the data to be sent according to the preset rule; The host sends the target data to be sent to the slave device; The slave device receives the target data to be sent, and restores the target data to be sent to the data to be sent according to the preset rule.
[0009] In a specific embodiment of the first aspect, the data to be sent includes: N valid data groups, N≥1; when the host determines that the slave device will be powered off according to the situation of writing 0 and writing 1 in the data to be sent, the high level ratio in the data to be sent is adjusted according to a preset rule to obtain the target data to be sent, so as to avoid the power off of the slave device, including: When the host writes 0s at a ratio greater than a first preset ratio in any valid data group, it is determined that the slave device will lose power, and the writes 0s and writes 1s in the valid data group are inverted to avoid power loss of the slave device; wherein the valid indication bit is placed in the inverted valid data group.
[0010] In a specific embodiment of the first aspect, when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent to avoid power failure of the slave device, and further includes: When the number of 0s written continuously by the host in two adjacent valid data groups is greater than a first number, it is determined that the slave device will be powered off, and a first preset high level is inserted between the two valid data groups to avoid power off of the slave device.
[0011] In a specific embodiment of the first aspect, when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent to avoid power failure of the slave device, and further includes: When the host writes 0s continuously for a number greater than a second number in any valid data group, it determines that the slave device will be powered off, and inserts a second preset high level at the position where the number of consecutive 0s written in the valid data group is equal to the second number to avoid power off of the slave device.
[0012] In a specific embodiment of the first aspect, when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent to avoid power failure of the slave device, and further includes: When the host has a write-0 ratio in M consecutive valid data groups that is greater than a second preset ratio and less than a first preset ratio, it is determined that the slave device will lose power, and all or part of the write-0s and write-1s in the M consecutive valid data groups are inverted to avoid power loss of the slave device; wherein the valid indication bit is placed in a valid data group equal to the inverted bit.
[0013] In a specific embodiment of the first aspect, the method further includes: When the write-0 ratio of the host in any valid data group is less than or equal to a first preset ratio, it is determined that the slave device is not powered off, and an invalid indication bit is placed in the valid data group.
[0014] In a specific embodiment of the first aspect, the valid indication bit is placed at the first or last bit of each valid data group, and the invalid indication bit is placed at the first or last bit of each valid data group.
[0015] In a specific embodiment of the first aspect, when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent to avoid power failure of the slave device, and further includes: The host sequentially counts the charge and discharge conditions of each valid data group in the data to be sent, and when the statistical result of the charge and discharge conditions indicates that the power consumption is greater than or equal to the first power threshold, inserts a third preset high level to avoid power failure of the slave device.
[0016] In a specific embodiment of the first aspect, when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, adjusting the high level ratio in the data to be sent according to a preset rule to obtain target data to be sent to avoid power failure of the slave device, including: When the host determines that the slave device will be powered off based on the situations of writing 0 and writing 1 in the data to be sent, the host inserts a fourth preset high level into the data to be sent to avoid the slave device from being powered off.
[0017] In a specific embodiment of the first aspect, the data to be sent includes: N valid data groups, N≥1; the method further includes: When the host determines that there are continuous repeated valid data groups in the data to be sent, one of the repeated valid data groups is retained, a repeat indication signal is inserted, and the remaining repeated valid data groups are replaced by write 1; When receiving the repeat indication signal, the slave device restores the replaced valid data group according to the retained valid data group.
[0018] In a second aspect, an embodiment of the present invention further discloses a communication device using a 1-WIRE bus, which is applied to a host and a slave device using the 1-WIRE bus for communication, and the device comprises: an adjustment module and a sending module located in the host, and a receiving module and a recovery module located in the slave device; The adjustment module is used to determine that when the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, adjust the high level ratio in the data to be sent according to the preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power; wherein the target data to be sent includes a valid indication bit, and the valid indication bit is used to indicate that the target data to be sent is obtained by the host adjusting the data to be sent according to the preset rule; The sending module is used to send the target data to be sent to the slave device; The receiving module is used to receive the target data to be sent; The recovery module is used to restore the target data to be sent to the data to be sent according to the preset rule.
[0019] In a specific embodiment of the second aspect, the data to be sent includes: N valid data groups, N≥1; and the adjustment module is specifically configured to: When the write 0 ratio in any valid data group is greater than a first preset ratio, it is determined that the slave device will lose power, and the write 0 and write 1 in the valid data group are inverted to avoid power loss of the slave device; wherein the valid indication bit is placed in the inverted valid data group.
[0020] In a specific embodiment of the second aspect, the adjustment module is further used to: When the number of consecutively written 0s in two adjacent valid data groups is greater than a first number, it is determined that the slave device will be powered off, and a first preset high level is inserted between the two valid data groups to avoid power off of the slave device.
[0021] In a specific embodiment of the second aspect, the adjustment module is further used to: When the number of consecutively written 0s in any valid data group is greater than a second number, it is determined that the slave device will be powered off, and a second preset high level is inserted at the position where the number of consecutively written 0s in the valid data group is equal to the second number to avoid power off of the slave device.
[0022] In a specific embodiment of the second aspect, the adjustment module is further used to: When the write-0 ratio in M consecutive valid data groups is greater than the second preset ratio and less than or equal to the first preset ratio, it is determined that the slave device will lose power, and all or part of the write-0s and write-1s in the M consecutive valid data groups are inverted to avoid power loss of the slave device; wherein the valid indication bit is placed in the valid data group equal to the inverted one.
[0023] In a specific embodiment of the second aspect, the adjustment module is further used to: When the write-0 ratio in any valid data group is less than or equal to the first preset ratio, it is determined that the slave device is not powered off, and an invalid indication bit is placed in the valid data group.
[0024] In a specific embodiment of the second aspect, the valid indication bit is placed at the first or last bit of each valid data group, and the invalid indication bit is placed at the first or last bit of each valid data group.
[0025] In a specific embodiment of the second aspect, the adjustment module is further used to: The charging and discharging conditions of each valid data group in the data to be sent are counted in sequence, and when the statistical results of the charging and discharging conditions indicate that the power consumption is greater than or equal to the first power threshold, a third preset high level is inserted to avoid power failure of the slave device.
[0026] In a specific embodiment of the second aspect, the adjustment module is used to: When it is determined that the slave device will be powered off according to the situation of writing 0 and writing 1 in the data to be sent, a fourth preset high level is inserted into the data to be sent to avoid the slave device from being powered off.
[0027] In a specific embodiment of the second aspect, the data to be sent includes: N valid data groups, N≥1; and the adjustment module is further used to: When it is determined that there are continuous repeated valid data groups in the data to be sent, one of the repeated valid data groups is retained, a repeat indication signal is inserted, and the remaining repeated valid data groups are replaced by writing 1; The recovery module is also used for: When the repeat indication signal is received, the replaced valid data group is restored according to the retained valid data group.
[0028] Beneficial effects of the embodiments of the present invention: The embodiment of the present invention provides a communication method and device using a 1-WIRE bus, which is applied to a host and a slave device using the 1-WIRE bus for communication. The method includes: when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the high level ratio in the data to be sent is adjusted according to a preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power; the host sends the target data to be sent to the slave device; the slave device receives the target data to be sent, and restores the target data to be sent to the data to be sent according to the preset rule. The technical solution of the embodiment of the present invention is that when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the high level ratio in the data to be sent is adjusted, thereby adjusting the charging and discharging situation of the slave device in advance, avoiding the slave device from losing power, and further avoiding the interruption of communication between the host and the slave device and the reset of the slave device state. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A schematic diagram of the structure of a one-master-one-slave system provided by an embodiment of the present invention; Figure 2 A flow chart of a communication method using a 1-WIRE bus provided in an embodiment of the present invention; Figure 3 A schematic diagram of the structure of a communication device using a 1-WIRE bus provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0030] In order to more clearly understand the above-mentioned purposes, features and advantages of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the technical concept of the embodiments of the present invention belong to the scope of protection of the present invention.
[0031] Referring to the background technology, for a host and a slave device that utilize the 1-WIRE bus for data transmission, if the capacity of the built-in capacitor of the slave device is insufficient and the low-level discharge is greater than the high-level charging (such as the presence of multiple consecutive write-0 processes), it is possible that the built-in capacitor of the slave device will be completely discharged, causing the slave device to lose power, communication interruption, and slave device status reset.
[0032] Furthermore, the inventors discovered during the process of implementing the present invention that in the prior art, the complete discharge of the built-in capacitor of the slave device usually occurs when the host sends data to the slave device. To this end, an embodiment of the present invention provides a communication method and apparatus using a 1-WIRE bus. When the host determines that the slave device will lose power based on the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the proportion of high levels in the data to be sent, thereby adjusting the charging and discharging conditions of the slave device in advance to avoid power failure of the slave device, thereby avoiding communication interruption between the host and the slave device and resetting the status of the slave device.
[0033] Furthermore, before describing the embodiment of the present invention in more detail, the application scenarios of the embodiment of the present invention are first exemplified so as to have a more intuitive understanding of the technical solution of the embodiment of the present invention. One possible scenario is that the host is a vehicle-mounted controller, and the slave device is configured with a security chip that provides security services such as encryption and signature, and the vehicle-mounted controller and the slave device are connected via a 1-WIRE bus communication. Another possible application scenario is a smart home system, in which the main controller acts as the host and connects multiple slave devices such as temperature sensors and lighting equipment via a 1-WIRE bus. It should be noted that this is only an illustrative description of the application scenarios of the embodiment of the present invention, and the embodiment of the present invention is not limited to the aforementioned application scenarios.
[0034] After exemplarily describing the application scenarios of the embodiments of the present invention, the technical solution itself will be described in conjunction with the accompanying drawings.
[0035] For ease of understanding, here we first explain the principle of the host powering the slave device. Figure 1 , which is a schematic diagram of the structure of a one-master-one-slave system provided by an embodiment of the present invention. Figure 1 The system shown includes a host 10 and a slave device 11 .
[0036] See also Figure 1As shown, in addition to providing power to the host 10, the host power supply VCC is connected to the 1-WIRE bus between the host 10 and the slave device 11 through a pull-up resistor R. When the host 10 writes 1 to the 1-WIRE bus, the 1-WIRE bus is pulled to a high level by the pull-up resistor R, and the host power supply VCC charges the built-in capacitor C of the slave device through the diode D in the slave device 11; when the host 10 writes 0 to the 1-WIRE bus, the 1-WIRE bus is pulled to a low level, the diode D is cut off, and the built-in capacitor C acts as the power supply of the slave device 11 to provide power to the slave device 11. It can be seen that if the host 10 continues to write 0 to the 1-WIRE bus, or the proportion of writing 0 is large, the built-in capacitor C may be completely discharged. Based on this, an embodiment of the present invention provides a communication method and device using a 1-WIRE bus.
[0037] See also Figure 2 FIG. 1 is a flow chart of a communication method using 1-WIRE bus provided by an embodiment of the present invention. The communication method is applied to a host and a slave device using 1-WIRE bus communication.
[0038] It should be noted that before performing the communication method using the 1-WIRE bus of the embodiment of the present invention, that is, before data is transmitted between the host and the slave device, the host and the slave device need to complete initialization through a reset pulse and a presence pulse. The specific initialization process can be found in the existing technology and will not be repeated here.
[0039] In addition, for the working condition of one master and multiple slaves (i.e., one host is connected to multiple slave devices), the host can complete the search operation of all slave devices connected to the host through a search algorithm such as a binary tree algorithm, and then use the unique identifier to select the corresponding slave device. In practical applications, the unique identifier of each slave device can be a ROM code set before the slave device leaves the factory. Among them, the length of the ROM code is defined by the manufacturer according to actual needs, for example, it can be 32 bits, 64 bits, etc. Of course, the embodiment of the present invention can also be applied to the working condition of one master and one slave.
[0040] Continue to see Figure 2 As shown, the communication method using the 1-WIRE bus provided in the embodiment of the present invention may include: In step S210, when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to the preset rule to obtain the target data to be sent to avoid power failure of the slave device.
[0041] Specifically, writing 0 in the data to be sent can reflect the expected power consumption of the slave device, and writing 1 in the data to be sent can reflect the expected charge amount of the slave device. The expected power consumption and the expected charge amount together reflect the charge and discharge situation of the slave device. Therefore, the host can deduce whether the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, that is, whether the built-in capacitor of the slave device will be completely discharged. When the host determines that if the data to be sent is sent directly, the slave device will lose power, the high level ratio in the data to be sent is adjusted according to the preset rules to obtain the target data to be sent, so as to avoid power failure of the slave device. Among them, the preset rules can be set in advance in the host and the slave device, or can be determined by negotiation between the host and the slave device. The preset rules should ensure that the high level ratio in the target data to be sent is higher than the high level ratio in the data to be sent, and can ensure that when the host sends the target data to be sent to the slave device, there will be no power failure. The reference factors for the formulation of the preset rules include the power consumption of the slave device, the size of the built-in capacitor, etc. In general, the preset rules may include: inverting the writing 0 and writing 1 in the data to be sent, inserting part or all of the high level in the data to be sent.
[0042] The target data to be sent includes a valid indication bit, which is used to indicate that the target data to be sent is obtained by adjusting the data to be sent by the host according to a preset rule, so that the slave device can recognize that the target data to be sent is obtained after the adjustment of the data to be sent. In practical applications, the valid indication bit is an indication mark agreed upon between the host and the slave device, and the specific form of expression can be a standard write 1 or write 0 signal, or a high-level signal different from write 1, or a low-level signal different from write 0, whichever is the recognition of the slave device.
[0043] In step S220, the host sends the target data to be sent to the slave device.
[0044] Specifically, the host sends the target data to be sent to the slave device through the 1-WIRE bus.
[0045] In step S230, the target data to be sent is received from the device, and the target data to be sent is restored to the data to be sent according to a preset rule.
[0046] Specifically, after receiving the target data to be sent, the slave device identifies a valid indication bit in the target data to be sent, and then restores the target data to be sent to the data to be sent according to a preset rule.
[0047] A communication method using a 1-WIRE bus provided by an embodiment of the present invention is applied to a host and a slave device using a 1-WIRE bus for communication, and the method includes: when the host determines that a slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent, so as to avoid power failure of the slave device; the target data to be sent includes a valid indication bit, and the valid indication bit is used to indicate that the target data to be sent is obtained by the host adjusting the data to be sent according to the preset rule; the host sends the target data to be sent to the slave device; the slave device receives the target data to be sent, and restores the target data to be sent to the data to be sent according to the preset rule. The technical solution of the embodiment of the present invention is that when the host determines that a slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent, thereby adjusting the charging and discharging situation of the slave device, so as to avoid power failure of the slave device, thereby avoiding communication interruption between the host and the slave device and resetting the state of the slave device.
[0048] Furthermore, in some embodiments, the host may divide the data to be sent into valid data groups, and send the data to the slave device in the form of valid data groups. For example, if a valid data group is 8 bits and the data to be sent is 30 bytes, the data to be sent may be divided into 30 valid data groups. It should be noted that in actual applications, a valid data group may also be 7 bits, 16 bits, 32 bits, etc. The length of a valid data group is determined comprehensively based on data requirements, memory space, time efficiency, etc., and generally an empirical value may be taken. It is obvious that the number of valid data groups included in each data to be sent is related to the length of the data to be sent and the length of the valid data group itself, and the data to be sent may include one or more valid data groups.
[0049] For the case where the data to be sent is divided into valid data groups, in some implementations of the embodiments of the present invention, the data to be sent includes: N valid data groups, N≥1. Accordingly, step S210 may include: When the host writes 0s in any valid data group at a ratio greater than a first preset ratio, it is determined that the slave device will be powered off, and the writes 0s and writes 1s in the valid data group are inverted to avoid power off of the slave device.
[0050] Specifically, when the host determines that the slave device will lose power, the host changes the write 0 to the write 1, and changes the write 1 to the write 0.
[0051] Among them, the first preset ratio is comprehensively determined based on the power consumption and built-in capacitor size of the slave device, and the determination standard is that when the write 0 ratio in the valid data group is equal to the first preset ratio, the slave device cannot be powered off, and the ratio of the slave device power-off boundary should be close to the first preset ratio to avoid adjusting the frequency of the data to be sent too high. For example, the first preset ratio is equal to 60%, and of course in other examples, the first preset ratio is equal to 80%. The valid indication bit is placed in the valid data group after negation. Taking the valid data group as 8 bits and the valid indication bit as write 1 as an example, the valid indication bit can be placed in the first bit of the valid data group after negation, or the last bit, and the data group corresponding to the valid data group sent to the slave device is 9 bits. It is obvious that in this embodiment, the position of the negation and the valid indication bit belongs to the preset rules.
[0052] It should be noted that valid data groups with a write-0 ratio less than or equal to the first preset ratio may not be processed, or other rules may be formulated for processing, and the modified and unmodified valid data groups in the data to be sent together constitute the target data to be sent.
[0053] In this specific implementation, by inverting write 0 and write 1 in a valid data group whose write 0 ratio is greater than a first preset ratio, the proportion of high level in the data to be sent is increased to avoid power failure of the slave device.
[0054] Further, considering the consistency of the lengths of the modified and unmodified valid data groups in the data to be sent, in some implementations of the embodiments of the present invention, the communication method using the 1-WIRE bus of the embodiments of the present invention may further include: When the proportion of zeros written by the host in any valid data group is less than or equal to a first preset proportion, it is determined that the slave device is not powered off, and an invalid indication bit is placed in the valid data group.
[0055] Generally, in order to ensure the consistency of the length of the modified and unmodified valid data groups, the length of the valid indication bit and the invalid indication bit should be consistent. Taking the valid data group as 8 bits and the invalid indication bit as written 0 as an example, the invalid indication bit can be placed at the first bit of the valid data group, or the last bit, and the data group corresponding to the valid data group sent to the slave device is 9 bits. It is obvious that in this embodiment, the position of the invalid indication bit also belongs to the preset rule. Generally, the positions of the valid indication bit and the invalid indication bit correspond, for example, the valid indication bit and the invalid indication bit are both placed at the last bit of the valid data group.
[0056] In this specific implementation, the lengths of the modified and unmodified valid data groups are made consistent, so that the data groups sent by the host to the slave device have high consistency and the implementation logic is simple.
[0057] It is understandable that in some other implementations, the valid data group whose write-0 ratio is less than or equal to the first preset ratio may not be processed.
[0058] Furthermore, considering that writing 0s in two adjacent valid data groups may be continuous, it will also cause the slave device to power off. For example, taking the valid data group as 8 bits and the first preset ratio as 60%, the first valid data group is "11110000" and the second data group is "00001111". Although the writing 0 ratios in the two valid data groups are both less than 60%, the continuous transmission of these two valid data groups will result in 8 consecutive writing 0s, which will also cause the slave device to power off. To this end, in some implementations of the embodiments of the present invention, step S210 may also include: When the number of 0s written continuously by the host in two adjacent valid data groups is greater than a first number, it is determined that the slave device will be powered off, and a first preset high level is inserted between the two valid data groups to avoid power off of the slave device.
[0059] Among them, the first number is determined comprehensively based on the power consumption and built-in capacitor size of the slave device, and the determination standard is that when the number of consecutive write 0s in two adjacent valid data groups is equal to the first number, the slave device cannot be powered off, and the number of consecutive write 0s at the power-off boundary of the slave device should be close to the first number to avoid adjusting the frequency of the data to be sent too high and increase unnecessary power consumption. The first preset high level is a continuous high level signal, and the duration should be long enough to ensure that the slave device no longer powers off. Considerations include the size of the built-in capacitor of the slave device, and energy-saving factors should also be taken into account, and the duration should not be too long. Generally, the duration of the first preset high level can be obtained by calibration or experimental measurement. Obviously, in this embodiment, the first preset high level belongs to the preset rule.
[0060] It should be noted that due to the different power consumption and built-in capacitor sizes of different slave devices, in some slave devices, the requirement of not losing power at any time can be met by simply inverting the valid data group whose write-0 ratio is greater than the first preset ratio. At this time, there is no need to determine whether the number of consecutive write-0s in two adjacent valid data groups is greater than the first number, and there is no need to insert the first preset high level.
[0061] Furthermore, even if the write-0 ratio in a valid data group is less than or equal to the first preset ratio, continuous write-0 occurs in the valid data group, i.e., continuous and rapid power consumption occurs. When the built-in capacitance of the slave device is small, the slave device may also lose power. Therefore, in some implementations of the embodiments of the present invention, step S210 may further include: When the host writes 0s continuously in any valid data group for a number greater than a second number, it determines that the slave device will be powered off, and inserts a second preset high level at the position where 0s are continuously written equal to the second number in the valid data group to avoid power off of the slave device.
[0062] Among them, the second number is determined comprehensively based on the power consumption and built-in capacitor size of the slave device, and the determination standard is that when the number of consecutive write 0s in the same valid data group is equal to the second number, the slave device cannot be powered off, and the number of consecutive write 0s at the power-off boundary of the slave device should be close to the second number to avoid adjusting the frequency of the data to be sent too high and increase unnecessary power consumption. The second preset high level is a continuous high level signal, and the duration should be long enough to ensure that the slave device no longer powers off. Considerations include the size of the built-in capacitor of the slave device, and energy-saving factors should also be taken into account, and the duration should not be too long. Generally, the duration of the second preset high level can be obtained by calibration or experimental measurement. Obviously, in this embodiment, the second preset high level belongs to the preset rule.
[0063] It should be noted that due to the different power consumption and built-in capacitor sizes of different slave devices, in some slave devices, the requirement of not losing power at any time can be met simply by inverting the valid data group whose write-0 ratio is greater than the first preset ratio. At this time, there is no need to determine whether the number of consecutive write-0s in any valid data group is greater than the second number, and there is no need to insert a second preset high level.
[0064] Furthermore, even if the write-0 ratio in each valid data group is less than or equal to the first preset ratio, the write-0 ratios in multiple consecutive valid data groups are close to the first preset ratio, so that the power of the built-in capacitor is reduced after each valid data group is sent, and the continuous slow discharge causes the built-in capacitor of the slave device to be completely discharged, thereby causing the slave device to power off. Based on this situation, in some implementations of the embodiments of the present invention, step S210 may also include: When the host's write-0 ratio in M consecutive valid data groups is greater than a second preset ratio and less than or equal to a first preset ratio, it is determined that a slave device will lose power, and all or part of the write-0s and write-1s in the M consecutive valid data groups are inverted to avoid power failure of the slave device; wherein the valid indication bit is placed in the inverted valid data group.
[0065] Among them, when the write-0 ratio in the valid data group is equal to the second preset ratio, the host sending the valid data group will cause the built-in capacitor of the slave device to discharge. The specific second preset ratio is related to the power consumption of the slave device and can be obtained through calibration. The number of M is related to the power consumption when the write-0 ratio in the valid data group is greater than the second preset ratio and less than or equal to the first preset ratio and the size of the built-in capacitor of the slave device, which can be obtained through calibration. Which valid data groups in the M valid data groups are specifically negated can be agreed in advance, and this agreement belongs to the preset rule.
[0066] Furthermore, even if the write-0 ratio in each valid data group is less than or equal to the first preset ratio, the superposition effect of charging and discharging in each valid data group may also cause the slave device to lose power. To this end, in some implementations of the present invention, step S210 may further include: The host sequentially counts the charge and discharge status of each valid data group in the data to be sent, and when the statistical results of the charge and discharge status indicate that the power consumption is greater than or equal to the first power threshold, inserts a third preset high level to avoid power failure of the slave device.
[0067] Among them, the first power threshold can be a calibration value, which should ensure that when the host first counts that the power consumption is greater than or equal to the first power threshold, the slave device does not lose power, and the first power threshold should be close to the power-off boundary to avoid adjusting the frequency of the data to be sent too high and increase unnecessary power consumption. The third preset high level is a continuous high level signal, and the duration should be able to ensure that the slave device no longer loses power. Considerations include the size of the built-in capacitor of the slave device. At the same time, energy-saving factors should be taken into account, and the duration cannot be too long. Generally, the duration of the third preset high level can be obtained by calibration or experimental measurement. Obviously, in this embodiment, the third preset high level belongs to the preset rule.
[0068] Optionally, in some implementations of the embodiments of the present invention, step S210 may include: When the host determines that the slave device will be powered off according to the situation of writing 0 and writing 1 in the data to be sent, the host inserts a fourth preset high level into the data to be sent to avoid the slave device from being powered off.
[0069] The fourth preset high level is a continuous high level signal, and the duration should be long enough to ensure that the slave device does not lose power. Considerations include the size of the built-in capacitor of the slave device, and energy saving factors should also be taken into account. The duration should not be too long. Generally, the duration of the fourth preset high level can be obtained by calibration or experimental measurement. Obviously, in this embodiment, the fourth preset high level belongs to the preset rule.
[0070] Furthermore, considering that there may be repeated valid data groups in the data to be sent in actual applications, in order to save data transmission volume and reduce energy consumption in this case, when the data to be sent includes: N valid data groups, N ≥ 1, a communication method using a 1-WIRE bus in an embodiment of the present invention may also include: When the host determines that there are continuous repeated valid data groups in the data to be sent, it retains one of the repeated valid data groups, inserts a repeat indication signal, and replaces the remaining repeated valid data groups with write 1; When receiving the repeat indication signal, the slave device restores the replaced valid data group according to the retained valid data group.
[0071] Specifically, the repeat indication signal is used to indicate that there are continuous repeated valid data groups in the data to be sent. In practical applications, the repeat indication signal is a repeat indication mark agreed upon between the host and the slave device, which can be a high-level signal different from write 1, or a low-level signal different from write 0, whichever can be recognized by the slave device. When the slave device recognizes the repeat indication signal, it takes the previously received valid data group as the retained valid data group, and restores the replaced valid data group according to the number of write 1s.
[0072] It should be noted that the number of replaced valid data groups is usually not equal to the length of the valid data group itself, so the number of replaced valid data groups can be determined according to the number of written 1s. In particular, when the number of replaced valid data groups is equal to the length of the valid data group itself, it can be recorded by a special mark, such as a predetermined high-level signal.
[0073] Corresponding to the above method embodiment, the embodiment of the present invention also discloses a communication device using a 1-WIRE bus, which is applied to a host and a slave device using a 1-WIRE bus for communication. Figure 3 As shown, a communication device using a 1-WIRE bus provided by an embodiment of the present invention may include: an adjustment module 310 and a sending module 320 located in a host, and a receiving module 330 and a recovery module 340 located in a slave device.
[0074] The adjustment module 310 is used to determine that when a slave device will lose power based on the situation of writing 0 and writing 1 in the data to be sent, adjust the high level ratio in the data to be sent according to the preset rules to obtain the target data to be sent, so as to avoid power failure of the slave device; wherein the target data to be sent includes a valid indication bit, and the valid indication bit is used to indicate that the target data to be sent is obtained by the host adjusting the data to be sent according to the preset rules.
[0075] The sending module 320 is used to send the target data to be sent to the slave device; The receiving module 330 is used to receive target data to be sent; The recovery module 340 is used to restore the target data to be sent to the data to be sent according to a preset rule.
[0076] A communication device using a 1-WIRE bus provided in an embodiment of the present invention is applied to a host and a slave device using the 1-WIRE bus for communication, and the device includes: an adjustment module and a sending module located in the host, and a receiving module and a recovery module located in the slave device; the adjustment module is used to determine that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, and adjust the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent, so as to avoid power failure of the slave device; the sending module is used to send the target data to be sent to the slave device; the receiving module is used to receive the target data to be sent; and the recovery module is used to restore the target data to be sent to the data to be sent according to the preset rule. The technical solution of the embodiment of the present invention is that when the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent, thereby adjusting the charging and discharging situation of the slave device in advance, avoiding power failure of the slave device, and further avoiding communication interruption between the host and the slave device and resetting the state of the slave device.
[0077] In some implementations of the embodiments of the present invention, the data to be sent includes: N valid data groups, N≥1; the adjustment module 310 is specifically used to: When the write 0 ratio in any valid data group is greater than the first preset ratio, it is determined that the slave device will lose power, and the write 0 and write 1 in the valid data group are inverted to avoid power failure of the slave device; wherein the valid indication bit is placed in the inverted valid data group.
[0078] In some implementations of the embodiments of the present invention, the adjustment module 310 is further used to: When the number of consecutively written 0s in two adjacent valid data groups is greater than a first number, it is determined that the slave device will be powered off, and a first preset high level is inserted between the two valid data groups to avoid power off of the slave device.
[0079] In some implementations of the embodiments of the present invention, the adjustment module 310 is further used to: When the number of consecutively written 0s in any valid data group is greater than a second number, it is determined that the slave device will be powered off, and a second preset high level is inserted at the position where the number of consecutively written 0s in the valid data group is equal to the second number to avoid power off of the slave device.
[0080] In some implementations of the embodiments of the present invention, the adjustment module 310 is further used to: When the write-0 ratio in M consecutive valid data groups is greater than the second preset ratio and less than the first preset ratio, it is determined that the slave device will lose power, and all or part of the write-0 and write-1 in the M consecutive valid data groups are inverted to avoid power failure of the slave device; wherein the valid indication bit is placed in the valid data group equal to the inverted bit.
[0081] In some implementations of the embodiments of the present invention, the adjustment module 310 is further used to: When the write-0 ratio in any valid data group is less than or equal to the first preset ratio, it is determined that the slave device is not powered off, and an invalid indication bit is placed in the valid data group.
[0082] In some implementations of the embodiments of the present invention, the valid indication bit is placed at the first or last bit of each valid data group, and the invalid indication bit is placed at the first or last bit of each valid data group.
[0083] In some implementations of the embodiments of the present invention, the adjustment module 310 is further used to: The charging and discharging conditions of each valid data group in the data to be sent are counted in sequence, and when the statistical results of the charging and discharging conditions indicate that the power consumption is greater than or equal to the first power threshold, a third preset high level is inserted to avoid power failure of the slave device.
[0084] In some implementations of the embodiments of the present invention, the adjustment module 310 is used to: When it is determined that the slave device will be powered off according to the situation of writing 0 and writing 1 in the data to be sent, a fourth preset high level is inserted into the data to be sent to avoid the slave device from being powered off.
[0085] In some implementations of the embodiments of the present invention, the data to be sent includes: N valid data groups, N≥1; the adjustment module 310 is further used to: When it is determined that there are continuous repeated valid data groups in the data to be sent, one of the repeated valid data groups is retained, a repeat indication signal is inserted, and the remaining repeated valid data groups are replaced by write 1; The recovery module 340 is also used to: When a repeat indication signal is received, the replaced valid data group is restored according to the retained valid data group.
[0086] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions in the embodiments of the present invention are essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the solutions described in each embodiment of the present invention or some parts of the embodiments.
[0087] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can refer to each other. In the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other. Each embodiment focuses on the differences from other embodiments.
[0088] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0089] The above-described embodiments of the present invention do not constitute a limitation on the protection scope of the present invention. Any modification, equivalent replacement and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A communication method using 1-WIRE bus, It is characterized in that Applied to a host and a slave device using 1-WIRE bus communication, the method comprises: When the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to the preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power; wherein the target data to be sent includes a valid indication bit, and the valid indication bit is used to indicate that the target data to be sent is obtained by the host adjusting the data to be sent according to the preset rule; The host sends the target data to be sent to the slave device; The slave device receives the target data to be sent, and restores the target data to be sent to the data to be sent according to the preset rule.
2. The communication method according to claim 1, It is characterized in that The data to be sent includes: N valid data groups, N≥1; the host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, and adjusts the high level ratio in the data to be sent according to a preset rule to obtain target data to be sent, so as to avoid the slave device from losing power, including: When the host writes 0s at a ratio greater than a first preset ratio in any valid data group, it is determined that the slave device will lose power, and the writes 0s and writes 1s in the valid data group are inverted to avoid power loss of the slave device; wherein the valid indication bit is placed in the inverted valid data group.
3. The communication method according to claim 2, It is characterized in that The host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, and adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power, and further includes: When the number of 0s written continuously by the host in two adjacent valid data groups is greater than a first number, it is determined that the slave device will be powered off, and a first preset high level is inserted between the two valid data groups to avoid power off of the slave device.
4. The communication method according to claim 2, It is characterized in that The host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, and adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power, and further includes: When the host writes 0s continuously for a number greater than a second number in any valid data group, it determines that the slave device will be powered off, and inserts a second preset high level at the position where the number of consecutive 0s written in the valid data group is equal to the second number to avoid power off of the slave device.
5. The communication method according to claim 2, It is characterized in that The host determines that the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, and adjusts the high level ratio in the data to be sent according to a preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power, and further includes: When the host's write-0 ratio in M consecutive valid data groups is greater than a second preset ratio and less than or equal to a first preset ratio, it is determined that the slave device will lose power, and all or part of the write-0s and write-1s in the M consecutive valid data groups are inverted to avoid power loss of the slave device; wherein the valid indication bit is placed in a valid data group equal to the inverted one.
6. The communication method according to claim 2, It is characterized in that The method further comprises: When the write-0 ratio of the host in any valid data group is less than or equal to a first preset ratio, it is determined that the slave device is not powered off, and an invalid indication bit is placed in the valid data group.
7. The communication method according to claim 6, It is characterized in that The valid indication bit is placed at the first bit or the last bit of each valid data group, and the invalid indication bit is placed at the first bit or the last bit of each valid data group.
8. The communication method according to claim 1, It is characterized in that The host determines that when the slave device is about to lose power according to the situation of writing 0 and writing 1 in the data to be sent, the host adjusts the high level ratio in the data to be sent according to a preset rule to obtain target data to be sent, so as to avoid the slave device from losing power, including: When the host determines that the slave device will be powered off based on the situations of writing 0 and writing 1 in the data to be sent, the host inserts a fourth preset high level into the data to be sent to avoid the slave device from being powered off.
9. The communication method according to claim 1, It is characterized in that The data to be sent includes: N valid data groups, N≥1; the method also includes: When the host determines that there are continuous repeated valid data groups in the data to be sent, one of the repeated valid data groups is retained, a repeat indication signal is inserted, and the remaining repeated valid data groups are replaced by write 1; When receiving the repeat indication signal, the slave device restores the replaced valid data group according to the retained valid data group.
10. A communication device using a 1-WIRE bus, It is characterized in that Applicable to a host and a slave device using 1-WIRE bus communication, the device comprises: an adjustment module and a sending module located in the host, and a receiving module and a recovery module located in the slave device; The adjustment module is used to determine that when the slave device will lose power according to the situation of writing 0 and writing 1 in the data to be sent, adjust the high level ratio in the data to be sent according to the preset rule to obtain the target data to be sent, so as to avoid the slave device from losing power; wherein the target data to be sent includes a valid indication bit, and the valid indication bit is used to indicate that the target data to be sent is obtained by the host adjusting the data to be sent according to the preset rule; The sending module is used to send the target data to be sent to the slave device; The receiving module is used to receive the target data to be sent; The recovery module is used to restore the target data to be sent to the data to be sent according to the preset rule.
