Data receiving method and data sending method based on signal duration
By signal -based data receiving and sending methods, the problem of limited resources of single -chip microcomputer communication scenarios in multiple single -chip microcomputers has been solved, and efficient single bus communication has been achieved, and chip selection and design costs are reduced.
Patent Information
- Application Number
- CN202411345927.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-01-21
AI Technical Summary
In multiple microcontrollers, due to limited peripheral resources and lack of multiple functional pins in the communication scenarios of multiple microcontrollers, existing microcontrollers have low communication efficiency and complex encoding and decoding operations.
Adopting the data receiving and sending method based on signal -based duration, determine the reset head signal and data bit by detecting the duration of the pulse signal received by the receiving terminal or sending the terminal, and realize the analysis and sending by themselves.
This method can achieve efficient single bus communication between single -chip machines without specific communication interfaces, reduce chip selection costs, simplify software implementation and hardware circuit design.
Smart Images

Figure CN119341686A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data communications, and specifically to a data receiving method and a data sending method based on signal duration. Background Art
[0002] At present, 51-core microcontrollers are commonly used in the small household appliance industry for functional application development. This type of microcontroller has few peripheral resources and usually has only one hardware serial interface. This type of microcontroller is a chip with a single functional pin, which has a great disadvantage in communication scenarios involving multiple microcontrollers. The Chinese invention patent with patent application number CN202410405100.6 discloses a random code sending control method and a random code-based burning control method to prevent repeated acquisition of the same random code at the same address. The invention patent controls the host and the target slave to perform conditional random code sending and receiving, but does not implement the level width recognition and level combination analysis bit by bit, nor does it plan the recognition order between the reset header signal and the data bit according to the data packet format, which is easy to affect the encoding and decoding operations of the complete data packet in the communication; and the indexing and deletion of the address of the read random code will increase the complexity of the software operation, and also require the chip to add a variety of functional pins. Summary of the invention
[0003] The present application discloses a data receiving method and a data sending method based on signal duration, and the specific technical solutions are as follows: A data receiving method based on signal duration, the data receiving method comprising: detecting a signal received by a receiving end; if the signal duration of a pulse detected for the first time does not satisfy the frame header duration definition of a preset communication protocol, continuing to detect the signal duration of the pulse received by the receiving end; if the signal duration of the pulse satisfies the frame header duration definition of the preset communication protocol, the receiving end receives a reset header signal; and then, when the signal duration of the pulse does not satisfy the frame header duration definition of the preset communication protocol, parsing the received signal into data bits according to the signal duration until a frame of data packets is parsed.
[0004] Based on this, the data receiving method disclosed in the present application first determines the reset header signal according to the pulse whose signal duration meets the frame header duration definition of the preset communication protocol to start parsing the data bit, and then parses the pulse bit by bit by detecting the signal duration of the pulse at the receiving end, so as to achieve cyclic parsing of multiple pulses according to the signal duration to obtain a complete frame of data packet when the pulses received twice successively meet the frame header duration definition of the preset communication protocol and do not meet the frame header duration definition of the preset communication protocol respectively. The software is relatively easy to implement and the amount of code is small; in the implementation of the hardware circuit, the data receiving method uses a receiving end to parse the received pulses according to the timing information, so as to parse out a frame of data packet pulse by pulse according to the agreed communication protocol, which can reduce the chip selection cost, is suitable for communication scenarios of multiple microcontrollers, and solves the single-bus communication problem between single-chip microcomputers that do not have specific communication interfaces.
[0005] Further, the data receiving method specifically includes: step A1, the receiving end enters an idle state, and then executes step A2; step A2, detects the signal duration of the pulse received by the receiving end, and then executes step A3; step A3, determines whether the signal duration of the pulse meets the frame header duration definition of the preset communication protocol, if yes, executes step A4, otherwise executes step A5; step A4, the receiving end receives a reset header signal, and then executes step A2; wherein the frame header of a frame of data packet is used to convert and output as the reset header signal; step A5, determines whether the receiving end received the reset header signal last time If the signal duration of the pulse is not satisfied, execute step A6, otherwise execute step A2; Step A6, parse out the data bits according to the signal duration of the pulse, and count the parsed data bits, and then execute step A7; Step A7, determine whether the number of data bits counted in step A6 reaches the preset number, if so, parse out a frame of data packets, and then execute step A1 to start parsing the next frame of data packets, otherwise execute step A2; wherein, the signal duration of the pulse is obtained by using a timer to time the width of the first level between two rising edges continuously received by the receiving end; the number of data bits is obtained by counting with a counter. In summary, when the signal duration of the pulse received by the receiving end does not meet the definition of the frame header duration of the preset communication protocol, the receiving controller parses out each data bit according to the signal duration pulse by pulse, and implements cyclic parsing of high pulse width data until enough data bits are parsed, and it is considered that a complete frame of data packets is parsed.
[0006] Further, in step A3, the method for determining whether the signal duration of a pulse meets the definition of the frame header duration of a preset communication protocol includes: determining whether the signal duration of a pulse is greater than or equal to a preset target number of bit periods, if yes, determining that the signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol, otherwise determining that the signal duration of the pulse does not meet the definition of the frame header duration of the preset communication protocol; wherein the preset target number is equal to a value of 4. Thus, the number of bit periods is used to determine which pulse signal duration meets the definition of the frame header duration of the preset communication protocol.
[0007] Further, in step A6, the method for parsing data bits according to the signal duration of the pulse includes: when executing step A6, determining that the signal duration of the pulse is less than the signal duration of the reset head signal; then judging whether the signal duration of the pulse is less than half of the bit period, if so, parsing the periodic signal where the pulse is located into the first data bit, otherwise parsing the periodic signal where the pulse is located into the second data bit, so as to achieve parsing the received signal into data bits according to the signal duration; wherein the value of the first data bit is binary 0, and the value of the second data bit is binary 1; wherein the bit period is represented by the total width of all levels converted from one data bit. Thus, based on the definition of the duration of binary 0 and binary 1 in the preset communication protocol, half of the bit period is used as the signal duration threshold for judging binary 0 and binary 1, when the signal duration of the pulse is less than the signal duration of the reset head signal, it is determined that the pulse width corresponding to binary 1 is greater than the pulse width corresponding to binary 0, and the interference of the reset head signal on the judgment of each data bit is eliminated.
[0008] Further, when executing step A6, the timer is controlled to time the width of the first level between two consecutive rising edges received by the receiving end within the bit period, and output the duration of the signal to be identified; then the bit period is controlled to subtract the duration of the signal to be identified to obtain a preset signal duration, wherein the preset signal duration represents the width of the second level between two consecutive rising edges received by the receiving end; or the timer is controlled to time the width of the second level between two consecutive rising edges received by the receiving end within the bit period, and output the duration of the signal to be identified; within the bit period, if the duration of the signal to be identified is less than the preset signal duration, the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the first data bit, otherwise the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the second data bit; wherein, the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is the periodic signal where the pulse is located. In summary, the data bit to be parsed is determined to be binary 1 or binary 0 according to the relative size between the first level signal duration (width) and the second level signal duration (width) within the bit period. Therefore, the decoding method of the data signal received by a single receiving end is easy to implement in software, reducing the chip selection cost.
[0009] Furthermore, the bit period of a data bit is equal to 1000us; the signal duration of the reset header signal is greater than or equal to 4000us; if the duration of the signal to be identified is equal to 200us, and the duration of the preset signal is equal to 800us, the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the first data bit; if the duration of the signal to be identified is equal to 800us, and the duration of the preset signal is equal to 200us, the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the second data bit. Based on the bit period being set to 1ms, the first data bit and the second data bit are parsed respectively according to the two level duty ratios of 200us / 800us and 800us / 200us, and the logic level format of the first data bit and the logic level format of the second data bit are defined by using a unipolar return-to-zero code, and the receiving controller completes communication decoding by detecting the signal duration of the pulse received by the receiving end, and the software is relatively easy to implement and the code volume is small.
[0010] Furthermore, before executing step A1, the receiving end is pulled up to the first level, and it is determined that the receiving end is not connected to the transmitting end; until the level at the receiving end is pulled down from the first level to the second level by the transmitting end, step A1 is executed to enter the idle state, and it is determined that the receiving end is connected to the transmitting end; in step A1, if the receiving end is awakened, step A2 is executed. Therefore, in order to realize the physical connection detection function of a single communication port, this embodiment adds a pull-up resistor on the communication line between the transmitting end and the receiving end, and determines the connection and disconnection of the transceiver ports of the communicating devices by detecting the level change at the receiving end, without using devices such as Hall, and without additional cost.
[0011] A data transmission method based on signal duration, the data transmission method includes: sending a reset header signal to a receiving end through a transmitting end; wherein the device where the transmitting end is located is different from the device where the receiving end is located; the transmitting end converts each data bit in the data packet to be sent and successively sends out a first level of a first preset signal duration and a second level of a second preset signal duration according to a preset communication protocol, until the transmitting end sends all data bits in the data packet to be sent. Based on this, the data transmission method disclosed in the present application first sends a reset header signal to start converting data bits and sending the corresponding combination of the first level and the second level bit by bit, so as to realize the sending of a complete frame of data packets, and the software is relatively easy to implement and the amount of code is small; in the implementation of the hardware circuit, the data transmission method uses a transmitting end to convert different first level and second level signal duration information according to different data bits, so as to convert the first level and second level combination of the corresponding signal duration bit by bit according to the agreed communication protocol, which can reduce the chip pin design cost, is suitable for the communication scenario of multiple microcontrollers, and also solves the bus communication problem between controllers that do not have specific communication interfaces.
[0012] Further, the data sending method specifically includes: step B1, the sending end enters an idle state, and then executes step B2; step B2, judges whether the sending end starts the sending operation, if yes, executes step B3, otherwise executes step B1; step B3, the sending end sends a reset header signal; then executes step B4; wherein, the frame header in the data packet to be sent is correspondingly converted to the reset header signal; step B4, judges whether the number of unsent data bits in the data packet to be sent is a value of 0, if yes, determines that the sending end has completed sending all data bits in the data packet to be sent, and then executes step B1 to wait for the next frame of data packet to be sent; otherwise, executes step B5; step B5, converts a data bit currently sent in the data packet to be sent and successively sends out a first level of a first preset signal duration and a second level of a second preset signal duration, and then controls the number of unsent data bits in the data packet to be sent to be reduced once and updates the number of unsent data bits, and then executes step B4; wherein, a sent data bit is correspondingly converted to a first level of the first preset signal duration and a second level of the second preset signal duration. From steps B1 to B5, it can be seen that the sending controller at the sending end starts from the need to send data, first sends a reset header signal to wake up the device at the receiving end, and then converts the bits and the sending end sequentially outputs a combination of a first level of a first preset signal duration and a second level of a second preset signal duration, thereby simulating the conversion of data bits through software and coordinating the sending operation of a single sending end to send a pulse signal that meets the duration definition of the preset communication protocol. It can complete the level conversion and sending of a single-frame complete data packet, and can also cyclically send the corresponding converted level combination of multiple-frame data packets, so that the device at the receiving end can parse each data bit pulse by pulse according to the signal duration, thereby improving the communication timing and data bit conversion accuracy between the sending end and the receiving end.
[0013] Further, in step B5, the method of converting a data bit currently sent in the data packet to be sent and successively sending out a first level of a first preset signal duration and a second level of a second preset signal duration includes: when the value of a data bit currently sent is a binary 0, the data bit currently sent is converted into a first level of a first preset signal duration and a second level of a second preset signal duration; when the value of a data bit currently sent is a binary 1, the data bit currently sent is converted into a first level of a first-second preset signal duration and a second level of a second-second preset signal duration; wherein the sum of the first-first preset signal duration and the second-first preset signal duration is equal to the bit period, and the sum of the first-second preset signal duration and the second-second preset signal duration is equal to the bit period; wherein the first-first preset signal duration is less than the second-first preset signal duration, and the first-second preset signal duration is greater than or equal to the second-second preset signal duration; wherein the first preset signal duration is the first-first preset signal duration or the first-second preset signal duration; the second preset signal duration is the second-first preset signal duration or the second-second preset signal duration; and the first level is higher than the second level. In summary, according to whether the value of the data bit is binary 1 or binary 0, a combination of a first level with different signal duration (width) and a second level with the corresponding signal duration (width) is converted, so that the sending end uses the signal duration relationship between the first level and the second level sent successively to encode and convert binary 1 and binary 0. Not only is it easy to implement the signal encoding method for the data bit sent by a single sending end in software, but the signal duration timed by the timer set in the single-chip microcomputer can detect data bits of different values and the count value of the counter can be used to detect the quantity characteristics of the sent data bits. It is suitable for communication scenarios in which the communicating parties exchange multi-frame data packets after completing the sending of the reset header signal.
[0014] Furthermore, the reset header signal sent in step B3 is a pulse signal with a signal duration greater than or equal to a preset target number of bit periods, so as to meet the definition of the duration of the frame header in the preset communication protocol.
[0015] Furthermore, in the preset communication protocol, the bit period is equal to 1000us; the signal duration of the reset head signal is greater than or equal to 4000us; the first preset signal duration is equal to 200us, and the second preset signal duration is equal to 800us; the first second preset signal duration is equal to 800us, and the second second preset signal duration is equal to 200us; wherein the transmitting end is configured to preferentially send the highest bit data in the data packet. Based on the bit period being set to 1ms, binary 1 and binary 0 are converted according to two level duty ratios of 200us / 800us and 800us / 200us, respectively, to implement the definition of the logic level format of binary 1 and binary 0 using a unipolar return-to-zero code method, so the transmitting controller completes the communication encoding by detecting the signal duration of the pulse sent by the transmitting end, and the software is relatively easy to implement, and the amount of code is small.
[0016] Furthermore, before executing step B1, the transmitting end is configured to be at the second level, and after the device where the transmitting end is located is connected to the device where the receiving end is located, step B1 is executed to enter the idle state; in step B1, if the device where the transmitting end is located is awakened, step B2 is executed. Therefore, in order to realize the physical connection detection function of a single communication port, a pull-up resistor is added to the communication line between the transmitting end and the receiving end, and the connection and disconnection between the transmitting end and the receiving end of the communicating devices are determined by detecting the level change at the receiving end, without using devices such as Hall, and without additional cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of signal waveforms of a binary 0 symbol format and a binary 1 symbol format are respectively defined in a unipolar return-to-zero code manner in an embodiment of the present application.
[0018] Figure 2 A waveform diagram of a reset head signal is disclosed as an embodiment of the present application.
[0019] Figure 3 A flowchart of a data receiving method based on signal duration is disclosed for an embodiment of the present application.
[0020] Figure 4 A flowchart of a data sending method based on signal duration is disclosed for an embodiment of the present application.
[0021] Figure 5 A connection diagram of two devices communicating with each other using a receiving end and a transmitting end is disclosed for one embodiment of the present application. DETAILED DESCRIPTION
[0022] The specific implementation of the present application will be further described below in conjunction with the accompanying drawings.
[0023] In application scenarios involving multiple microcontroller communications, industry professionals use a variety of single-wire bus protocols to build communication platforms in software practice in order to establish signal connections between components. They may use pins with multiple complex functions and rely on peripheral resources to complete the transmission and parsing of the protocol, which places certain requirements on microcontroller performance and is difficult to develop. For example, currently the small home appliance industry generally uses 51-core microcontrollers for application development. This type of microcontroller has few peripheral resources, usually only one hardware asynchronous transceiver or even a chip with only input and output pins, which is at a great disadvantage in application scenarios involving multiple microcontroller communications.
[0024] In a split application scenario, the transmitter and receiver are set in two devices respectively. The two devices that establish communication usually detect each other's access status in low power mode. Figure 5 In the illustrated embodiment, the first device and the second device can work independently of each other. After the first device and the second device are connected together, data can be exchanged. When full-duplex communication is established between the first device and the second device, two communication lines are used.
[0025] Two communication lines are used for full-duplex communication, which are not shown in the figure. The transmitting end TX of the first device is connected to the receiving end RX of the second device, and the transmitting end RX of the first device is connected to the receiving end TX of the second device. The first device and the second device can both be understood as hosts. It depends on the actual situation. If only the first device needs to send to the second device, or only the second device needs to send to the first device, only one communication line is used; if both parties need to send and receive, two communication lines are required.
[0026] The data receiving method and data sending method based on signal duration disclosed in the present application are applicable to a hardware system composed of at least two controllers, which communicate according to the same protocol. Each controller has at least one counter and one timer inside or on the periphery, which can be a hardware device or a functional device simulated by software; the counter is used to count the number of transmitted data bits to determine whether the transmission is completed; the timer is used to send a timing interrupt or to time the signal duration of a high-level signal and a low-level signal when receiving data.
[0027] On the connecting line, such as Figure 5 As shown, the transmitting end TX of the first device is connected to the receiving end RX of the second device, the transmitting end TX of the first device is connected to the receiving end RX of the second device, and the receiving end RX of the second device is connected to the power supply VCC through a pull-up resistor Rv.
[0028] The present application discloses a data receiving method based on signal duration. The execution subject of the data receiving method is a receiving device or a receiving controller, specifically involving its receiving end, which is used to receive data sent by a sending end.
[0029] The data receiving method comprises the following steps: Detect the signal received by the receiving end; wherein, a frame of data packet consists of a frame header and multiple data bits, and a frame of data packet is equivalent to a data frame with a predetermined data transmission format, specifically including a frame header, address data and check data; after the receiving controller connected to the receiving end receives the corresponding signal, it must first decode / parse / unpack it before identifying the actual valid data.
[0030] In order to synchronize the decoding signal, the transmitting end first sends a sufficiently long pulse signal (high level greater than 3 bit periods, i.e. 4ms) before sending the actual valid data, which is used to act as a frame header and a reset header signal. Based on this, the receiving end can only parse the actual valid data after receiving the reset header signal. Therefore, it is necessary to first detect the reset header signal received by the receiving end.
[0031] It is worth noting that in the event of signal interference, the reset head signal may be detected twice in succession. Therefore, when detecting the reset head signal, the reset head signal and the pulse signal corresponding to the data bit will also be distinguished to avoid detecting the pulse signal corresponding to the data bit by default and starting the parsing operation after the reset head signal is detected for the first time. If the reset head signal is always detected or no reset head signal is detected, the pulse signal corresponding to the data bit cannot be detected and parsed.
[0032] In the process of detecting the signal received by the receiving end, if the signal duration of the pulse detected for the first time does not meet the definition of the frame header duration of the preset communication protocol, the signal duration of the pulse received by the receiving end continues to be detected; until the detected signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol. It should be noted that the pulse is a high-level signal that occupies a certain duration in the signal corresponding to the entire data packet, specifically a high level between two consecutive rising edges; wherein the signal duration of the pulse represents the total time for the receiving end to flip from a low level to a high level, and then from a high level to a low level. The signal duration of the pulse can be obtained by timing with a timer, that is, the pulse width is obtained by timing; the number of data bits corresponding to the pulse can be counted by a counter to obtain the number of data bits appearing in a data packet.
[0033] If the signal duration of the pulse meets the frame header duration definition of the preset communication protocol, the receiving end receives a reset header signal, which can be regarded as receiving the frame header or reset signal of a data packet, so that the signal received by the receiving end is synchronized in timing with the signal sent by the sending end, and starts to parse each bit of data. Then, if the signal duration of the pulse does not meet the frame header duration definition of the preset communication protocol, the received signal is parsed into data bits according to the signal duration until a frame of data packet is parsed. It is worth noting that after receiving the reset header signal, the receiving end does not parse the reset header signal, but parses the periodic signal of the pulse whose signal duration does not meet the frame header duration definition of the preset communication protocol, wherein the periodic signal of the pulse is a signal sequence converted from a single data bit (one bit of data), including at least one high level and one low level, and the signal duration (pulse width) of the high level is not necessarily equal to the signal duration (pulse width) of the low level; the signal duration (pulse width) of the high level in the reset header signal must be greater than the signal duration (pulse width) of its low level, and the signal duration (pulse width) of the high level in the reset header signal is greater than the signal duration (pulse width) of the high level converted from a single data bit, so as to distinguish the frame header from the data bit.
[0034] The operation of parsing the signal received by the receiving end according to the signal duration in the present application is determined according to the content of the preset communication protocol. The analysis here includes: performing signal analysis according to the format of the logic level of the communication signal, or designing other data transmission formats according to specific circumstances; in fact, there will be differences due to the specific meaning of the bytes, which will involve the difference in the number of bytes of address data and check data, which can be used to distinguish the type of data packet or data frame or data bit.
[0035] Whether receiving the reset header signal or parsing the data bit, the receiving end is sampled by triggering an interrupt through a timer. Every time a high pulse width is collected (i.e., the total time for the receiving end to change from a low level to a high level and then from a high level to a low level), a symbol judgment is performed. If the signal duration (pulse width) of the pulse meets the definition of the frame header duration of the preset communication protocol, the reset header signal is received. If the signal duration (pulse width) of the pulse is less than the pulse width of the reset header signal, the real-time received pulse can be parsed into a data bit based on the signal duration. In this way, the communication effect equivalent to a single bus is achieved through software timed interrupt sampling detection and parsing of pulse width.
[0036] Based on this, the data receiving method disclosed in the present application first determines the reset header signal according to the pulse whose signal duration meets the frame header duration definition of the preset communication protocol to start parsing the data bit, and then parses the pulse bit by bit by detecting the signal duration of the pulse at the receiving end, so as to achieve cyclic parsing of multiple pulses according to the signal duration to obtain a complete frame of data packet when the pulses received twice successively meet the frame header duration definition of the preset communication protocol and do not meet the frame header duration definition of the preset communication protocol respectively. The software is relatively easy to implement and the amount of code is small; in the implementation of the hardware circuit, the data receiving method uses a receiving end to parse the received pulses according to the timing information, so as to parse out a frame of data packet pulse by pulse according to the agreed communication protocol, which can reduce the chip selection cost, is suitable for communication scenarios of multiple microcontrollers, and solves the single-bus communication problem between single-chip microcomputers that do not have specific communication interfaces.
[0037] As an example, Figure 3 As shown, the data receiving method specifically includes: Step A1, the receiving end enters the idle state, and then executes step A2; when the receiving end is in the idle state, the receiving controller is deemed to be in the idle state, the timer is reset to initialize the timing value, and the timing of the pulse signal duration is stopped; at the same time, the counter is reset to initialize the counting value, and the number of parsed data bits is stopped; at the same time, the receiving end is currently deemed to have not received the reset header signal. When the receiving end or the device where it is located is awakened, step A2 is executed to start receiving data.
[0038] It should be noted that the signal duration of the pulse is obtained by timing the width of the first level between two rising edges received continuously by the receiving end using a timer; the number of data bits is obtained by counting the number of data bits using a counter. The pulse can be regarded as including the first level between two rising edges received continuously by the receiving end; or the high level part of the pulse is the first level between two rising edges received continuously by the receiving end.
[0039] Step A2, detect the signal duration of the pulse received by the receiving end, and then execute step A3. In step A2, the receiving controller performs a symbol judgment every time it detects the signal duration of a pulse collected by the receiving end (i.e., the total time for the receiving end to change from a low level to a high level and then from a high level to a low level), and specifically identifies the reset head signal and various data bits (including binary 0 and binary 1) based on the relationship between the signal duration of a pulse currently collected and the relevant signal duration threshold, and the relevant signal duration threshold meets the definition of duration in the preset communication protocol.
[0040] Starting from step A2, the timer is controlled to time the pulse received by the receiving end in an interrupt-triggered manner; in the process of the receiving end receiving the pulse, the timer triggers an interrupt program every time it times a unit timing cycle, performs a timing operation, and obtains a timing value; the corresponding timing value is accumulated and calculated during the duration of the high level until the receiving end receives the second level. It should be noted that the first level is a high level and the second level is a low level.
[0041] Schematically, the receiving end receives a pulse with a high level of 500us, and the timer triggers an interrupt timing every 100us. Then, the receiving end samples the high level every 100us, and the timing value is automatically increased by one until the receiving end samples a low level, and the cumulative timing value of the high level signal duration is equal to the value 5. At this time, the receiving controller configures the high level signal duration to be equal to the product of the cumulative timing value of the high level signal duration and 100us; then the timing value of the trigger timer is cleared, and the receiving end waits for the next pulse to be received, and then starts timing the high level.
[0042] Step A3: determine whether the signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol. If yes, execute step A4; otherwise, execute step A5.
[0043] In order to facilitate the receiving end to synchronously decode the signal and parse the data bits bit by bit from the signal corresponding to the data packet sent from the sending end, step A3 determines whether the latest received pulse belongs to the reset header signal through the frame header duration definition of the preset communication protocol, which is also understood as the frame header signal; in the serial communication understood by technical personnel in this field, the frame header is the start bit, which neither represents data bit 0 nor data bit 1, but only represents the beginning of a frame of data packet currently received.
[0044] Preferably, the frame header duration definition of the preset communication protocol stipulates that a pulse signal greater than 3 bit periods (i.e., a signal duration of 4ms) serves as a reset header signal, and is configured before the actual data bits of a frame of data packets, so that the transmitter sends the reset header signal first, and the receiver receives the same reset header signal first. Based on the frame header duration definition of the preset communication protocol, the signal duration of the reset header signal is greater than at least one bit period (the signal duration of the periodic signal corresponding to the conversion of a single data bit (also understood as a code element period of one bit), including the high level width and the low level width).
[0045] Step A4: If the pulse received by the receiving end belongs to a reset header signal, it is determined that the receiving end has received the reset header signal, and then step A2 is executed; wherein the frame header of a frame of data packet is used to convert and output as the reset header signal. Specifically, the receiving controller times the pulse received by the receiving end through a timer, and when the high-level duration of the pulse (i.e., the total time for the receiving end to change from a low level to a high level and then from a high level to a low level) meets the definition of the frame header duration of the preset communication protocol, it is determined that the receiving end has received the reset header signal.
[0046] In some embodiments, when the receiving end receives the reset head signal, the level signal of the receiving end changes from a low level to a high level, thereby waking up the device where the receiving end is located. After the device where the receiving end is located wakes up, it starts to parse the communication signal by executing step A6.
[0047] Step A5, determine whether the receiving end received a reset header signal last time, if yes, execute step A6, otherwise execute step A2; specifically, if the currently executed step A3 determines that the signal duration of the pulse does not meet the definition of the frame header duration of the preset communication protocol, jump to step A5, and determine whether the receiving end has received a reset header signal before re-entering the initial state. If the reset header signal has been received, enter step A6 to start parsing the data bit. If the reset header signal has not been received, enter step A2 to keep detecting the signal duration of the pulse received by the receiving end.
[0048] Step A6: parse the data bits according to the pulse signal duration, and count the parsed data bits, that is, parse the signal waveform received by the receiving end according to the pulse width, parse the duration definition of each data bit according to the preset communication protocol, and use a counter to count the number of parsed data bits. Then execute step A7.
[0049] When executing step A6, the timer counts the high level width of the pulse (the high level width between two consecutive rising edges, i.e., the pulse width) in an interrupt-triggered manner, and the timer counts the accumulated result of the timing value to obtain the signal duration of the pulse, and then, based on the preset communication protocol for the duration definition of each data bit, parses the binary 1 or binary 0 from the signal waveform received by the receiving end within a bit period; specifically, the relevant signal duration threshold is set for identification according to the logical level format of the received and sent data defined in the protocol content, wherein the logical level format of the received and sent data is used to encode and represent a specific information, so that the receiving controller can perform functional operation or communication response to it. At the same time, each time a binary 1 or binary 0 is identified, the timer is controlled to count once; the counter counts the number of data bits received by the receiving end to know the number of data bits received. Therefore, the number of data bits included in a complete frame of data packets is equal to the total number of binary 1s and binary 0s that are cumulatively identified.
[0050] It is worth noting that in the case where the reset header signal has been received, after step A5 determines that the receiving end has received the reset header signal, it does not parse the reset header signal, but instead enters step A6 to parse the periodic signal of the pulse whose signal duration does not meet the frame header duration definition of the preset communication protocol, so as to parse out the data bits that are behind the frame header address.
[0051] Step A7, determine whether the number of data bits counted in step A6 reaches the preset number, if yes, parse out a frame of data packet, and then notify the application layer in the receiving controller to process the business logic, then the receiving controller restores the data sent by the sender according to the protocol content, specifically, the data bits parsed in step A6 are orderly organized into a group of data according to the data transmission format of the receiving and sending data defined in the protocol content, and the meaning and transmission format of each bit of data are identified according to the application requirements, and the receiving controller will call part or all of the data of the frame of data packet according to the application requirements; then the receiving controller will reset the decoding state, and then execute step A1 to re-enter the idle state or low power mode, and then start parsing the next frame of data packet after waking up, otherwise execute step A2 to continue to detect the pulse corresponding to the next data bit. Schematically, it is defined that each frame of data packet is composed of 3 bytes of data, and the preset number is equal to 24. Then after the receiving end receives the reset header signal, after parsing 3*8=24 data bits (binary 0 or binary 1) bit by bit, it is considered that a complete frame of data packet is parsed.
[0052] In summary, when the signal duration of the pulse received by the receiving end does not meet the frame header duration definition of the preset communication protocol, the receiving controller parses each data bit according to the signal duration pulse by pulse, and implements cyclic parsing of high pulse width data until enough data bits are parsed, and it is considered that a complete frame of data packet is parsed.
[0053] In step A3, the method for determining whether the signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol includes: determining whether the signal duration of the pulse is greater than or equal to a preset target number of bit periods, if yes, determining that the signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol, the receiving end receives the reset header signal, and the receiving end begins to prepare to receive data bits of each bit. Otherwise, determining that the signal duration of the pulse does not meet the definition of the frame header duration of the preset communication protocol, the receiving end does not receive the reset header signal.
[0054] Based on the definition of the frame header duration of the preset communication protocol, the preset target number is equal to the value 4; the bit period is preferably 1ms, such as Figure 2 As shown, when the signal duration of the pulse is greater than or equal to 4ms, it is determined that the receiving end has received the reset header signal shown in the figure. The signal duration between the rising edge and the falling edge of the reset header signal shown in the figure is greater than or equal to 4ms, that is, the high pulse width duration is greater than or equal to 4ms, which meets the signal duration definition of the frame header in the protocol.
[0055] Preferably, the receiving controller triggers an interrupt at each rising edge and falling edge of the reset header signal, and the signal duration between adjacent rising edges and falling edges represents a reset header signal.
[0056] In step A6, the method for parsing data bits according to the signal duration of a pulse includes: when executing step A6, determining that the signal duration of the pulse is less than the signal duration of the reset head signal, that is, the receiving end has not currently received the reset head signal, and has begun to receive pulses corresponding to each data bit. Then determine whether the signal duration of the pulse is less than half of the bit period, if so, parse the periodic signal where the pulse is located into the first data bit, otherwise parse the periodic signal where the pulse is located into the second data bit; wherein the value of the first data bit is binary 0, and the value of the second data bit is binary 1; the bit period is represented by the total width of all levels converted from a data bit, that is, one bit period represents the signal duration of one data bit, and the signal duration of one data bit is obtained by adding the signal duration (level width) of the high level to the signal duration (level width) of the low level. Therefore, based on the definition of the duration of binary 0 and binary 1 in the preset communication protocol, half of the bit period is used as the signal duration threshold for judging binary 0 and binary 1. When the signal duration of the pulse is less than the signal duration of the reset head signal, it is determined that the pulse width corresponding to binary 1 is greater than the pulse width corresponding to binary 0, and the interference of the reset head signal on the judgment of each data bit is eliminated.
[0057] It should be noted that after the receiving controller wakes up from the low-power mode, it establishes a connection with the transmitting end in the idle state and can exchange data; it takes some time to go from the idle state to the normal data parsing through chip initialization and other operations, so the signal duration defined by the reset header signal is set to be relatively large, for example, greater than or equal to 4ms, and the time span spans step A2 to step A5.
[0058] When executing the step A6, in order to time the high-level signal duration and the low-level signal duration corresponding to the same data bit, the control timer is controlled to time the width of the first level between two consecutive rising edges received by the receiving end within the bit period, and output the duration of the signal to be identified as the signal duration of the pulse to be timed, which is equal to the high-level signal duration; Then, the bit period is controlled to subtract the duration of the signal to be identified, and a preset signal duration is obtained, which is equal to the signal duration of the low level; wherein the preset signal duration represents the width of the second level between two consecutive rising edges received by the receiving end; the first level represents a high level, and the second level represents a low level. Alternatively, the timer is controlled to time the width of the second level between two consecutive rising edges received by the receiving end within the bit period, and output the preset signal duration; it should be noted that each pulse received by the receiving end and the second level at its falling edge constitute a bit signal, and the signal duration of the bit signal is equal to the sum of the duration of the signal to be identified and the preset signal duration.
[0059] Within the bit period, if the duration of the signal to be identified is less than the preset signal duration, the signal consisting of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the first data bit, and a binary 0 of one bit is identified; otherwise, the signal consisting of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the second data bit, that is, when the duration of the signal to be identified is greater than or equal to the preset signal duration, a binary 1 of one bit is identified.
[0060] It should be noted that the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is the periodic signal of the pulse, indicating the periodic signal converted corresponding to binary 0 or the periodic signal converted corresponding to binary 1; the signal duration of the periodic signal converted corresponding to binary 0 is equal to the signal duration of the periodic signal converted corresponding to binary 1, and both are equal to the bit period.
[0061] In summary, the data bit to be parsed is determined to be binary 1 or binary 0 according to the relative size between the first level signal duration (width) and the second level signal duration (width) within the bit period. Therefore, the decoding method of the data signal received by a single receiving end is easy to implement in software, reducing the chip selection cost.
[0062] In the embodiment of the definition of the logic level format of the preset communication protocol, as shown in FIG. Figure 1 As shown, the bit period of one data bit is equal to 1000us; the signal duration of the reset header signal is greater than or equal to 4000us; preferably, it is stipulated that 1 byte is composed of 8 bits of data, and the receiving end preferentially receives the highest bit of data; the symbol period of each bit of data is 1000us, that is, the bit period of one data bit is equal to 1000us, which corresponds to Figure 1 The time interval between two adjacent rising edges.
[0063] It is worth noting that the receiving end RX is at a high level in the idle state, that is, Figure 1 No pulses are received and Figure 2 Before receiving any pulse, it is pulled up to high level.
[0064] If the duration of the signal to be identified is equal to 200us, and the duration of the preset signal is equal to 800us, that is, the duration of the high level received first in the bit period is equal to 200us, and the duration of the low level received later is equal to 800us, then the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is interpreted as the first data bit, that is, interpreted as Figure 1 As shown in bit 0, a combination of a high level of 200us and a low level of 800us is specified to represent a binary 0.
[0065] If the duration of the signal to be identified is equal to 800us, and the duration of the preset signal is equal to 200us, that is, the duration of the high level received first in the bit period is equal to 800us, and the duration of the low level received later is equal to 200us, then the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the second data bit, that is, parsed as Figure 1 As shown in bit 1, a combination of a high level of 800us and a low level of 200us is specified to represent a binary 1.
[0066] based on Figure 1 The prescribed bit period is set to 1ms, and the first data bit and the second data bit are parsed out according to two level duty ratios of 200us / 800us and 800us / 200us respectively, so as to define the logic level format of the first data bit and the logic level format of the second data bit using a unipolar return-to-zero code. Moreover, the receiving controller completes communication decoding by detecting the signal duration of the pulse received by the receiving end. The software is relatively easy to implement and the amount of code is small.
[0067] Although the bit period is set to 1000 us in some embodiments, bit periods of other signal durations may be set according to specific needs, and other duty cycles may be set according to specific needs.
[0068] like Figure 5 As shown, a transmitter TX is set in the first device, and a receiver RX is set in the second device. The transmitter TX is connected to the receiver RX using a communication line. Either the first device or the second device can act as a host (sender) and be configured according to actual conditions. If only the first device needs to send to the second device, or only the second device needs to send to the first device, only one communication line is used. If both parties need to send and receive, two communication lines are required.
[0069] When the first device is configured as a host device and the second device is configured as a slave device, the first device is used to send a data packet to the second device, wherein the data packet sent by the sending end is converted into a pulse signal or a level signal of various durations and then transmitted to the second device through a communication line. After receiving the pulse signal or the level signal of various durations, the second device parses it into a frame header and each data bit.
[0070] exist Figure 5 In the communication, both parties need to detect the access status of the other party in the low power mode. Therefore, the receiving end RX of the second device is connected to the power supply VCC through the pull-up resistor Rv in the communication line, and the access status of the other party can be detected based on the level change of the receiving end RX.
[0071] Before executing step A1, the receiving end is pulled up to the first level. In the hardware communication environment, the receiving end is pulled up to the first level by the external pull-up resistor, and it is determined that the receiving end is not connected to the transmitting end. The receiving end is in low power consumption mode and configured as input floating. When the transmitting end is not connected, it is pulled up to a high level by the pull-up resistor. Here, the external pull-up resistor is connected to the receiving end; corresponding to Figure 5 When the receiving end RX is in the low power consumption mode, the receiving end RX is configured as an input floating and is pulled up to a high level by the pull-up resistor Rv. The first level is a high level, which is close to the power supply, and the power supply voltage of the power supply is between 3V and 5V.
[0072] Until the level at the receiving end is pulled down from the first level to the second level by the transmitting end, step A1 is executed to enter the idle state; when executing step A1, the receiving controller enters the idle state, determines that the receiving end is connected to the transmitting end, and there is no data interaction between the receiving end and the transmitting end temporarily, but triggers the port interrupt, generates an edge interrupt, and starts to wake up the receiving controller to receive data through the receiving end. Therefore, in the idle state, the receiving end and its device or the receiving controller connected to the receiving end are awakened to start receiving data, and then step A2 is executed. Therefore, in order to realize the physical connection detection function of a single communication port, this embodiment adds a pull-up resistor to the communication line between the transmitting end and the receiving end, and determines the connection and disconnection of the transceiver ports of the communicating devices by detecting the level change at the receiving end, without using devices such as Hall, and without additional cost.
[0073] The transmitting end TX is not connected to the receiving end RX, both the transmitting end TX and the receiving end RX are in low power consumption mode, the transmitting end TX maintains a low level, and when the receiving end RX is pulled down to a low level by the transmitting end TX, a hardware connection is established between the receiving end and the transmitting end, the receiving end enters an idle state, and can clear and reset the counter and timer. Data communication has not yet started between the receiving end and the transmitting end, at least the receiving end has not received the reset header signal.
[0074] In some embodiments, the device where the transmitter TX is located also has other receivers. The device where the transmitter TX is located and the device where the receiver RX is located (not the same device) are both awakened because their own RX is pulled low. After software filtering, it is considered that both parties have been connected and can communicate.
[0075] The device where the receiving end is located can act as a sending device or a receiving device. Figure 5 It can be understood that when the second device where the receiving end RX is located acts as a receiving device, the first device where the transmitting end TX is located acts as a transmitting device; or, when the second device where the receiving end RX is located acts as a transmitting device, the first device where the transmitting end TX is located acts as a receiving device, and the first device can also be set as a receiving end.
[0076] The second level is a low level, which is close to a ground voltage, and the ground voltage is between 0V and 1V.
[0077] It should be noted that the transmitting end is used to connect to the receiving end through a communication line and send a data packet to the receiving end, so that the receiving end receives the pulse converted corresponding to the data packet and parses out the frame header and each data bit.
[0078] The present application also discloses a data sending method based on signal duration. The executor of the data sending method is a sending device or a sending controller, specifically involving its sending end, which serves as an interrupt port for periodically converting data into a pulse signal according to a preset communication protocol and sending it to the outside.
[0079] The execution time of the data sending method may be before the execution of the data receiving method disclosed in the aforementioned embodiment, or after the execution of the data receiving method disclosed in the aforementioned embodiment.
[0080] The data sending method includes the following steps: The sending controller sends a reset header signal to the receiving end through the sending end; wherein, the device where the sending end is located is different from the device where the receiving end is located, and there is a communication relationship between the two parties, and they are connected by at least one communication line. What the sending end needs to send is a frame of data packets, and a frame of data packets consists of a frame header and multiple data bits; based on the preset communication protocol, the frame header is converted into a reset header signal before it can be sent from the sending end to the receiving end. The reset header signal is a sufficiently long pulse signal (high level is equal to 4 bit cycles, i.e. 4ms), and its signal duration satisfies the time required for the microcontroller to wake up from low power mode and parse data normally.
[0081] The transmitting end or the device where it is located is originally in low power consumption mode, the transmitting end maintains a low level state, and then enters an idle state to initialize the timer and the timer, and waits to be connected to the device where the receiving end is located or awakened by other operations (key, touch, etc.), and when it starts to send data to the receiving end, it first sends the reset header signal to the device where the receiving end is located, so as to wake up the device where the receiving end is located from the low power consumption mode and start decoding synchronization. Among them, after the transmitting end sends the reset header signal to the receiving end, the level signal at the receiving end changes from a low level to a high level, thereby waking up the device where the receiving end is located. After waking up, the device where the receiving end is located continues to parse the communication waveform sent by the transmitting end.
[0082] The transmitting end converts each data bit in the data packet to be sent according to the preset communication protocol and sends out the first level of the first preset signal duration and the second level of the second preset signal duration in sequence, wherein the frame header in the data packet to be sent has been converted into the reset header signal and sent to the receiving end, and the remaining data bits to be sent are the data bits in the actual data frame, each data bit is the first level of the first preset signal duration and the second level of the second preset signal duration, and the first level is sent before the second level, so that the receiving end receives the first level first and then the second level. This bit-by-bit transmission is performed until the transmitting end has sent all the data bits in the data packet to be sent, that is, the transmission of a frame of data packets is completed. The transmitting end restores the low level state and enters the idle state to initialize the timer and the timer, and waits to be connected to the device where the receiving end is located or awakened by other operations (key, touch, etc.), and then starts to send the next frame of data packets to the receiving end.
[0083] The sending controller of the present application converts each data bit that the sending end needs to send and successively sends out the first level of the first preset signal duration and the second level of the second preset signal duration. It is encoded according to the format of the logic level of the communication signal, or other data transmission formats are designed according to the specific situation. Based on the encoding rule, the receiving controller can restore each data bit that the sending end needs to send. Furthermore, based on the definition of signal duration by the preset communication protocol, the signal duration (pulse width) of the first level is not necessarily equal to the signal duration (pulse width) of the second level; the signal duration (pulse width) of the first level in the reset header signal must be greater than the signal duration (pulse width) of its second level, and the signal duration (pulse width) of the first level in the reset header signal is greater than the signal duration (pulse width) of the first level converted corresponding to a single data bit, so as to distinguish the frame header and the data bit.
[0084] Whether sending a reset header signal or sending the first level of the first preset signal duration and the second level of the second preset signal duration, the level width of the sending end can be timed by triggering an interruption through a timer. Each time a high pulse width is sent (i.e., the total time for the receiving end to change from a low level to a high level and then from a high level to a low level), a code element judgment is performed. If the signal duration (pulse width) of the sent pulse meets the definition of the frame header duration of the preset communication protocol, the reset header signal is sent; if the signal duration (pulse width) of the sent pulse / first level is less than the pulse width of the reset header signal, the real-time data bits can be converted into a combination of the first level and the second level of the corresponding signal duration according to the signal duration of each level and sent out in sequence. In this way, the communication effect equivalent to a single bus is achieved by converting data bits and sending high and low levels through software timer interrupts.
[0085] Based on this, the data sending method disclosed in the present application first sends a reset header signal to start converting data bits and sending the corresponding first level and second level combination bit by bit, so as to realize sending a complete frame of data packet. The software is relatively easy to implement and the amount of code is small. In the implementation of the hardware circuit, the data sending method uses a sending end to convert different first level and second level signal duration information according to different data bits, so as to convert the first level and second level combination of the corresponding signal duration one data bit by one according to the agreed communication protocol. This can reduce the chip pin design cost, is suitable for communication scenarios of multiple microcontrollers, and also solves the bus communication problem between controllers that do not have specific communication interfaces.
[0086] As an example, Figure 4 As shown, the data sending method specifically includes: Step B1, the sending end enters the idle state, and then executes step B2; the device where the sending end is located has two working preparation states in the idle state, one is that the device where the sending end is located has been dormant, until the sending end and the receiving end confirm the connection relationship, the key is triggered or other control operations are performed, the device where the sending end is located is awakened, and it is ready to send data to the receiving end and execute step B2; the other is that the device where the sending end is located is not dormant, until the key is triggered or other control operations are performed, the device where the sending end is awakened, and it is ready to send data to the receiving end and execute step B2.
[0087] Step B2, determine whether the sending end starts the sending operation, that is, determine whether the sending end needs to send a data packet. If so, execute step B3, otherwise execute step B1 until the sending end is awakened; the data packet that needs to be sent when the sending end starts the sending operation is recorded as the data packet to be sent; therefore, the sending end will only start the sending operation when there is a data interaction request between the sending end and the receiving end, and at least send a reset header signal to the receiving end first.
[0088] When the sender enters the idle state, the sender and the receiver are both connected and enter the low power mode. After the sender is awakened by other operations (button, touch and other functions), it sends the communication content to the receiver after the judgment in step B2.
[0089] Step B3, the sending end sends a reset header signal, and then executes step B4; wherein, the frame header in the data packet to be sent is converted into a reset header signal; preferably, the frame header duration definition of the preset communication protocol stipulates that a pulse signal greater than 3 bit periods serves as the reset header signal, then the sending end first sends a high-level pulse width signal of 4ms (obtained by the timer triggering the interrupt timing) to the receiving end, so as to wake up the device where the receiving end is located from a low power consumption state and start decoding synchronization, wherein, after the sending end sends the reset header signal to the receiving end, the level signal at the receiving end changes from a low level to a high level, thereby waking up the device where the receiving end is located, and after the device where the receiving end is located wakes up, it parses the communication waveform sent by the sending end.
[0090] Step B4, determine whether the number of unsent data bits in the data packet to be sent is a value of 0. If so, determine that the sending end has completed sending all the data bits in the data packet to be sent, and then execute step B1 to wait for the next frame of data packet to be sent; otherwise, execute step B5; therefore, step B4 is essentially to determine whether the data bits in the data packet to be sent are completely sent. Schematically, it is defined that 3 bytes are sent in each frame, then after sending the reset header signal, 3*8=24 bit signals (binary 0 or binary 1) are sent bit by bit, and the sending controller confirms that the data packet to be sent has been sent.
[0091] The execution basis of the judgment step described in step B4 is to count the number of unsent data bits or the number of sent data bits in the data packet to be sent in real time through a counter. In the case of uncertainty about the number of data bits actually sent, it is possible to more directly determine whether all data bits in the data packet at the sending end have been sent by judging whether the number of unsent data bits in the data packet to be sent is a value of 0.
[0092] After step B4 determines that all data to be sent have been sent bit by bit, step B1 is executed to restore the sending end to an idle state.
[0093] Step B5, converting a data bit currently being sent in the data packet to be sent and sending out the first level of the first preset signal duration and the second level of the second preset signal duration in sequence, then controlling the number of unsent data bits in the data packet to be sent to be reduced once and updating the number of unsent data bits, and then executing step B4; based on the duration definition of the preset communication protocol, the first preset signal duration is not equal to the second preset signal duration, the value of the data bit changes due to the change in the size relationship between the first preset signal duration and the second preset signal duration, and the first level is higher than the second level. Among them, the sent data bit is converted to the first level of the first preset signal duration and the second level of the second preset signal duration.
[0094] In step B5, for each data bit in the data packet sent by the sending end, the first level of the first preset signal duration and the second level of the second preset signal duration are converted, and the counter counts the number of data bits that have been sent by a self-incrementing operation, or counts the number of data bits that have not been sent by a self-decrementing operation so as to determine whether the number of data bits that have not been sent in the data packet to be sent is a value of 0 when executing step B4.
[0095] It should be noted that, when the timer is triggered by an interrupt, each time the transmitting end sends a set of the first level of the first preset signal duration and the second level of the second preset signal duration, that is, the timer successively times the first preset signal duration and the second preset signal duration, it is determined that the transmitting end has sent a data bit, and the bit period is equal to the sum of the first preset signal duration and the second preset signal duration; then the counter can add one to the count value of the data bit that has been sent, and the timer can also subtract one from the count value of the data bit that has not been sent. By timing and counting in this way, the counter can count the number of data bits that have been sent in the data packet to be sent or the number of data bits that have not been sent in the data packet to be sent according to the bit period counted by the timer.
[0096] From steps B1 to B5, it can be seen that the sending controller at the sending end starts from the need to send data, first sends a reset header signal to wake up the device at the receiving end, and then converts the bits and the sending end sequentially outputs a combination of a first level of a first preset signal duration and a second level of a second preset signal duration, thereby simulating the conversion of data bits through software and coordinating the sending operation of a single sending end to send a pulse signal that meets the duration definition of the preset communication protocol. It can complete the level conversion and sending of a single-frame complete data packet, and can also cyclically send the corresponding converted level combination of multiple-frame data packets, so that the device at the receiving end can parse each data bit pulse by pulse according to the signal duration, thereby improving the communication timing and data bit conversion accuracy between the sending end and the receiving end.
[0097] In step B5, the method of converting a data bit currently being sent in a data packet to be sent and successively sending out a first level of a first preset signal duration and a second level of a second preset signal duration includes: when the value of a data bit currently being sent is binary 0, the sending controller converts a data bit currently being sent into a first level of a first preset signal duration and a second level of a second preset signal duration; when the value of a data bit currently being sent is binary 1, the data bit currently being sent is converted into a first level of a first second preset signal duration and a second level of a second second preset signal duration; in step B5, the first preset signal duration is configured to include the first first preset signal duration and the first second preset signal duration; and the second preset signal duration is configured to be the second first preset signal duration and the second second preset signal duration; the first level is higher than the second level. Specifically, when the value of a data bit currently being sent is binary 0, the first preset signal duration is the first-first preset signal duration, and the second preset signal duration is the second-first preset signal duration; when the value of a data bit currently being sent is binary 1, the first preset signal duration is the first-second preset signal duration, and the second preset signal duration is the second-second preset signal duration; wherein the sum of the first-first preset signal duration and the second-first preset signal duration is equal to the bit period, and the sum of the first-second preset signal duration and the second-second preset signal duration is equal to the bit period; preferably, based on the duration definition of the preset communication protocol, the first-first preset signal duration is equal to the second-second preset signal duration, and the second-first preset signal duration is equal to the first-second preset signal duration.
[0098] It can also be understood that the signal duration of the first level between two consecutive rising edges is equal to the first preset signal duration, the signal duration of the second level between two consecutive rising edges is equal to the second preset signal duration, the first level of the first preset signal duration and the second level of the second preset signal duration are periodic signals converted corresponding to the data bits, indicating the periodic signal converted corresponding to binary 0 or the periodic signal converted corresponding to binary 1.
[0099] For the conversion result of binary 0, the first preset signal duration is less than the second preset signal duration; for the conversion result of binary 1, the first second preset signal duration is greater than the second second preset signal duration. Wherein, the first level is higher than the second level, the first level is regarded as a high level, and the second level is regarded as a low level.
[0100] It should be noted that, according to the provisions of the preset communication protocol for the same data bit, each data bit to be transmitted is represented by two continuous square wave signals / pulses / rising edge signals and sent out by the transmitting end, and the level state of a square wave signal currently sent is always different from the level state of the previous square wave signal. If the value of the data bit to be sent is binary 0, the duration of the high level state actually output by the transmitting end (the first preset signal duration) is less than the duration of the low level state (the second preset signal duration); if the value of the data bit to be sent is binary 1, the duration of the high level state actually output by the transmitting end (the first second preset signal duration) is greater than or equal to the duration of the low level state (the second second preset signal duration).
[0101] In summary, according to whether the value of the data bit is binary 1 or binary 0, a combination of a first level with different signal duration (width) and a second level with the corresponding signal duration (width) is converted, so that the sending end uses the signal duration relationship between the first level and the second level sent successively to encode and convert binary 1 and binary 0. Not only is it easy to implement the signal encoding method for the data bit sent by a single sending end in software, but the signal duration timed by the timer set in the single-chip microcomputer can detect data bits of different values and the count value of the counter can be used to detect the quantity characteristics of the sent data bits. It is suitable for communication scenarios in which the communicating parties exchange multi-frame data packets after completing the sending of the reset header signal.
[0102] In some embodiments, the reset header signal sent in step B3 is a pulse signal with a signal duration greater than or equal to a preset target number of bit periods, so as to meet the preset communication protocol for the duration definition of the frame header; wherein the preset target number is equal to a value of 4. By sending the reset header signal to the ground terminal, the transmitting end not only reserves data transmission preparation time for each data bit to be sent by the transmitting end, but also allows the receiving end to receive the reset header signal to wake up the receiving end to start preparing to receive each bit of data. Of course, based on the definition of the frame header duration of the preset communication protocol, the reset header signal is a sufficiently long pulse signal (high level is equal to 4 bit periods, i.e. 4ms), and its signal duration meets the time required for the microcontroller to wake up from the low power mode to be able to parse data normally (after the wake-up time, chip initialization and other operations), so that the time consumed from the transmitting end sending the reset header signal to the receiving end receiving the reset header signal allows the device where the receiving end is located to wake up from the low power mode to be able to parse data normally (including operations such as waking up the controller and chip initialization during the period).
[0103] In some embodiments, in the preset communication protocol, the bit period is equal to 1000us; the signal duration of the reset header signal is greater than or equal to 4000us; preferably, 1 byte is composed of 8 bits of data; the transmitting end is configured to give priority to sending the highest bit data in the data packet. The symbol period of each bit of data is 1000us, that is, the bit period of a data bit is equal to 1000us, which is equal to Figure 1 The time interval between two adjacent rising edges.
[0104] In the embodiment of the definition of the logic level format of the preset communication protocol, the first preset signal duration is equal to 200us, the second preset signal duration is equal to 800us; the first second preset signal duration is equal to 800us, the second second preset signal duration is equal to 200us. Figure 1 It can be seen that if the transmitting end first outputs a high level for 200us and then outputs a low level for 800us, the value of the currently transmitted data bit is binary 0, which is interpreted as Figure 1 The bit 0 shown in FIG. 1 is a binary bit 1, which specifies a combination of a high level of 200 us and a low level of 800 us to represent a binary 0. If the transmitting end first outputs a high level of 800 us and then outputs a low level of 200 us, the value of the currently transmitted data bit is a binary 1, which is interpreted as Figure 1 As shown in bit 1, a combination of a high level of 800us and a low level of 200us is specified to represent a binary 1. It is worth noting that the transmitting end TX is at a low level in an idle state.
[0105] based on Figure 1 The specified bit period is set to 1ms, and binary 1 and binary 0 are converted according to two level duty cycles of 200us / 800us and 800us / 200us respectively, to define the logic level format of binary 1 and binary 0 using a unipolar return-to-zero code. Therefore, the sending controller completes the communication encoding by detecting the signal duration of the pulse sent by the sending end. The software is relatively easy to implement and the amount of code is small.
[0106] Although the bit period is set to 1000 us in some embodiments, bit periods of other signal durations may be set according to specific needs, and other duty cycles may be set according to specific needs.
[0107] Before executing step B1, the transmitting end is configured to be at the second level. The device where the transmitting end is located may be in a dormant state, waiting to be awakened, and is not connected to the device where the transmitting end is located. Therefore, the device where the transmitting end is located can be regarded as being in a low-power mode, and the aforementioned sending process is suspended. After the device where the transmitting end is located is connected to the device where the receiving end is located, step B1 is executed to enter the idle state. The transmitting end is in an idle state and may still be in a dormant state until it is awakened by a key or other control operation. There is no data communication between the transmitting end and the receiving end, but the port interrupt of the transmitting end is triggered, an edge interrupt is generated, and the sending controller starts to wake up to send signals through the transmitting end. Therefore, in the idle state, the transmitting end and its device or the sending controller connected to the transmitting end are awakened to start selecting to send data, and then the transmitting end sends data to the receiving end by executing steps B2 to B5; based on this, in step B1, if the device where the transmitting end is located is awakened, step B2 is executed.
[0108] When executing step B1, if the transmitting end remains in an idle state for a period of time, it enters a low power consumption mode and waits for the next wake-up before executing step B2.
[0109] When executing step B1, when the transmitting end is in the idle state, the transmitting end is configured to be at the second level until the receiving end drops from the first level to the second level, so that the receiving end confirms that it has established a connection with the transmitting end, and the transmitting end enters step B2 to determine whether to start sending data to the receiving end. Figure 5 As can be seen from the embodiments related to the aforementioned data receiving method, the communicating parties need to detect the access status of the other party in the low power consumption mode. Therefore, the receiving end RX of the second device is connected to the power supply VCC through the pull-up resistor Rv in the communication line, and the access status of the other party can be detected based on the level change of the receiving end RX. Therefore, in order to realize the physical connection detection function of a single communication port, a pull-up resistor is added to the communication line between the transmitting end and the receiving end, and the connection and disconnection between the transmitting end and the receiving end of the communicating party devices are determined by detecting the level change at the receiving end, without using devices such as Hall, and without additional cost.
[0110] The terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0111] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A data receiving method based on signal duration, characterized in that: The data receiving method includes: Detecting a signal received by a receiving end; If the signal duration of the pulse detected for the first time does not meet the definition of the frame header duration of the preset communication protocol, continue to detect the signal duration of the pulse received by the receiving end; If the signal duration of the pulse meets the frame header duration definition of the preset communication protocol, the receiving end receives a reset header signal; then, if the signal duration of the pulse does not meet the frame header duration definition of the preset communication protocol, the received signal is parsed into data bits according to the signal duration until a frame of data packet is parsed.
2. The data receiving method according to claim 1, characterized in that: The data receiving method specifically comprises: Step A1, the receiving end enters an idle state, and then executes step A2; Step A2, detecting the signal duration of the pulse received by the receiving end, and then executing step A3; Step A3, determining whether the signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol, if yes, executing step A4, otherwise executing step A5; Step A4: The receiving end receives the reset header signal, and then executes step A2; wherein the frame header of a frame of data packet is used to convert and output as the reset header signal; Step A5, determining whether the receiving end received the reset header signal last time, if yes, executing step A6, otherwise executing step A2; Step A6, parsing the data bits according to the signal duration of the pulse, counting the parsed data bits, and then executing step A7; Step A7, determining whether the number of data bits counted in step A6 reaches a preset number, if yes, parse out a frame of data packets, and then execute step A1 to start parsing the next frame of data packets, otherwise, execute step A2; The signal duration of the pulse is obtained by timing the width of the first level between two rising edges continuously received by the receiving end using a timer; and the number of data bits is obtained by counting using a counter.
3. The data receiving method according to claim 2, characterized in that: In step A3, the method for determining whether the signal duration of the pulse meets the definition of the frame header duration of the preset communication protocol includes: Determine whether the signal duration of the pulse is greater than or equal to a preset target number of bit periods. If so, determine that the signal duration of the pulse meets the frame header duration definition of the preset communication protocol; otherwise, determine that the signal duration of the pulse does not meet the frame header duration definition of the preset communication protocol; wherein the preset target number is equal to the value 4.
4. The data receiving method according to claim 2, characterized in that: In step A6, the method of parsing data bits according to the signal duration of the pulse includes: When executing to the step A6, it is determined that the signal duration of the pulse is less than the signal duration of the reset head signal; Then determine whether the signal duration of the pulse is less than half of the bit period, if yes, parse the periodic signal where the pulse is located into the first data bit, otherwise parse the periodic signal where the pulse is located into the second data bit, so as to realize parsing the received signal into the data bit according to the signal duration; wherein the value of the first data bit is binary 0 and the value of the second data bit is binary 1; The bit period is represented by the total width of all levels converted by one data bit.
5. The data receiving method according to claim 4, characterized in that: When executing step A6, the control timer counts the width of the first level between two consecutive rising edges received by the receiving end within the bit period, and outputs the duration of the signal to be identified; Then, the bit period is controlled to subtract the duration of the signal to be identified to obtain a preset signal duration, wherein the preset signal duration represents the width of the second level between two consecutive rising edges received by the receiving end; or a timer is controlled to time the width of the second level between two consecutive rising edges received by the receiving end within the bit period, and output the duration of the signal to be identified; Within the bit period, if the duration of the signal to be identified is less than the preset signal duration, the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the first data bit; otherwise, the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the second data bit; wherein the signal composed of the first level and the second level between two consecutive rising edges received by the receiving end is the periodic signal of the pulse.
6. The data receiving method according to claim 5, characterized in that: The bit period of one data bit is equal to 1000us; the signal duration of the reset head signal is greater than or equal to 4000us; If the duration of the signal to be identified is equal to 200us, and the duration of the preset signal is equal to 800us, a signal consisting of a first level and a second level between two consecutive rising edges received by the receiving end is parsed as a first data bit; If the duration of the signal to be identified is equal to 800us and the duration of the preset signal is equal to 200us, the signal consisting of the first level and the second level between two consecutive rising edges received by the receiving end is parsed as the second data bit.
7. The data receiving method according to claim 2, characterized in that: Before executing step A1, the receiving end is pulled up to a first level, and it is determined that the receiving end is not connected to the transmitting end; until the level at the receiving end is pulled down from the first level to the second level by the transmitting end, step A1 is executed to enter an idle state, and it is determined that the receiving end is connected to the transmitting end; In step A1, if the receiving end is awakened, step A2 is executed.
8. A data transmission method based on signal duration, characterized in that: Data sending methods include: Sending a reset header signal to a receiving end through a sending end; wherein a device where the sending end is located is different from a device where the receiving end is located; The transmitting end converts each data bit in the data packet to be sent according to the preset communication protocol and sends out a first level of a first preset signal duration and a second level of a second preset signal duration in sequence until the transmitting end completes sending all data bits in the data packet to be sent.
9. The data transmission method according to claim 8, characterized in that: The data sending method specifically includes: Step B1, the sending end enters an idle state, and then executes step B2; Step B2, determine whether the sending end starts the sending operation, if yes, execute step B3, otherwise execute step B1; Step B3, the transmitting end sends a reset header signal; then execute step B4; wherein the frame header in the data packet to be sent is correspondingly converted into the reset header signal; Step B4, determining whether the number of unsent data bits in the data packet to be sent is a value of 0, if yes, determining that the transmitting end has completed sending all data bits in the data packet to be sent, and then executing step B1 to wait for sending the next frame of data packet; otherwise, executing step B5; Step B5, converting a data bit currently being sent in the data packet to be sent and sending out a first level of a first preset signal duration and a second level of a second preset signal duration in sequence, then controlling the number of unsent data bits in the data packet to be sent to be reduced once and updating the number of unsent data bits, and then executing step B4; Among them, one data bit sent out is correspondingly converted into a first level of the first preset signal duration and a second level of the second preset signal duration.
10. The data transmission method according to claim 9, characterized in that: In step B5, the method of converting a data bit currently being sent in a data packet to be sent and successively sending a first level of a first preset signal duration and a second level of a second preset signal duration includes: When the value of a data bit currently being sent is binary 0, the data bit currently being sent is converted into a first level of a first preset signal duration and a second level of a second preset signal duration; When the value of a data bit currently being sent is binary 1, the data bit currently being sent is converted into a first level of a first second preset signal duration and a second level of a second second preset signal duration; The sum of the first preset signal duration and the second preset signal duration is equal to the bit period, and the sum of the first second preset signal duration and the second second preset signal duration is equal to the bit period; The first preset signal duration is less than the second preset signal duration, and the first second preset signal duration is greater than or equal to the second second preset signal duration; Among them, the first preset signal duration is the first-first preset signal duration or the first-second preset signal duration; the second preset signal duration is the second-first preset signal duration or the second-second preset signal duration; and the first level is higher than the second level.
11. The data transmission method according to claim 10, characterized in that: The reset header signal sent in step B3 is a pulse signal with a signal duration greater than or equal to a preset target number of bit periods to meet the definition of the duration of the frame header in the preset communication protocol; wherein the preset target number is equal to a value of 4.
12. The data transmission method according to claim 11, characterized in that: In the preset communication protocol, the bit period is equal to 1000us; the signal duration of the reset head signal is greater than or equal to 4000us; The first preset signal duration is equal to 200us, and the second preset signal duration is equal to 800us; The first second preset signal duration is equal to 800us, and the second second preset signal duration is equal to 200us; The transmitting end is configured to preferentially transmit the highest bit data in the data packet.
13. The data transmission method according to claim 10, characterized in that: Before executing step B1, the transmitting end is configured to be at the second level. After the device where the transmitting end is located is connected to the device where the receiving end is located, step B1 is executed to enter the idle state. In step B1, if the device where the transmitting end is located is awakened, step B2 is executed.
Citation Information
Patent Citations
Random code sending control method and random code-based burning control method
CN118041532A