CN112579509B - Single-wire communication method, single-wire communication device, electronic equipment and readable storage medium - Google Patents
Single-wire communication method, single-wire communication device, electronic equipment and readable storage medium Download PDFInfo
- Publication number
- CN112579509B CN112579509B CN202011475955.4A CN202011475955A CN112579509B CN 112579509 B CN112579509 B CN 112579509B CN 202011475955 A CN202011475955 A CN 202011475955A CN 112579509 B CN112579509 B CN 112579509B
- Authority
- CN
- China
- Prior art keywords
- data packet
- host
- slave
- duration
- bus
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F15/00—Digital computers in general; Data processing equipment in general
- G06F15/16—Combinations of two or more digital computers each having at least an arithmetic unit, a program unit and a register, e.g. for a simultaneous processing of several programs
- G06F15/163—Interprocessor communication
- G06F15/17—Interprocessor communication using an input/output type connection, e.g. channel, I/O port
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/14—Handling requests for interconnection or transfer
- G06F13/20—Handling requests for interconnection or transfer for access to input/output bus
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/40—Bus structure
- G06F13/4004—Coupling between buses
- G06F13/4027—Coupling between buses using bus bridges
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Computer Hardware Design (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Information Transfer Systems (AREA)
- Small-Scale Networks (AREA)
Abstract
The invention relates to the technical field of data communication, and discloses a single-wire communication method, a single-wire communication device, electronic equipment and a readable storage medium. Wherein the method comprises the following steps: the host sets the input/output port thereof to an output state, and sends a first data packet to the slave; when the first data packet is sent, releasing the bus and switching the input/output port of the bus to an input state; the slave receives the first data packet and generates a response data packet corresponding to the first data packet; switching the input/output port of the slave to be in an output state, and sending the response data packet to the host through the bus; when the transmission of the response data packet is completed, the bus is released, and the input/output port of the bus is switched to an input state; the host receives a response data packet corresponding to the first data packet sent by at least one slave. By implementing the invention, the confusion of data transmission is avoided, and the stability of single-wire communication and the accuracy of data receiving are ensured.
Description
Technical Field
The present invention relates to the field of data communication technologies, and in particular, to a single-wire communication method, a single-wire communication device, an electronic device, and a readable storage medium.
Background
The near field communication modes between chips include USART, IIC, SPI, a single bus and the like. However, the USART communication mode and the IIC communication mode require two data lines for data communication transmission; the SPI communication mode needs to use three data lines for data communication transmission, and the communication modes such as USART, IIC and SPI need to use two specific communication ports of a chip, so that more chip port resources are occupied, and the communication cost is high. For the above problems, only one data line is needed based on the single bus communication mode, so that the short-range communication mode between chips mostly adopts the single bus communication mode, but when data communication is performed by using the single bus communication mode, the single bus communication protocol must be strictly adhered to, a delay function (No Operation, NOP) is needed to be used for sending or reading data, delay parameters of each state are set according to communication time sequence, parameter adjustment is complicated and unstable, delay inaccuracy is easy to be caused, and when delay inaccuracy occurs, the situation that both chips occupy buses at the same time to perform data transmission occurs, and data communication between both chips is disordered, so that data communication stability of both chips is poor, and data reception is inaccurate.
Disclosure of Invention
In view of the above, the embodiments of the present invention provide a single-wire communication method, apparatus, electronic device, and readable storage medium, so as to solve the problems of poor data communication stability and inaccurate data reception of both chips in a single-bus communication manner.
According to a first aspect, an embodiment of the present invention provides a single-wire communication method, for a host, where the host is connected to at least one slave through a bus, and the method includes the following steps: setting an input/output port of the host as an output state, and sending a first data packet to the slave; judging whether the first data packet is sent completely or not; when the first data packet is sent, releasing the bus and switching the input/output port of the host to an input state; and receiving a response data packet corresponding to the first data packet sent by at least one slave machine, wherein the response data packet is sent through the released bus.
The single-wire communication method provided by the embodiment of the invention is used for a host, the host is connected with at least one slave computer through a bus, the host sends a first data packet to the slave computer by setting the corresponding input/output port of the host as an output state, and when the first data packet is sent, the bus is released, and the corresponding input/output port of the host is switched to the input state. When the slave receives the first data packet sent by the host, the corresponding response data packet is sent to the host, and the host receives at least one response data packet corresponding to the first data packet sent by the slave, wherein the response data packet is sent through a bus released by the host. The host releases the bus after the host transmits the first data packet, so that the host cannot occupy the bus to transmit the data packet to the slave after the host transmits the first data packet, and the slave can accurately transmit the response data packet to the slave. The method avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
With reference to the first aspect, in a first implementation manner of the first aspect, the setting the input/output port of the host to an output state includes: judging whether the host needs to send a first data packet or not; when the host needs to send the first data packet, the input/output port of the host is switched to the output state.
With reference to the first implementation manner of the first aspect, in a second implementation manner of the first aspect, the setting the input/output port of the host to an output state further includes: when the host does not need to send the first data packet, the input state of the input/output port of the host is maintained.
According to the single-wire communication method provided by the embodiment of the invention, whether the host needs to send the first data packet is judged, and when the host needs to send the first data packet, the input/output port of the host is switched to an output state so as to send the first data packet. When the host computer does not need to send the first data packet, the input state of the input/output port of the host computer is maintained, so that the data communication bus between the host computer and the slave computer is ensured to be in an unoccupied state. The method ensures that the input/output port of the host on the bus at any time is in an output state only when the data packet is sent, and the input/output ports of the host are in an input state at other moments, thereby avoiding data transmission conflicts.
With reference to the first aspect or the first implementation manner or the second implementation manner of the first aspect, in a third implementation manner of the first aspect, after the receiving a response data packet sent by at least one slave machine and corresponding to the first data packet, the method further includes: detecting a first duration of time that the slave releases the bus; judging whether the first duration is longer than a first preset duration or not; when the first duration is longer than the first preset duration, judging whether to continue sending the second data packet or not; and when the second data packet needs to be continuously sent, executing the step of setting the input/output port of the host to be in an output state.
According to the single-wire communication method provided by the embodiment of the invention, by detecting the first duration of the slave release bus, whether the first duration is longer than the first preset duration is judged, and when the first duration is longer than the first preset duration, whether the second data packet needs to be continuously sent is judged; when the second data packet needs to be continuously sent, the input/output port of the host is switched to be in an output state so that the host can continuously send the second data packet to the slave by using the released bus, data transmission conflict is avoided, and stability of data transmission is guaranteed.
With reference to the third implementation manner of the first aspect, in a fourth implementation manner of the first aspect, the method further includes: when the second data packet does not need to be continuously sent, judging whether the first duration is longer than a second preset duration; when the first duration is longer than the second preset duration, judging whether a third data packet needs to be sent or not; and when the third data packet needs to be sent, executing the step of setting the input/output port of the host to an output state.
According to the single-wire communication method provided by the embodiment of the invention, when the second data packet is not required to be continuously transmitted, whether the first duration is longer than the second preset duration is judged, when the first duration is longer than the second preset duration, whether the third data packet is required to be transmitted is judged, when the third data packet is required to be transmitted, the host is indicated to enter new data communication, the input/output port of the host is switched to be in an output state, so that the host can continuously transmit the data packet to the slave by using the released bus, the data transmission conflict is avoided, and the stability of the data transmission is further ensured.
With reference to the first aspect, in a fifth implementation manner of the first aspect, when the number of the hosts is multiple, the input/output ports of the hosts are connected to the bus, and the input/output ports of the multiple slaves are respectively connected to the bus, where the first data packet or the second data packet or the third data packet includes a target slave address.
According to the single-wire communication method provided by the embodiment of the invention, when a plurality of hosts are provided, the input/output ports of the hosts are connected with the bus, the input/output ports of the plurality of slaves are respectively connected with the bus, and the first data packet or the second data packet or the third data packet also comprises the target slave address, so that the accuracy of data transmission between the hosts and the slaves is ensured, and the bus is prevented from being occupied by errors.
According to a second aspect, an embodiment of the present invention provides a single-wire communication method, for a slave, where the slave is connected to a host through a bus, and the method includes the following steps: receiving a first data packet sent by the host through the bus, and generating a response data packet corresponding to the first data packet; switching an input/output port of the slave to be in an output state, and sending the response data packet to the host through the bus; judging whether the sending of the response data packet is completed or not; and when the transmission of the response data packet is completed, releasing the bus and switching the input/output port of the slave to an input state.
The embodiment of the invention provides a single-wire communication method, which is used for a slave machine, wherein the slave machine is connected with a host machine through a bus, the slave machine receives a first data packet sent by the host machine through the bus, generates a response data packet corresponding to the first data packet, switches an input/output port corresponding to the first data packet to be in an output state, sends the response data packet to the host machine through the bus, releases the bus when the response data packet is sent, and switches the input/output port corresponding to the response data packet to be in the input state. The slave releases the bus after the slave transmits the response data packet, so that the slave cannot occupy the bus to transmit other data packets to the slave again after the slave transmits the response data packet, and the host can accurately receive the response data packet transmitted by the slave. The method avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
With reference to the second aspect, in a first implementation manner of the second aspect, the sending the response data packet to the host through the bus includes: detecting a second duration of time that the host releases the bus; judging whether the second duration exceeds a third preset duration; and when the second duration exceeds the third preset duration, generating a response data packet corresponding to the first data packet.
According to the single-wire communication method provided by the embodiment of the invention, whether the second duration exceeds the third preset duration is judged by detecting the second duration of the bus release of the host, and when the second duration exceeds the third preset duration, the slave generates a response data packet corresponding to the first data packet and sends the response data packet. The method ensures that the host does not occupy the bus when the slave sends the response data packet, thereby avoiding the data transmission conflict.
With reference to the second aspect or the first implementation manner of the second aspect, in a second implementation manner of the second aspect, the plurality of slaves are connected to the master through the bus, the first data packet includes a target slave address, and the sending the response data packet to the master through the bus further includes: judging whether the target slave machine address is the same as the physical address of the current slave machine or not; and when the target slave machine address is the same as the physical address of the current slave machine, sending a response data packet corresponding to the first data packet.
According to the single-wire communication method provided by the embodiment of the invention, the plurality of slaves are connected with the host computer through the bus, the first data packet comprises the target slave address, and when the target slave address is the same as the physical address of the current slave, the current slave sends the response data packet corresponding to the first data packet, so that the accuracy of data transmission between the host computer and the slaves is ensured, and the bus is prevented from being occupied by errors.
According to a third aspect, an embodiment of the present invention provides a single-wire communication device for a host, where the host is connected to at least one slave through a bus, and the single-wire communication device includes: the first sending module is used for setting the input/output port of the host to be in an output state and sending a first data packet to the slave; the first judging module is used for judging whether the first data packet is sent completely or not; the first releasing module is used for releasing the bus and switching the input/output port of the host into an input state when the first data packet is sent; and the first receiving module is used for receiving response data packets corresponding to the first data packets and sent by at least one slave machine, and the response data packets are sent through the released buses.
The single-wire communication device provided by the embodiment of the invention is used for the host, the host is connected with at least one slave computer through one bus, and the bus is released after the host transmits the first data packet, so that the host is ensured not to occupy the bus to transmit the data packet to the slave computer again after the host transmits the first data packet, and the slave computer is ensured to accurately transmit the response data packet to the slave computer. The device avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
According to a fourth aspect, an embodiment of the present invention provides a single-wire communication device, for a slave, where the slave is connected to a master through a bus, and the single-wire communication device includes: the second receiving module is used for receiving a first data packet sent by the host through the bus and generating a response data packet corresponding to the first data packet; the second sending module is used for switching the input/output port of the slave to be in an output state and sending the response data packet to the host through the bus; the second judging module is used for judging whether the transmission of the response data packet is completed or not; and the second releasing module is used for releasing the bus and switching the input/output port of the slave to an input state when the transmission of the response data packet is completed.
The embodiment of the invention provides a single-wire communication device which is used for a slave machine, wherein the slave machine is connected with a host machine through a bus, and the slave machine releases the bus after sending a response data packet, so that the slave machine is ensured not to occupy the bus to send other data packets to the slave machine again after sending the response data packet, and the host machine is ensured to accurately receive the response data packet sent by the slave machine. The device avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
According to a fifth aspect, an embodiment of the present invention provides an electronic device, including: the memory and the processor are in communication connection with each other, the memory stores computer instructions, and the processor executes the computer instructions, so as to execute the single-wire communication method according to the first aspect or any implementation manner of the first aspect, or execute the single-wire communication method according to the second aspect or any implementation manner of the second aspect.
According to a sixth aspect, an embodiment of the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to perform the single-wire communication method according to the first aspect or any implementation manner of the first aspect, or to perform the single-wire communication method according to the second aspect or any implementation manner of the second aspect.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are needed in the description of the embodiments or the prior art will be briefly described, and it is obvious that the drawings in the description below are some embodiments of the present invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a single wire communication method according to an embodiment of the present invention;
FIG. 2 is a flow chart of a single wire communication method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a master and a slave communication connection according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a master communication connection with a plurality of slaves in accordance with an embodiment of the present invention;
FIG. 5 is a flow chart of a single wire communication method according to an embodiment of the present invention;
FIG. 6 is a flow chart of a single wire communication method according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of logic level 0 according to an embodiment of the present invention;
FIG. 8 is a schematic diagram of logic level 1 according to an embodiment of the invention;
FIG. 9 is a schematic diagram of data communication according to an embodiment of the invention;
FIG. 10 is another schematic diagram of data communication according to an embodiment of the invention;
fig. 11 is a block diagram of a single wire communication device according to an embodiment of the present invention;
Fig. 12 is a block diagram of a single wire communication device according to an embodiment of the present invention;
fig. 13 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The short-range communication mode between chips adopts a single bus communication mode, but the data communication by using the single bus communication mode must strictly adhere to a single bus communication protocol, a delay function (No Operation, NOP) is needed when data is transmitted or read, delay parameters of each state are set according to communication time sequence, the parameter adjustment is complex and unstable, delay inaccuracy is easy to be caused, the situation that both the chips occupy buses at the same time for data transmission is caused when the delay inaccuracy occurs, the data communication of both the chips is disordered, and the data communication stability and the data receiving inaccuracy of both the chips are caused.
Based on the above, in the technical scheme of the invention, when the host and the slave (the host and the slave in the technical scheme are chips) do not perform data communication, the input/output ports of the host and the slave are set to be in an input state, when the host needs to send a data packet to the slave, the input/output port of the host is switched to be in an output state, and after the host finishes sending the data packet, the bus is released, and then the input/output port of the host is switched to be in an input state; the slave can switch the corresponding input/output port to an output state at the moment, send the response data packet to the host by using the bus released by the host, release the bus after the transmission of the response data packet is completed, and switch the input/output port to an input state. Therefore, at most, the input/output ports of the master computer and each slave computer on the bus have one output state at any time, and the stability of data communication and the accuracy of data receiving of the master computer and the slave computers are ensured.
In accordance with an embodiment of the present invention, there is provided an embodiment of a single wire communication method, it being noted that the steps shown in the flowchart of the figures may be performed in a computer system, such as a set of computer executable instructions, and, although a logical sequence is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than what is shown or described herein.
In this embodiment, a single-wire communication method is provided, which may be used for a master, where the master is connected to at least one slave through a bus, and fig. 1 is a flowchart of the single-wire communication method according to an embodiment of the present invention, and as shown in fig. 1, the flowchart includes the following steps:
S11, setting the input/output port of the host to be in an output state, and sending a first data packet to the slave.
The host computer communicates data with the slave computer through a bus. When the host does not send a packet, an input/output (I/O) port of the host is set to an input state, such as an input pull-up state or an input pull-down state. When the host needs to send data to the slave, the host switches the I/O port of the host from the input state to the output state so as to send a first data packet to the slave. The data content of the first data packet may include a start bit, a data length, data, a checksum end code, etc., and the data length is not particularly limited herein.
Taking the input pull-up state as an example, before the host computer and the slave computer communicate, the two computers need to define a communication protocol, and data transmission is carried out according to the communication protocol defined by the two computers during communication. Before the host computer communicates with the slave computer, the I/O ports of the host computer and the slave computer are connected and pulled up by using a pull-up resistor. At this time, the two-way I/O port is set to the input state and the pull-up state. When the host needs to send data to the slave, the host can set its I/O port to an output state, and send the first data packet to the slave through the I/O port, while the I/O port of the slave is still in an input pull-up state.
S12, judging whether the first data packet is sent completely or not.
The host determines whether it has completed the transmission of the first data packet. Specifically, the host may determine whether the transmission of the first data packet is completed by checking an end code existing in the first data packet. When it is determined that the host completes the transmission of the first data packet, step S13 is executed, otherwise, the transmission is continued.
S13, releasing the bus and switching the input/output port of the host to an input state.
And after the host finishes sending the first data packet, releasing a data transmission bus between the host and the slave, and simultaneously switching an input/output port of the host into an input state, so that the host pauses sending the data packet to the slave until receiving a response data packet from the slave, judging whether the data needs to be continuously sent to the slave, if the data needs to be continuously sent to the slave by the host, switching the input/output port of the host into an output state, and otherwise, continuously maintaining the input state.
S14, receiving a response data packet corresponding to the first data packet sent by at least one slave machine, wherein the response data packet is sent through a released bus.
After receiving the first data packet sent by the host, the slave can send a response data packet corresponding to the first data packet. When the slave detects that the bus is in a release state, the response data packet host is sent through the released bus, and the host can receive the response data packet corresponding to the first data packet sent by the slave.
The single-wire communication method provided by the embodiment is used for a host, the host is connected with at least one slave through a bus, the host sends a first data packet to the slave by setting the corresponding input/output port of the host to be in an output state, and when the first data packet is sent, the bus is released, and the corresponding input/output port of the host is switched to be in an input state. When the slave receives the first data packet sent by the host, the corresponding response data packet is sent to the host, and the host receives at least one response data packet corresponding to the first data packet sent by the slave, wherein the response data packet is sent through a bus released by the host. The host releases the bus after the host transmits the first data packet, so that the host cannot occupy the bus to transmit the data packet to the slave after the host transmits the first data packet, and the slave can accurately transmit the response data packet to the slave. The method avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
In this embodiment, a single-wire communication method is provided, which may be used for a master, where the master is connected to at least one slave through a bus, and fig. 2 is a flowchart of the single-wire communication method according to an embodiment of the present invention, and as shown in fig. 2, the flowchart includes the following steps:
S20, setting the input/output port of the host to be in an output state, and sending a first data packet to the slave.
Specifically, the step S20 may include the steps of:
s201, judging whether the host needs to send the first data packet.
The host monitors whether a sending instruction of the first data packet is received or not in real time, so as to determine whether the first data packet needs to be sent or not. When the host receives the sending instruction of the first data packet, it indicates that the host needs to send the first data packet to the slave, and step S202 is performed, otherwise, step S203 is performed.
S202, the input/output port of the host is switched to an output state.
When the host needs to send the first data packet, the I/O port of the host needs to be switched to an output state to ensure that the host can send the first data packet to the slave.
S203, maintaining the input state of the input/output port of the host.
When the host computer does not need to send the first data packet to the slave computer, the I/O port of the host computer is kept in the input state until the host computer needs to send the data packet to the slave computer again, and the input state of the I/O port of the host computer is switched to the output state.
S21, judging whether the first data packet is sent completely or not. For details, reference is made to the relevant description of the step 12 corresponding to the above embodiment, and the details are not repeated here.
S22, releasing the bus and switching the input/output port of the host to an input state. For details, see the relevant descriptions of the corresponding step 13 in the above embodiment, and are not repeated here.
S23, receiving a response data packet corresponding to the first data packet sent by at least one slave machine, wherein the response data packet is sent through a released bus. For details, reference is made to the relevant description of the step 14 corresponding to the above embodiment, and the details are not repeated here.
S24, detecting a first duration of bus release of the slave.
The first duration is the duration that the data bus corresponding to the exchange of the data transmission direction between the host and the slave is released. When the host detects that the slave releases the bus, starting timing and acquiring a first duration of the slave releases the bus.
S25, judging whether the first duration is longer than a first preset duration.
The first preset duration is the duration of the data bus corresponding to the data transmission direction between the host and the slave being released when the data transmission direction is changed. Specifically, if the duration of one logic level of data transmission is T, theoretically, the first duration is longer than T, and in order to make the signal identification degree higher, the first preset duration may be set to be 2T. Comparing the first duration with a first preset duration, and determining the magnitude relation between the first duration and the first preset duration. When the first duration is longer than the first preset duration, step S26 is executed, otherwise, the first duration is continuously detected.
For example: logic level 0. A logic level is of duration T (typically T.gtoreq.3t, T being the minimum timing time base), then logic level 0 is first the low level of N/MT, then the high level of (M-N)/MT. Wherein Mt=T, N is less than or equal to (M/2) -1. If t=250us, t=4x250us=1 ms, n=1; the logic level 0 is first a low level of 1/4T (i.e., 250 us) and then a high level of 3/4T (i.e., 750 us), as shown in fig. 7.
For example: logic level 1. A logic level is of duration T (T is usually more than or equal to 3T, and T is the minimum timing time base), and then the logic level 1 is of high level of (M-N)/MT, and then of low level of N/MT. Wherein Mt=T, N is less than or equal to (M/2) -1. If t=250us, t=4x250us=1 ms, n=1; the logic level 1 is first 3/4T (i.e., 750 us) low and then 1/4T (i.e., 250 us) high, as shown in fig. 8.
S26, judging whether the second data packet needs to be continuously sent.
When the first duration is longer than the first preset duration, the current bus is not used, and the host can continue to send data to the slave. At this time, it is determined whether the host receives a transmission instruction corresponding to the second data packet to determine whether the host needs to continue to transmit the second data packet. When the host needs to send the second data packet, step S27 is performed, otherwise step S28 is performed.
S27, setting the input/output port of the host to be in an output state.
And when the second data packet needs to be continuously transmitted, executing the operation of transmitting the second data packet. The operation of sending the second data packet is identical to the operation of sending the first data packet, and the detailed description is referred to above regarding step S202, which is not repeated here.
S28, judging whether the first duration is longer than a second preset duration.
The second preset duration is the duration of the data bus corresponding to the end of the communication between the host and the slave. And when the data packet does not need to be continuously sent, continuously comparing the first duration with a second preset duration, and determining whether the first duration is greater than the second preset duration or not so as to determine whether the data communication between the host computer and the slave computer is finished or not. When the first duration is longer than the second preset duration, step S29 is executed, otherwise execution continues to detect the first duration.
S29, judging whether the third data packet needs to be sent.
When the first duration is longer than the second preset duration, the data communication between the host and the slave is finished, and the next data communication can be entered. The host detects whether a sending instruction corresponding to the third data packet is received in real time to determine whether the third data packet needs to be sent. Wherein the third data packet is the data content to be sent for the new data communication. When the host needs to send the third data packet, step S210 is performed, otherwise, the host maintains its I/O port in the input state.
S210, setting the input/output port of the host to an output state.
When the third data packet needs to be transmitted, an operation of transmitting the third data packet is performed. The operation of transmitting the third data packet is identical to the operation of transmitting the first data packet, and the detailed description is referred to above regarding step S202, which is not repeated here.
According to the single-wire communication method provided by the embodiment of the invention, whether the host needs to send the first data packet is judged, and when the host needs to send the first data packet, the input/output port of the host is switched to an output state so as to send the first data packet. When the host computer does not need to send the first data packet, the input/output port of the host computer is switched to an input state so as to release the bus for the host computer to communicate with the slave computer. The method ensures that the input/output port of the host on the bus at any time is in an output state only when the data packet is sent, and the input/output ports of the host are in an input state at other moments, thereby avoiding data transmission conflicts.
Judging whether the first duration is longer than a first preset duration or not by detecting the first duration of the slave release bus, and judging whether the second data packet needs to be continuously sent or not when the first duration is longer than the first preset duration; when the second data packet needs to be continuously sent, the input/output port of the host is switched to be in an output state so that the host can continuously send the second data packet to the slave by using the released bus, data transmission conflict is avoided, and stability of data transmission is guaranteed.
When the second data packet is not required to be continuously sent, judging whether the first duration is longer than the second preset duration, when the first duration is longer than the second preset duration, judging whether a third data packet is required to be sent, when the third data packet is required to be sent, indicating that the host enters new data communication, switching an input/output port of the host into an output state, so that the host can continuously send the data packet to the slave by using the released bus, avoiding data transmission conflict, and further ensuring the stability of data transmission.
Optionally, when the number of the hosts is multiple, the input/output ports of the hosts are connected with the buses, and the input/output ports of the multiple slaves are respectively connected with the buses, so that when the slaves receive the first data packet or the second data packet or the third data packet sent by the hosts, the target slaves can check the target slaves with the own physical address to determine the slaves which are in communication with the hosts, and the situation that the data transmitted by the hosts are mistakenly regarded as the addresses by other slaves, and the other slaves participate in the data communication at the time, so that the data buses are mistakenly occupied is avoided.
If the master computer is connected with one slave computer through a bus, as shown in fig. 3, when the two parties of the master computer and the slave computer perform data communication, the first data packet or the second data packet or the third data packet may not be added with the target slave computer address, and the master computer directly sends the first data packet or the second data packet or the third data packet to the slave computer.
If the host computer is connected with the plurality of slaves through the bus, the input/output ports of the host computer are connected with the bus, and the input/output ports of the plurality of slaves are respectively connected with the bus. Taking a connection between a master and two slaves as shown in fig. 4, before data communication, the two slaves define their own physical addresses in the program, respectively, and the addresses of the two slaves are not repeatable. When the host computer and the two slave computers perform data communication, the addresses of the target slave computers are added into the first data packet or the second data packet or the third data packet, after the two slave computers acquire the first data packet or the second data packet or the third data packet sent by the host computer, whether the addresses of the target slave computers of the first data packet or the second data packet or the third data packet are consistent with the physical addresses of the slave computers or not is checked, if so, the slave computers respond to the first data packet or the second data packet or the third data packet and generate a response data packet corresponding to the first data packet or the second data packet or the third data packet; if not, the slave does not respond to the first data packet or the second data packet or the third data packet.
According to the single-wire communication method provided by the embodiment of the invention, when a plurality of hosts are provided, the input/output ports of the hosts are connected with the bus, the input/output ports of the plurality of slaves are respectively connected with the bus, and the first data packet or the second data packet or the third data packet also comprises the target slave address, so that the accuracy of data transmission between the hosts and the slaves is ensured, and the bus is prevented from being occupied by errors.
In this embodiment, a single-wire communication method is provided, which may be used for a slave, where the slave is connected to a host through a bus, and fig. 5 is a flowchart of the single-wire communication method according to an embodiment of the present invention, and as shown in fig. 5, the flowchart includes the following steps:
S31, receiving a first data packet sent by a host through a bus, and generating a response data packet corresponding to the first data packet.
The response data packet is response data which is generated by the slave and corresponds to the data packet sent by the host. The slave can receive a first data packet sent by the host, respond to the data content contained in the first data packet, and generate a response data packet corresponding to the first data packet.
S32, switching the input/output port of the slave to be in an output state, and sending the response data packet to the host through the bus.
When the host transmits the first data packet, the slave is always in the input state, and can only transmit data when the I/O port is in the output state. Therefore, in order to transmit the response packet to the master, it is necessary to switch the input state of the I/O port of the slave to the output state.
S33, judging whether the transmission of the response data packet is completed.
The data content in the response data packet is consistent with the data format of the first data packet, that is, the response data content in the response data packet may include information such as a start bit, a data length, data, a checksum and an end code corresponding to the response data. The slave can determine whether the transmission of the response data packet is completed by checking the end code corresponding to the response data existing in the response data packet. When the transmission of the response packet is completed, step S34 is executed, otherwise, the transmission is continued.
S34, releasing the bus and switching the input/output port of the slave to an input state.
When the slave machine finishes sending the response data packet, the data transmission bus between the host machine and the slave machine is released, meanwhile, the input/output port of the slave machine is switched to an input state, the slave machine stops sending the response data packet to the host machine until the slave machine receives the data packet sent by the host machine again, the slave machine needs to send the response data packet corresponding to the data packet to the host machine, the I/O port of the slave machine is switched to an output state, and otherwise, the input state is continuously maintained.
Specifically, the data communication between the master and the slave may be a master-slave as shown in fig. 3, or may be a master-multi-slave as shown in fig. 4. When the data communication between the master and the slave can be a master and a slave, the corresponding data communication is shown in fig. 9; when the data communication between the master and the slave can be one master and more, the corresponding data communication is shown in fig. 10.
The embodiment provides a single-wire communication method, which is used for a slave machine, wherein the slave machine is connected with a host machine through a bus, the slave machine receives a first data packet sent by the host machine through the bus, generates a response data packet corresponding to the first data packet, switches an input/output port corresponding to the first data packet to be in an output state, sends the response data packet to the host machine through the bus, releases the bus when the response data packet is sent, and switches the input/output port corresponding to the response data packet to be in the input state. The slave releases the bus after the slave transmits the response data packet, so that the slave cannot occupy the bus to transmit other data packets to the slave again after the slave transmits the response data packet, and the host can accurately receive the response data packet transmitted by the slave. The method avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
In this embodiment, a single-wire communication method is provided, which may be used for a slave, where the slave is connected to a host through a bus, and fig. 6 is a flowchart of the single-wire communication method according to an embodiment of the present invention, and as shown in fig. 6, the flowchart includes the following steps:
S41, receiving a first data packet sent by the host through the bus, and generating a response data packet corresponding to the first data packet. The detailed description refers to the relevant description of the playing step S31 in the above embodiment, and will not be repeated here.
S42, switching the input/output port of the slave to be in an output state, and sending the response data packet to the host through the bus.
Specifically, the step S42 may include the steps of:
s421, the input/output port of the slave is switched to be in an output state.
The transmission of the response packet can be performed only when the I/O port of the slave is in the output state, and therefore, the input state of the I/O port of the slave needs to be switched to the output state before the response packet is transmitted.
S422, detecting a second duration of the host release bus.
The second duration is the duration that the data bus corresponding to the change of the data transmission direction between the slave and the host is released. When the slave detects the host release bus, starting timing and acquiring a second duration of the host release bus.
S423, judging whether the second duration exceeds a third preset duration.
The third preset duration is the duration of the data bus corresponding to the data transmission direction between the master and the slave being released when the data transmission direction is changed. Specifically, if the duration of one logic level of the data transmission is T, theoretically, the first duration is longer than T, and in order to make the signal identification degree higher, a third preset duration may be set to be 2T. Comparing the second duration with a third preset duration, and determining the magnitude relation between the second duration and the third preset duration. When the second duration is longer than the third preset duration, step S414 is executed, otherwise, the second duration is continuously detected.
S424, transmitting a response data packet corresponding to the first data packet.
When the second duration exceeds the third preset duration, the current bus is not used, and the slave can send a response data packet to the host through the released bus.
Specifically, when a plurality of slaves are connected to the master through the bus and the first data packet includes the target slave address, the step S424 may include the following steps:
(1) And judging whether the target slave machine address is the same as the physical address of the current slave machine.
After the slave receives the first data packet sent by the host, the first data packet is analyzed, and a target slave address contained in the first data packet is obtained. The slave compares the acquired target slave address with the physical address of the slave, and determines whether the target slave address is identical to the physical address of the current slave. And (3) executing the step (2) when the target slave address is the same as the physical address of the current slave, otherwise executing the step (3).
(2) And sending a response data packet corresponding to the first data packet.
And when the target slave address is the same as the physical address of the current slave, the target slave is indicated to be the target slave for data communication corresponding to the master. At this time, the slave may transmit a response packet corresponding to the first packet and transmit the response packet to the master.
(3) Waiting for the host to send data to it.
When the target slave address is different from the physical address of the current slave, the target slave is indicated to be not the target slave of the data communication corresponding to the host. At this time, the slave does not respond or reply to the first data packet received by the slave, and continues to wait for the host to send data to the slave.
S43, judging whether the sending of the response data packet is completed. The detailed description refers to the relevant description of the playing step S33 in the above embodiment, and will not be repeated here.
S44, when the transmission of the response data packet is completed, the bus is released, and the input/output port of the slave is switched to the input state. The detailed description refers to the related description of the playing step S44 in the above embodiment, and will not be repeated here.
According to the single-wire communication method provided by the embodiment of the invention, whether the second duration exceeds the third preset duration is judged by detecting the second duration of the bus release of the host, and when the second duration exceeds the third preset duration, the slave sends a response data packet corresponding to the first data packet and sends the response data packet. The method ensures that the host does not occupy the bus when the slave sends the response data packet, thereby avoiding the data transmission conflict. When a plurality of slaves are connected with a host computer through a bus, a first data packet comprises a target slave address, before a response data packet corresponding to the first data packet is sent, whether the target slave address is the same as the address of the current slave is judged, and when the target slave address is the same as the address of the current slave, the response data packet corresponding to the first data packet is sent, so that the accuracy of data transmission between the host computer and the slaves is ensured, and the error occupation of the bus is avoided.
In this embodiment, a single-wire communication device is further provided, and the device is used to implement the foregoing embodiments and preferred embodiments, and is not described in detail. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. While the means described in the following embodiments are preferably implemented in software, implementation of hardware or a combination of software and hardware is also possible and contemplated.
The present embodiment provides a single-wire communication device for a master, where the master is connected to at least one slave through a bus, as shown in fig. 11, and includes:
The first sending module 51 is configured to set an input/output port of the master to an output state, and send a first data packet to the slave. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
A first judging module 52 is configured to judge whether the first data packet is sent completely. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
The first releasing module 53 is configured to release the bus and switch the input/output port of the host to the input state when the first data packet is sent. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
The first receiving module 54 is configured to receive a response packet corresponding to the first packet sent by at least one slave, where the response packet is sent through the released bus. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
The single-wire communication device provided by the embodiment is used for a host, the host is connected with at least one slave computer through a bus, and the bus is released after the host transmits the first data packet, so that the host is ensured not to occupy the bus to transmit the data packet to the slave computer again after the host transmits the first data packet, and the slave computer is ensured to accurately transmit the response data packet to the slave computer. The device avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
The single wire communication device in this embodiment is presented in the form of functional units, where the units refer to ASIC circuits, processors and memories executing one or more software or firmware programs, and/or other devices that provide the functionality described above.
Further functional descriptions of the above respective modules are the same as those of the above corresponding embodiments, and are not repeated here.
In this embodiment, a single-wire communication device is further provided, and the device is used to implement the foregoing embodiments and preferred embodiments, and is not described in detail. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. While the means described in the following embodiments are preferably implemented in software, implementation of hardware or a combination of software and hardware is also possible and contemplated.
The embodiment provides a single-wire communication device, which is used for a slave machine, wherein the slave machine is connected with a host machine through a bus, as shown in fig. 12, and comprises:
The second receiving module 61 is configured to receive the first data packet sent by the host through the bus, and send a response data packet corresponding to the first data packet. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
The second sending module 62 is configured to switch the input/output port of the slave to an output state, and send the response packet to the host through the bus. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
A second judging module 63, configured to judge whether the transmission of the response packet is completed. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
The second releasing module 64 is configured to release the bus and switch the input/output port of the slave to the input state when the transmission of the response packet is completed. The detailed description refers to the corresponding related descriptions of the above embodiments, and will not be repeated here.
The embodiment provides a single-wire communication device, which is used for a slave machine, wherein the slave machine is connected with a host machine through a bus, and the bus is released after the slave machine transmits a response data packet, so that the slave machine is ensured not to occupy the bus to transmit other data packets to the slave machine again after the slave machine transmits the response data packet, and the host machine is ensured to accurately receive the response data packet transmitted by the slave machine. The device avoids the situation that the host and the slave occupy the bus to send data packets to each other at the same time due to inaccurate time delay when the host is in single-wire communication with the slave, thereby avoiding data transmission confusion and ensuring the stability and the data receiving accuracy of single-wire communication.
The single wire communication device in this embodiment is presented in the form of functional units, where the units refer to ASIC circuits, processors and memories executing one or more software or firmware programs, and/or other devices that provide the functionality described above.
Further functional descriptions of the above respective modules are the same as those of the above corresponding embodiments, and are not repeated here.
The embodiment of the invention also provides electronic equipment, which is provided with the single-wire communication device shown in the figures 7 and 8.
Referring to fig. 13, fig. 13 is a schematic structural diagram of an electronic device according to an alternative embodiment of the present invention, as shown in fig. 13, the electronic device may include: at least one processor 71, such as a CPU (Central Processing Unit ), at least one communication interface 73, a memory 74, at least one communication bus 72. Wherein the communication bus 72 is used to enable connected communication between these components. The communication interface 73 may include a Display screen (Display) and a Keyboard (Keyboard), and the optional communication interface 73 may further include a standard wired interface and a wireless interface. The memory 74 may be a high-speed RAM memory (Random Access Memory, volatile random access memory) or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 74 may alternatively be at least one memory device located remotely from the processor 71. Wherein the processor 71 may be as described in connection with fig. 7 and 8, the application program is stored in the memory 74, and the processor 71 invokes the program code stored in the memory 74 for performing any of the method steps described above.
The communication bus 72 may be a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, PCI) bus, an extended industry standard architecture (extended industry standard architecture, EISA) bus, or the like. The communication bus 72 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in fig. 13, but not only one bus or one type of bus.
Wherein the memory 74 may include volatile memory (English) such as random-access memory (RAM); the memory may also include a nonvolatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk (English: HARD DISK DRIVE, abbreviation: HDD) or a solid state disk (English: solid-STATE DRIVE, abbreviation: SSD); memory 74 may also include a combination of the above types of memory.
The processor 71 may be a central processor (English: central processing unit, abbreviated: CPU), a network processor (English: network processor, abbreviated: NP) or a combination of CPU and NP.
The processor 71 may further include a hardware chip, among others. The hardware chip may be an application-specific integrated circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof (English: programmable logic device). The PLD may be a complex programmable logic device (English: complex programmable logic device, abbreviated: CPLD), a field-programmable gate array (English: field-programmable GATE ARRAY, abbreviated: FPGA), a general-purpose array logic (English: GENERIC ARRAY logic, abbreviated: GAL), or any combination thereof.
Optionally, the memory 74 is also used for storing program instructions. Processor 71 may invoke program instructions to implement the single-wire communication method as shown in the embodiments of fig. 1 and 2, fig. 5 and 6 of the present application.
The embodiment of the invention also provides a non-transitory computer storage medium, which stores computer executable instructions that can execute the processing method of the single-wire communication method in any of the above method embodiments. Wherein the storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a Flash Memory (Flash Memory), a hard disk (HARD DISK DRIVE, abbreviated as HDD), a Solid state disk (Solid-state-STATE DRIVE, SSD), or the like; the storage medium may also comprise a combination of memories of the kind described above.
Although embodiments of the present invention have been described in connection with the accompanying drawings, various modifications and variations may be made by those skilled in the art without departing from the spirit and scope of the invention, and such modifications and variations fall within the scope of the invention as defined by the appended claims.
Claims (7)
1. A single wire communication method for a host computer connected to at least one slave computer via a bus, comprising the steps of:
Setting an input/output port of the host as an output state, and sending a first data packet to the slave;
judging whether the first data packet is sent completely or not by checking an end code in the first data packet;
When the first data packet is sent, releasing the bus and switching the input/output port of the host to an input state;
Receiving a response data packet corresponding to the first data packet sent by at least one slave machine, wherein the response data packet is sent through the released bus;
After receiving the response data packet corresponding to the first data packet sent by at least one slave, the method further comprises: detecting a first duration of time that the slave releases the bus; the method comprises the steps that a first duration is the duration that a data bus corresponding to the data transmission direction between a host and a slave is released when the data transmission direction between the host and the slave is changed, and when the host detects that the slave releases the bus, timing is started, and the first duration is acquired; judging whether the first duration is longer than a first preset duration which is twice the duration of one logic level of data transmission; when the first duration is longer than the first preset duration, judging whether to continue sending the second data packet or not; when the first duration is longer than the first preset duration, the current bus is not used, and the host can continue to send data to the slave, at this time, whether the host receives a sending instruction corresponding to the second data packet is judged to determine whether the host needs to continue to send the second data packet; when the second data packet needs to be continuously sent, executing the step of setting the input/output port of the host to be in an output state;
The setting the input/output port of the host to an output state includes:
judging whether the host needs to send a first data packet or not;
when the host needs to send a first data packet, switching an input/output port of the host into the output state;
the setting the input/output port of the host to an output state further includes:
When the host does not need to send a first data packet, maintaining the input state of the input/output port of the host;
The method further comprises the steps of:
when the second data packet does not need to be continuously sent, judging whether the first duration is longer than a second preset duration or not so as to determine whether data communication between the host computer and the slave computer is finished or not; the second preset duration is the duration for which the data bus corresponding to the end of communication between the host and the slave is released; when the first duration is longer than the second preset duration, the data communication between the host and the slave is finished, and the next data communication can be entered;
When the first duration is longer than the second preset duration, judging whether a third data packet needs to be sent or not; specifically, the host detects whether a sending instruction corresponding to a third data packet is received in real time to determine whether the third data packet needs to be sent, wherein the third data packet is the data content to be sent for new data communication;
when the third data packet needs to be sent, executing the step of setting the input/output port of the host to an output state;
When the number of the host computers is multiple, the input/output ports of the host computers are connected with the bus, the input/output ports of the plurality of the slaves are respectively connected with the bus, and the first data packet or the second data packet or the third data packet comprises a target slave address.
2. A single-wire communication method for a slave, said slave being connected to a master via a bus, comprising the steps of:
Receiving a first data packet sent by the host through the bus, generating a response data packet corresponding to the first data packet, wherein the first data packet is sent after the host sets an input/output port of the host to an output state, and the host sets the input/output port of the host to the output state, and the response data packet comprises: judging whether the host needs to send a first data packet or not; when the host needs to send a first data packet, switching an input/output port of the host into the output state; when the host does not need to send the first data packet, maintaining the input state of the input/output port of the host; the host judges whether the first data packet is sent completely or not by checking an end code in the first data packet, releases the bus when the first data packet is sent completely, and switches an input/output port of the host into an input state;
Switching an input/output port of a slave to be in an output state, and sending the response data packet to a host through the bus so that the host detects a first duration of the slave releasing the bus; the method comprises the steps that a first duration is the duration that a data bus corresponding to the data transmission direction between a host and a slave is released when the data transmission direction between the host and the slave is changed, and when the host detects that the slave releases the bus, timing is started, and the first duration is acquired; judging whether the first duration is longer than a first preset duration which is twice the duration of one logic level of data transmission; when the first duration is longer than the first preset duration, judging whether to continue sending the second data packet or not; when the first duration is longer than the first preset duration, the current bus is not used, and the host can continue to send data to the slave, at this time, whether the host receives a sending instruction corresponding to the second data packet is judged to determine whether the host needs to continue to send the second data packet; when the second data packet needs to be continuously sent, executing the step of setting the input/output port of the host to be in an output state; when the second data packet does not need to be continuously sent, judging whether the first duration is longer than a second preset duration or not so as to determine whether data communication between the host computer and the slave computer is finished or not; the second preset duration is the duration for which the data bus corresponding to the end of communication between the host and the slave is released; when the first duration is longer than the second preset duration, the data communication between the host and the slave is finished, and the next data communication can be entered; when the first duration is longer than the second preset duration, judging whether a third data packet needs to be sent or not; specifically, the host detects whether a sending instruction corresponding to a third data packet is received in real time to determine whether the third data packet needs to be sent, wherein the third data packet is the data content to be sent for new data communication; when the third data packet needs to be sent, executing the step of setting the input/output port of the host to an output state; when the number of the host computers is multiple, the input/output ports of the host computers are connected with the bus, the input/output ports of the plurality of the slaves are respectively connected with the bus, and the first data packet or the second data packet or the third data packet comprises a target slave address;
The sending the response data packet to the host through the bus includes: detecting a second duration of time that the host releases the bus; judging whether the second duration exceeds a third preset duration; when the second duration exceeds the third preset duration, sending a response data packet corresponding to the first data packet;
judging whether the response data packet is sent completely or not by checking an end code in the response data packet;
and when the transmission of the response data packet is completed, releasing the bus and switching the input/output port of the slave to an input state.
3. The method of claim 2, wherein said sending the reply packet to the host over the bus further comprises:
judging whether the target slave machine address is the same as the physical address of the current slave machine or not;
And when the target slave machine address is the same as the physical address of the current slave machine, sending a response data packet corresponding to the first data packet.
4. A single wire communication device for a host computer connected to at least one slave computer via a bus, comprising:
The first sending module is used for setting the input/output port of the host to be in an output state and sending a first data packet to the slave; the setting the input/output port of the host to an output state includes: judging whether the host needs to send a first data packet or not; when the host needs to send a first data packet, switching an input/output port of the host into the output state; the setting the input/output port of the host to an output state further includes: when the host does not need to send the first data packet, maintaining the input state of the input/output port of the host;
the first judging module is used for judging whether the first data packet is sent completely or not by checking the end code in the first data packet;
The first releasing module is used for releasing the bus and switching the input/output port of the host into an input state when the first data packet is sent;
The first receiving module is used for receiving response data packets corresponding to the first data packets sent by at least one slave machine, and the response data packets are sent through the released buses;
After receiving the response data packet corresponding to the first data packet sent by at least one slave, the method further comprises: detecting a first duration of time that the slave releases the bus; the method comprises the steps that a first duration is the duration that a data bus corresponding to the data transmission direction between a host and a slave is released when the data transmission direction between the host and the slave is changed, and when the host detects that the slave releases the bus, timing is started, and the first duration is acquired; judging whether the first duration is longer than a first preset duration which is twice the duration of one logic level of data transmission; when the first duration is longer than the first preset duration, judging whether to continue sending the second data packet or not; when the first duration is longer than the first preset duration, the current bus is not used, and the host can continue to send data to the slave, at this time, whether the host receives a sending instruction corresponding to the second data packet is judged to determine whether the host needs to continue to send the second data packet; when the second data packet needs to be continuously sent, executing the step of setting the input/output port of the host to be in an output state; when the second data packet does not need to be continuously sent, judging whether the first duration is longer than a second preset duration or not so as to determine whether data communication between the host computer and the slave computer is finished or not; the second preset duration is the duration for which the data bus corresponding to the end of communication between the host and the slave is released; when the first duration is longer than the second preset duration, the data communication between the host and the slave is finished, and the next data communication can be entered; when the first duration is longer than the second preset duration, judging whether a third data packet needs to be sent or not; specifically, the host detects whether a sending instruction corresponding to a third data packet is received in real time to determine whether the third data packet needs to be sent, wherein the third data packet is the data content to be sent for new data communication; when the third data packet needs to be sent, executing the step of setting the input/output port of the host to an output state; when the number of the host computers is multiple, the input/output ports of the host computers are connected with the bus, the input/output ports of the plurality of the slaves are respectively connected with the bus, and the first data packet or the second data packet or the third data packet comprises a target slave address.
5. A single wire communication device for a slave, said slave being connected to a master via a bus, comprising:
The second receiving module is configured to receive a first data packet sent by the host through the bus, generate a response data packet corresponding to the first data packet, and send the first data packet after the host sets an input/output port of the host to an output state, where the host sets the input/output port of the host to the output state, and includes: judging whether the host needs to send a first data packet or not; when the host needs to send a first data packet, switching an input/output port of the host into the output state; when the host does not need to send the first data packet, maintaining the input state of the input/output port of the host; the host judges whether the first data packet is sent completely or not by checking an end code in the first data packet, releases the bus when the first data packet is sent completely, and switches an input/output port of the host into an input state;
The second sending module is used for switching the input/output port of the slave machine into an output state and sending the response data packet to the host machine through the bus so as to enable the host machine to detect the first duration of the slave machine releasing the bus; the method comprises the steps that a first duration is the duration that a data bus corresponding to the data transmission direction between a host and a slave is released when the data transmission direction between the host and the slave is changed, and when the host detects that the slave releases the bus, timing is started, and the first duration is acquired; judging whether the first duration is longer than a first preset duration which is twice the duration of one logic level of data transmission; when the first duration is longer than the first preset duration, judging whether to continue sending the second data packet or not; when the first duration is longer than the first preset duration, the current bus is not used, and the host can continue to send data to the slave, at this time, whether the host receives a sending instruction corresponding to the second data packet is judged to determine whether the host needs to continue to send the second data packet; when the second data packet needs to be continuously sent, executing the step of setting the input/output port of the host to be in an output state; when the second data packet does not need to be continuously sent, judging whether the first duration is longer than a second preset duration or not so as to determine whether data communication between the host computer and the slave computer is finished or not; the second preset duration is the duration for which the data bus corresponding to the end of communication between the host and the slave is released; when the first duration is longer than the second preset duration, the data communication between the host and the slave is finished, and the next data communication can be entered; when the first duration is longer than the second preset duration, judging whether a third data packet needs to be sent or not; specifically, the host detects whether a sending instruction corresponding to a third data packet is received in real time to determine whether the third data packet needs to be sent, wherein the third data packet is the data content to be sent for new data communication; when the third data packet needs to be sent, executing the step of setting the input/output port of the host to an output state; when the number of the host computers is multiple, the input/output ports of the host computers are connected with the bus, the input/output ports of the plurality of the slaves are respectively connected with the bus, and the first data packet or the second data packet or the third data packet comprises a target slave address;
The sending the response data packet to the host through the bus includes: detecting a second duration of time that the host releases the bus; judging whether the second duration exceeds a third preset duration; when the second duration exceeds the third preset duration, sending a response data packet corresponding to the first data packet;
the second judging module is used for judging whether the response data packet is sent completely or not by checking the end code in the response data packet;
And the second releasing module is used for releasing the bus and switching the input/output port of the slave to an input state when the transmission of the response data packet is completed.
6. An electronic device, comprising:
a memory and a processor, the memory and the processor being communicatively connected to each other, the memory having stored therein computer instructions, the processor executing the computer instructions to perform the single wire communication method of claim 1 or to perform the single wire communication method of any of claims 2-3.
7. A computer-readable storage medium storing computer instructions for causing a computer to perform the single-wire communication method of claim 1 or to perform the single-wire communication method of any one of claims 2-3.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011475955.4A CN112579509B (en) | 2020-12-14 | 2020-12-14 | Single-wire communication method, single-wire communication device, electronic equipment and readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011475955.4A CN112579509B (en) | 2020-12-14 | 2020-12-14 | Single-wire communication method, single-wire communication device, electronic equipment and readable storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN112579509A CN112579509A (en) | 2021-03-30 |
| CN112579509B true CN112579509B (en) | 2024-07-23 |
Family
ID=75135046
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202011475955.4A Active CN112579509B (en) | 2020-12-14 | 2020-12-14 | Single-wire communication method, single-wire communication device, electronic equipment and readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN112579509B (en) |
Families Citing this family (13)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114253196A (en) * | 2021-12-23 | 2022-03-29 | 深圳宇凡微电子有限公司 | Stable and reliable communication method for single chip microcomputer system |
| CN114500689B (en) * | 2022-01-30 | 2023-09-08 | 合肥美的电冰箱有限公司 | Bus communication method, device, communication board, household electrical appliance and storage medium |
| CN114928378B (en) * | 2022-04-19 | 2024-08-09 | 深圳市芯生半导体有限公司 | Single-wire signal transmission method and device and electronic equipment |
| CN115168276B (en) * | 2022-06-27 | 2025-09-19 | 漳州科华技术有限责任公司 | Master-slave switching communication control method, device and system |
| CN115567080B (en) * | 2022-09-14 | 2024-10-01 | 上海龙旗科技股份有限公司 | Communication method, system and equipment based on USART |
| CN115422103A (en) * | 2022-09-22 | 2022-12-02 | 杭州安恒信息技术股份有限公司 | Data transmission method, system, device and readable storage medium |
| CN115637558A (en) * | 2022-09-29 | 2023-01-24 | 珠海格力电器股份有限公司 | Communication system and communication method for washing machine |
| CN115664455B (en) * | 2022-09-30 | 2025-09-26 | 影石创新科技股份有限公司 | Data transmission method, pan/tilt platform, computer equipment and storage medium |
| CN115801214A (en) * | 2022-11-04 | 2023-03-14 | 陕西银河景天电子有限责任公司 | Single-wire communication method and device |
| CN115827535A (en) * | 2022-11-07 | 2023-03-21 | 珠海东之尼电子科技有限公司 | Control method, device and storage medium for single-wire synchronous two-way communication |
| CN116107951B (en) * | 2023-04-10 | 2023-09-08 | 佛山市小熊厨房电器有限公司 | Single-wire bidirectional-based data communication method, device and storage medium |
| CN116561041B (en) * | 2023-07-12 | 2023-09-19 | 成都市芯璨科技有限公司 | Single bus communication system and method |
| CN117112473B (en) * | 2023-10-19 | 2024-02-02 | 紫光同芯微电子有限公司 | Data transmission method, system, equipment and storage medium based on single bus |
Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104657303A (en) * | 2014-10-13 | 2015-05-27 | 江苏瑞微电子有限公司 | Unibus data communication method |
| CN110704341A (en) * | 2019-09-06 | 2020-01-17 | 珠海泰芯半导体有限公司 | Device and method for upgrading code by serial port single line |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102693205B (en) * | 2012-05-11 | 2015-03-18 | 杭州硅星科技有限公司 | Data transmission, power supply device, data transmission and power supply method thereof |
-
2020
- 2020-12-14 CN CN202011475955.4A patent/CN112579509B/en active Active
Patent Citations (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104657303A (en) * | 2014-10-13 | 2015-05-27 | 江苏瑞微电子有限公司 | Unibus data communication method |
| CN110704341A (en) * | 2019-09-06 | 2020-01-17 | 珠海泰芯半导体有限公司 | Device and method for upgrading code by serial port single line |
Also Published As
| Publication number | Publication date |
|---|---|
| CN112579509A (en) | 2021-03-30 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN112579509B (en) | Single-wire communication method, single-wire communication device, electronic equipment and readable storage medium | |
| CN106681953B (en) | Slave connected with host by using I2C bus and communication method thereof | |
| US9294300B2 (en) | Token based communication in daisy chain configured battery management devices | |
| US11221977B2 (en) | Daisy chain mode entry sequence | |
| US10090916B2 (en) | Optical module availability detection method and apparatus | |
| CN111488304B (en) | Interface switching circuit | |
| CN111427828A (en) | SPI flow control method, system, master device, slave device and storage medium | |
| CN112148629A (en) | Method for addressing an integrated circuit on a bus and corresponding device | |
| CN115203092A (en) | Single-master multi-slave single-wire communication method, device and equipment | |
| CN114006787A (en) | Data transmission method, device, and computer-readable storage medium | |
| CN105446837A (en) | Method, device and system for detecting whether IIC (inter-integrated circuit) interface device is connected | |
| CN111913904A (en) | Method for automatically assigning mutually different addresses to a plurality of slave devices using a master-slave communication protocol and device therefor | |
| CN118673848A (en) | Single signal debug port | |
| CN111447121A (en) | Test method, device, equipment and storage medium of PCIE controller | |
| CN108197062B (en) | Method, system, equipment and medium for realizing communication between single chip microcomputer and terminal equipment | |
| CN119248586B (en) | A simulation verification model with flexibly configurable addressing mode for I2C interface IP verification | |
| EP2750030A1 (en) | Method, apparatus and processor for reading BIOS | |
| CN117407343B (en) | Method and device for processing clock extension in integrated circuit bus transparent transmission mode | |
| CN113468028B (en) | Device management method for computing device, apparatus and medium | |
| CN115794699B (en) | Data writing method based on SPI communication, electronic terminal and storage medium | |
| CN109597781B (en) | Detection of a time condition associated with a two-wire bus | |
| CN112445744A (en) | I2C communication | |
| KR101260313B1 (en) | Electric apparatus and data sending/receiving method thereof and slave apparatus and communication method between the plural number of apparatuses | |
| CN111930582B (en) | System management bus detection platform, processor and system management bus detection method | |
| JP4160068B2 (en) | Digital programming interface between baseband processor and radio frequency integrated module |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |