Communication methods, devices, media and systems for general purpose input / output ports
By using duty cycle encoding in general-purpose input/output ports, the problem that GPIO cannot distinguish between information, multiple instructions, and multiple states is solved, enabling bidirectional, multi-instruction, and multi-state data interaction between devices, and improving information transmission capacity and reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GREE ELECTRIC APPLIANCE INC OF ZHUHAI
- Filing Date
- 2026-06-05
- Publication Date
- 2026-07-10
AI Technical Summary
General Purpose Input/Output (GPIO) ports cannot distinguish information or encode multiple instructions and states, resulting in only unidirectional control with low information capacity, and cannot support bidirectional, multi-instruction, and multi-state data interaction.
By using a single signal line for pulse duty cycle encoding between devices, and utilizing a mapping table between duty cycle and communication information, information encoding and decoding are achieved, supporting bidirectional, multi-command, and multi-state data interaction.
It enables bidirectional, multi-instruction, and multi-state data interaction between devices through duty cycle encoding without the need for dedicated hardware, thereby improving information transmission capacity and reliability.
Smart Images

Figure CN122364129A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of data transmission, specifically relating to a communication method, apparatus, medium, and system for a general-purpose input / output port. Background Technology
[0002] In related technologies, general purpose input / output (GPIO) ports can be used to simulate simple timing (such as single-wire switching signals) to achieve data transmission. However, GPIO ports can only achieve unidirectional control with low information capacity. For example, they can be used to start or stop devices based on binary control logic such as high and low levels. Because GPIO ports cannot distinguish information or encode multiple instructions and multiple states, they can only achieve unidirectional control with low information capacity (such as start / stop) and cannot support bidirectional, multi-instruction, and multi-state data interaction. Summary of the Invention
[0003] In view of the above problems, a communication method, apparatus, medium, and system for a universal input / output port are proposed to overcome or at least partially solve the above problems, including: A communication method for a general purpose input / output (GPIO) port, wherein the GPIO port includes a first GPIO port deployed on a first device and a second GPIO port deployed on a second device; the first GPIO port is connected to the second GPIO port via a single signal line, and the first device and the second device store a first mapping table between duty cycle and communication information; the method includes: The first device determines the first communication information to be sent and queries the first mapping table to determine the first duty cycle corresponding to the first communication information; Based on the first duty cycle, the first communication information is encoded into a first pulse signal; The first pulse signal is sent to the second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, and the second device is used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; Receive the second pulse signal and determine the second duty cycle of the second pulse signal; Query the first mapping table to determine the second communication information corresponding to the second duty cycle.
[0004] In some embodiments, the first mapping table includes a mapping relationship between duty cycle tolerance intervals and communication information, and there is no overlap between the various duty cycle tolerance intervals; querying the first mapping table to determine the second communication information corresponding to the second duty cycle includes: Determine the second duty cycle tolerance range to which the second duty cycle belongs; Query the first mapping table to determine the second communication information corresponding to the second duty cycle fault tolerance interval.
[0005] In some embodiments, the second pulse signal includes a plurality of second pulses, and the method further includes: Determine the first number of second pulses that correspond to the second duty cycle fault-tolerant interval; Based on the first quantity, determine whether the second pulse signal is valid.
[0006] In some embodiments, determining whether the second pulse signal is valid based on the first quantity includes: The effective frame ratio is determined based on the first quantity and the total number of the second pulses; Determine the standard deviation of the second pulse that corresponds to the second duty cycle tolerance interval, and determine the signal quality concentration of the second pulse signal based on the standard deviation and the second duty cycle tolerance interval; The validity of the second pulse signal is determined based on the effective frame ratio and the signal quality concentration.
[0007] In some embodiments, the first device further stores a second mapping table between communication information and executed actions, and the method further includes: Query the second mapping table to determine the second execution action corresponding to the second communication information; Perform the second action.
[0008] In some embodiments, the communication information includes instruction information and status information, and the first mapping table includes an instruction mapping table of instruction information and duty cycle, and a status mapping table of status information and duty cycle.
[0009] In some embodiments, the method further includes: Configure the direction register of the first general-purpose input / output port to set the first general-purpose input / output port to output mode to drive the level when the first device sends information to the second device, and to switch the first general-purpose input / output port to input mode to release the bus and read the information when the first device receives information sent by the second device.
[0010] This application embodiment also provides a communication device with a general-purpose input / output port, the general-purpose input / output port including a first general-purpose input / output port deployed on a first device and a second general-purpose input / output port deployed on a second device; the first general-purpose input / output port is connected to the second general-purpose input / output port via a single signal line, and the first device and the second device store a first mapping table between duty cycle and communication information; the device includes: The determination module is used by the first device to determine the first communication information to be sent and to query the first mapping table to determine the first duty cycle corresponding to the first communication information. The encoding module is used to encode the first communication information into a first pulse signal according to the first duty cycle; The transceiver module is used to send the first pulse signal to the second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, and the second device is used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; The parsing module is used to receive the second pulse signal and determine the second duty cycle of the second pulse signal; query the first mapping table to determine the second communication information corresponding to the second duty cycle.
[0011] This application embodiment also provides a communication system based on a general purpose input / output (GPIO) port, wherein the GPIO port includes a first GPIO port deployed on a first device and a second GPIO port deployed on a second device; the first GPIO port is connected to the second GPIO port via a single signal line; the system includes: The hardware initialization and configuration module is used to configure the direction register of the first general-purpose input / output port so that when the first device sends information to the second device, the first general-purpose input / output port is set to output mode to drive the level, and when the first device receives information sent by the second device, the first general-purpose input / output port is switched to input mode to release the bus and read the information. A two-way communication protocol module is designed to generate the first mapping table between duty cycle and communication information; A communication data determination module is used to determine the first communication information to be sent, and query the first mapping table to determine the first duty cycle corresponding to the first communication information; encode the first communication information into a first pulse signal according to the first duty cycle; and send the first pulse signal to the second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, the second device being used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; receive the second pulse signal and determine the second duty cycle of the second pulse signal; and query the first mapping table to determine the second communication information corresponding to the second duty cycle.
[0012] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the communication method of the general input / output port as described above.
[0013] The embodiments of this application have the following advantages: In this embodiment, a first device determines the first communication information to be sent and queries a first mapping table to determine the first duty cycle corresponding to the first communication information; according to the first duty cycle, the first communication information is encoded into a first pulse signal; the first pulse signal is sent to a second device; the second device sends a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent; the second device determines the second duty cycle corresponding to the second communication information according to the first mapping table; receives the second pulse signal and determines the second duty cycle of the second pulse signal; queries the first mapping table to determine the second communication information corresponding to the second duty cycle. Compared to general-purpose input / output ports that can only implement device start / stop based on binary control logic, the device of this application can encode information through different pulse duty cycles, enabling general-purpose input / output ports to transmit more types of information between devices, such as multiple instruction information and multiple status information, thereby achieving the distinction between multiple instructions and multiple states, and thus solving the problem that general-purpose input / output ports cannot distinguish information, multiple instructions, and multiple states.
[0014] In addition, the first device can encode information using different pulse duty cycles, enabling the general-purpose input / output port to transmit more types of information between devices; the second device can also encode information using different pulse duty cycles, enabling the general-purpose input / output port to transmit more types of information between devices; based on this, both the first and second devices can encode different communication information based on duty cycles and perform bidirectional data interaction, thereby enabling the general-purpose input / output port to support bidirectional, multi-command, and multi-state data interaction. Attached Figure Description
[0015] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating the steps of a communication method using a general input / output port according to an embodiment of this application. Figure 2 This is a flowchart of another communication method for a general input / output port according to an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a communication system based on a general-purpose input / output port according to an embodiment of this application; Figure 4 This is a flowchart of a communication system based on a general-purpose input / output port according to an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a communication device with a general-purpose input / output port according to an embodiment of this application. Detailed Implementation
[0016] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0017] In embedded hardware system design, communication between the main controller and functional modules often relies on dedicated serial bus interfaces such as UART (Universal Asynchronous Receiver / Transmitter), I2C (Inter-Integrated Circuit), or SPI (Serial Peripheral Interface).
[0018] While these interfaces can transmit data efficiently, their implementation relies on specific hardware peripheral resources on the microcontroller. This leads to reduced system design flexibility: when selecting a microcontroller, there must be a sufficient number of dedicated communication pins; in multi-module systems, these hardware resources may be quickly exhausted or become a bottleneck in terms of cost and complexity.
[0019] While using general-purpose input / output ports to simulate simple timing sequences eliminates the need for dedicated hardware interfaces and saves pin resources, in practical applications, general-purpose input / output ports cannot distinguish information or encode multiple instructions and states. Therefore, they can only achieve unidirectional, low-capacity control (such as start / stop) and cannot support bidirectional, multi-instruction, and multi-state data interaction.
[0020] To distinguish information and differentiate between multiple instructions and states, enabling general-purpose input / output ports to support bidirectional, multi-instruction, and multi-state data interaction, this application provides a communication method for general-purpose input / output ports. This method can encode information using different pulse duty cycles, thereby enabling reliable, bidirectional, multi-instruction, and multi-state interaction between devices based on a single general-purpose input / output port without requiring any dedicated communication hardware.
[0021] Reference Figure 1 The diagram illustrates a flowchart of a communication method for a general-purpose input / output port according to an embodiment of this application, which may include the following steps: Step 101: The first device determines the first communication information to be sent and queries the first mapping table to determine the first duty cycle corresponding to the first communication information.
[0022] In this embodiment, the general purpose input / output (GPIO) port includes a first GPIO port deployed on a first device and a second GPIO port deployed on a second device; the first GPIO port is connected to the second GPIO port via a single signal line. The first and second devices store a first mapping table between duty cycles and communication information.
[0023] In some embodiments, the first device and the second device can achieve multi-instruction, multi-state, highly reliable all-digital bidirectional communication through only one general-purpose input / output port, thereby eliminating the dependence on dedicated hardware resources such as UART and I2C. For example, the first device and the second device can have only one general-purpose input / output port or multiple general-purpose input / output ports; each general-purpose input / output port can realize bidirectional communication.
[0024] In some embodiments, the first device may store a first mapping table of duty cycle and communication information; the second device may also store a first mapping table of duty cycle and communication information; the first mapping table may store the mapping relationship between duty cycle and communication information, and based on the first mapping table, the duty cycle corresponding to the communication information can be determined, and the communication information corresponding to the duty cycle can also be determined.
[0025] When the first device needs to send information to the second device, it can first determine the first communication information to be sent. For example, the first device and the second device can be one of a master device and a slave device, respectively. When the first device is the master device and the second device is the slave device, the first device can issue a control instruction to the second device, and the first communication information can be instruction information. The second device can also issue a control instruction to the first device.
[0026] When the first device is a slave device and the second device is the master device, the first device can upload the status information of the second device to the second device; that is, the first communication information can be status information. The second device can also upload the status information of the first device to the first device.
[0027] In practical applications, general-purpose input / output ports cannot distinguish information or encode multiple instructions and states. As a result, they can only achieve unidirectional, low-information-capacity control (such as start / stop) and cannot support bidirectional, multi-instruction, and multi-state data interaction.
[0028] In order to distinguish information and differentiate between multiple instructions and multiple states, so that general-purpose input / output ports can support bidirectional, multi-instruction, and multi-state data interaction, this application proposes a bidirectional communication method with single-line pulse width encoding. After determining the first communication information, the first device can query the first mapping table to determine the duty cycle corresponding to the first communication information, i.e., the first duty cycle.
[0029] To ensure unambiguous decoding, the correspondence between communication information and duty cycles in the first mapping table is one-to-one, meaning one duty cycle corresponds to only one piece of communication information. Duty cycle refers to the high-level (on / active) time divided by the entire period of a periodic signal, often expressed as a percentage. The first duty cycle can refer to the unique duty cycle set for the first communication information. This application, through the mapping between duty cycles and communication information, enables encoding to distinguish between multiple instructions and states, and also distinguishes between different information, thereby enabling general-purpose input / output ports to support bidirectional, multi-instruction, and multi-state data interaction.
[0030] For the second device, after determining the second communication information, the second device can also query the first mapping table to determine the duty cycle corresponding to the second communication information, i.e., the second duty cycle.
[0031] Step 102: Encode the first communication information into a first pulse signal according to the first duty cycle.
[0032] After determining the first duty cycle, the first communication information can be encoded into a first pulse signal with a specific duty cycle. This specific duty cycle can be the first duty cycle.
[0033] Step 103: Send the first pulse signal to the second device; the second device is used to send the second pulse signal to the first device. The second pulse signal is obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent.
[0034] After obtaining the first pulse signal, the first general-purpose input / output port can be controlled based on the first pulse signal, and a timer can be used to generate a PWM (Pulse Width Modulation) pulse waveform with a first duty cycle on a single signal line, thereby completing the mapping and physical generation of the analog pulse duty cycle characteristics from digital signals.
[0035] For the second device, after receiving the first pulse signal, it can detect the first pulse signal to determine the first duty cycle of the first pulse signal; then, the second device can determine the communication information corresponding to the first duty cycle as the first communication information; thus, the interaction of complex information is completed.
[0036] In some embodiments, the second device may also send information to the first device; specifically, the first device may, like the second device, first determine the second communication information to be sent.
[0037] After determining the second communication information, in order to distinguish the information, the second device can determine the second duty cycle corresponding to the second communication information. If the first communication information is different from the second communication information, then the first duty cycle and the second duty cycle are also different; based on the different duty cycles, the device receiving the communication information can perform accurate parsing, thereby enabling the general-purpose input / output port to support bidirectional, multi-instruction, and multi-state data interaction.
[0038] Upon receiving the second communication information, the first device, like the second device, can first detect the second communication information to determine its second duty cycle. Then, the first device can identify the communication information corresponding to the second duty cycle as the second communication information; thus, the interaction of complex information is completed.
[0039] Step 104: Receive the second pulse signal and determine the second duty cycle of the second pulse signal.
[0040] For the first device, after receiving the second pulse signal sent by the second device, it can first detect the second pulse signal to determine the second duty cycle of the second pulse signal.
[0041] For example, the first device can first switch the direction register to input, making the first general-purpose input / output port high impedance to release the bus, then read the level of the first general-purpose input / output port through the input data register, and use the input capture function of the timer to measure the pulse width, thereby obtaining the second duty cycle.
[0042] Step 105: Query the first mapping table to determine the second communication information corresponding to the second duty cycle.
[0043] After obtaining the second duty cycle, the first device can query the first mapping table and determine the communication information corresponding to the second duty cycle, and use the communication information as the second communication information.
[0044] For example, if the second communication information is instruction information, the first device can perform the corresponding operation in response to the instruction information; if the second communication information is status information, the first device can perform subsequent operations based on the status information, such as updating the status of the second device in the first device, generating instruction information based on the status information and sending it to the second device. This application embodiment does not limit this.
[0045] In this embodiment, a first device determines the first communication information to be sent and queries a first mapping table to determine the first duty cycle corresponding to the first communication information; based on the first duty cycle, the first communication information is encoded into a first pulse signal; the first pulse signal is sent to a second device; the second device sends a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent; the second device determines the second duty cycle corresponding to the second communication information according to the first mapping table. Compared to general-purpose input / output ports that can only implement device start / stop based on binary control logic, the device of this application can encode information through different pulse duty cycles, enabling general-purpose input / output ports to transmit more types of information between devices, such as multiple instruction information and multiple status information, thereby achieving the ability to distinguish multiple instructions and multiple states, and thus solving the problem that general-purpose input / output ports cannot distinguish information, multiple instructions, and multiple states.
[0046] In addition, the first device can encode information using different pulse duty cycles, enabling the general-purpose input / output port to transmit more types of information between devices; the second device can also encode information using different pulse duty cycles, enabling the general-purpose input / output port to transmit more types of information between devices; based on this, both the first and second devices can encode different communication information based on duty cycles and perform bidirectional data interaction, thereby enabling the general-purpose input / output port to support bidirectional, multi-command, and multi-state data interaction.
[0047] Reference Figure 2 The diagram illustrates a flowchart of a communication method for a general-purpose input / output port according to an embodiment of this application, which may include the following steps: Step 201: The first device determines the first communication information to be sent.
[0048] In some embodiments, the first device and the second device may have only one general purpose input / output port. When the first device needs to send information to the second device, it can first determine the first communication information to be sent.
[0049] For example, if the first device is the master control device, when the first device needs to control the second device, it can first generate instruction information based on the control of the second device, and use the instruction information as the first communication information.
[0050] In another example, if the first device is a slave device, then when the first device needs to report status information to the second device, it can first collect the status information of the second device and then use it as the first communication information.
[0051] Step 202: Query the first mapping table to determine the first duty cycle corresponding to the first communication information.
[0052] In some embodiments, the first device may store a first mapping table of duty cycle and communication information; the second device may also store a first mapping table of duty cycle and communication information; the first mapping table may store the mapping relationship between duty cycle and communication information, and based on the first mapping table, the duty cycle corresponding to the communication information can be determined, and the communication information corresponding to the duty cycle can also be determined.
[0053] After determining the first communication information, the first device can query the first mapping table to determine the duty cycle corresponding to the first communication information, i.e., the first duty cycle.
[0054] For the second device, after determining the second communication information, the second device can also query the first mapping table to determine the duty cycle corresponding to the second communication information, i.e., the second duty cycle.
[0055] In some embodiments of this application, the communication information includes instruction information and status information. The first mapping table includes an instruction mapping table of instruction information and duty cycle, and a status mapping table of status information and duty cycle.
[0056] In some embodiments, the communication information can be instructions sent by the master device to the slave device to control the slave device, or it can be status information reported by the slave device to the master device. For example, the instructions may include power on, power off, parameter adjustment, etc., and the status information may include abnormal status, normal status, etc., and the embodiments of this application do not limit this.
[0057] The first mapping table may include an instruction mapping table that includes instruction information and duty cycle, and may also include a status mapping table that includes status information and duty cycle.
[0058] For example, when the first device acts as the master device and the second device acts as the slave device, the first communication information can be instruction information; the first device can determine the first duty cycle corresponding to the first communication information based on the instruction mapping table. The second device can determine the first duty cycle by detecting the first pulse signal; then, based on the instruction mapping table, it determines the first communication information corresponding to the first duty cycle. The second communication information can be status information; after determining the second communication information, the second device can determine the second duty cycle through the status mapping table. After receiving the second pulse signal, the first device can determine the second duty cycle by detecting the second pulse signal; then, based on the status mapping table, it determines the second communication information.
[0059] When the first device acts as a slave device and the second device acts as the master device, the first communication information can be status information. The first device can determine the first duty cycle corresponding to the first communication information based on a status mapping table. The second device can determine the first duty cycle by detecting a first pulse signal; then, based on the status mapping table, it can determine the first communication information corresponding to the first duty cycle. The second communication information can be instruction information. After determining the second communication information, the second device can determine the second duty cycle through an instruction mapping table. After receiving a second pulse signal, the first device can determine the second duty cycle by detecting the second pulse signal; then, it can determine the second communication information based on the instruction mapping table.
[0060] Step 203: Encode the first communication information into a first pulse signal according to the first duty cycle.
[0061] After determining the first duty cycle, the first communication information can be encoded into a first pulse signal with a specific duty cycle. This specific duty cycle can be the first duty cycle.
[0062] Step 204: Send the first pulse signal to the second device.
[0063] After determining the first pulse signal, the first device can switch to the transmit mode; at this time, the first device can set the direction register to output and write the level value through the data register, and generate a pulse waveform with the first duty cycle in conjunction with the timer to send to the second device.
[0064] After receiving the pulse waveform of the first duty cycle, the second device can detect it to obtain the first duty cycle; then, the second device can determine the communication information corresponding to the first duty cycle based on the first mapping table, and use it as the first communication information.
[0065] For example, if the first communication information is instruction information, the second device can perform the corresponding operation in response to the instruction information; if the first communication information is status information, the second device can perform subsequent operations based on the status information, such as updating the status of the first device in the second device, generating instruction information based on the status information and sending it to the first device. This application embodiment does not limit this.
[0066] Step 205: Receive the second pulse signal and determine the second duty cycle of the second pulse signal.
[0067] For the first device, after receiving the second pulse signal sent by the second device, it can first detect the second pulse signal to determine the second duty cycle of the second pulse signal.
[0068] For example, the first device can first switch the direction register to input, making the first general-purpose input / output port high impedance to release the bus, then read the level of the first general-purpose input / output port through the input data register, and use the input capture function of the timer to measure the pulse width, thereby obtaining the second duty cycle.
[0069] Step 206: Determine the second duty cycle fault tolerance interval to which the second duty cycle belongs.
[0070] In some embodiments of this application, signal deviation may occur when information is transmitted on a single signal line; that is, there is an error between the expected duty cycle and the actual detected duty cycle. To avoid the problem of unidentification due to errors, embodiments of this application can set a corresponding duty cycle tolerance interval for each communication information, that is, one communication information corresponds to at least one duty cycle, and one duty cycle corresponds to only one communication information. Specifically, the mapping table can include the mapping relationship between the duty cycle tolerance interval and the communication information. To avoid decoding ambiguity, there is no intersection between the various duty cycle tolerance intervals; based on this, the second communication information can be determined by the following method: In some embodiments, after determining the second duty cycle, the size of the second duty cycle can be compared with the endpoints of each duty cycle space to determine the second duty cycle tolerance interval to which the second duty cycle belongs.
[0071] For the first device, when determining the first duty cycle, it can first query a mapping table to determine the first duty cycle tolerance interval corresponding to the first communication information. Then, the value set for the first duty cycle tolerance interval can be used as the first duty cycle. For example, the median value of the first duty cycle tolerance interval can be used as the first duty cycle.
[0072] Step 207: Query the first mapping table to determine the second communication information corresponding to the second duty cycle fault tolerance interval.
[0073] After determining the second duty cycle fault tolerance interval, the first device can query the first mapping table to determine the second communication information corresponding to the second duty cycle fault tolerance interval.
[0074] For example, if the second communication information is instruction information, the first device can perform the corresponding operation in response to the instruction information; if the second communication information is status information, the first device can perform subsequent operations based on the status information, such as updating the status of the second device in the first device, generating instruction information based on the status information and sending it to the second device. This application embodiment does not limit this.
[0075] If the first device is the master device, it can query the status mapping table to determine the second communication information. If the first device is the slave device, it can query the instruction mapping table to determine the second communication information.
[0076] In some embodiments of this application, the second pulse signal includes a plurality of second pulses; based on this, the above embodiments may further include the following steps: Determine the first number of second pulses that correspond to the second duty cycle fault tolerance interval; based on the first number, determine whether the second pulse signal is valid.
[0077] In some embodiments, to combat random errors in a single transmission, the first and second devices may generate a set of N pulses based on communication information during transmission; N is a positive integer greater than 2. For example, the second pulse signal may include multiple second pulses; additionally, the first pulse signal may also include multiple first pulses.
[0078] When the first device receives the second pulse signal, it can first determine whether each received frame (i.e. each second pulse) falls within the duty cycle tolerance range of the first mapping table.
[0079] If the second pulse does not fall within the duty cycle tolerance range in the first mapping table, the second pulse can be determined to be an invalid frame; if the second pulse falls within the duty cycle tolerance range in the first mapping table, the second pulse can be determined to be a valid frame.
[0080] After judging each second pulse in the second pulse information, the first number of all valid frames can be determined, that is, the total number of second pulses with corresponding second duty cycle fault tolerance intervals.
[0081] Next, the validity of the second pulse signal can be determined based on the number of valid frames, i.e., the first number. For example, if the ratio of the number of valid frames to the total number of second pulses in the second pulse signal is greater than a preset value, the second pulse signal can be determined to be valid. At this time, subsequent steps can be performed based on the second pulse information.
[0082] Conversely, if the ratio of the number of valid frames to the total number of second pulses in the second pulse signal is not greater than a preset value, the second pulse signal can be determined to be invalid. In this case, the second pulse signal can be discarded.
[0083] In some embodiments of this application, the validity of the second pulse signal can be determined by the following sub-steps: Sub-step 11: Determine the effective frame ratio based on the first quantity and the total number of the second pulse.
[0084] In some embodiments, while the number of valid frames directly reflects the degree of interference in the transmission, it is insufficient to distinguish between real signals and discretely distributed random noise. Therefore, embodiments of this application may introduce signal quality concentration as a key criterion, aiming to eliminate false valid frames in principle. Specifically, the ratio of the first number to the total number of second pulses in the second pulse signal can be calculated first, i.e., the valid frame ratio.
[0085] Sub-step 12: Determine the standard deviation of the second pulse that corresponds to the second duty cycle tolerance interval, and determine the signal quality concentration of the second pulse signal based on the standard deviation and the second duty cycle tolerance interval.
[0086] In some embodiments, when determining the signal quality concentration, all second pulses with corresponding second duty cycle tolerance intervals can be identified first. Then, the standard deviation of the duty cycle of these second pulses can be calculated.
[0087] In addition, the half-width of the second duty cycle tolerance interval can be determined; the half-width is half the difference between the maximum endpoint value and the minimum endpoint value of the second duty cycle tolerance interval.
[0088] After determining the standard deviation and the half-width of the interval, the signal quality concentration of the second pulse signal can be determined based on the standard deviation and the half-width of the interval; for example, the ratio of the standard deviation to the half-width of the interval can be used as the signal quality concentration.
[0089] Sub-step 13: Determine whether the second pulse signal is valid based on the effective frame ratio and signal quality concentration.
[0090] After determining the effective frame ratio and signal quality concentration, the validity of the second pulse signal can be determined by combining these two factors. For example, if both the effective frame ratio and the signal quality concentration exceed a preset threshold, the second pulse signal is considered valid. Conversely, if either the effective frame ratio or the signal quality concentration does not exceed the preset threshold, the second pulse signal is considered invalid.
[0091] In some embodiments of this application, the first device further stores a second mapping table between communication information and executed actions. Based on this, the above embodiments may further include the following steps: Query the second mapping table to determine the second execution action corresponding to the second communication information; execute the second execution action.
[0092] In some embodiments, the first device is a slave device, and the second communication information is instruction information; the first device may also store a second mapping table between communication information and execution actions. Based on this, after determining the second communication information, the first device can query the second mapping table to determine the execution action corresponding to the second communication information, i.e., the second execution action.
[0093] After the second action is determined, the first device can execute the second action; for example, the actions of turning off or turning on.
[0094] In some embodiments of this application, the above embodiments may further include the following steps: Configure the direction register of the first general purpose input / output port to set the first general purpose input / output port to output mode to drive the level when the first device sends information to the second device, and to switch the first general purpose input / output port to input mode to release the bus and read the information when the first device receives information sent by the second device.
[0095] In some embodiments, after the first device and the second device are connected, the port can be configured; for example, the direction register of the first general-purpose input / output port can be dynamically configured by software, as follows: When transmitting, the first general-purpose input / output port is set to output mode to drive the level; when receiving, it is switched to input mode to release the bus and read the signal, thereby realizing time-division bidirectional communication on a single line.
[0096] During configuration, the first general-purpose input / output port can be configured as a quasi-bidirectional or open-drain mode that supports dynamic software switching, enabling it to drive a high-impedance state when transmitting and release to a high-impedance state when receiving.
[0097] Additionally, timer resources can be initialized to generate precisely timed transmit pulses and measure the width of receive pulses.
[0098] In this embodiment, a first device determines the first communication information to be sent; queries a first mapping table to determine the first duty cycle corresponding to the first communication information; encodes the first communication information into a first pulse signal according to the first duty cycle; sends the first pulse signal to a second device; receives a second pulse signal and determines the second duty cycle of the second pulse signal; determines the second duty cycle tolerance interval to which the second duty cycle belongs; and queries the first mapping table to determine the second communication information corresponding to the second duty cycle tolerance interval. This embodiment encodes information using different pulse duty cycles, thereby achieving encoding differentiation between multiple instructions and multiple states. This application can differentiate information without requiring any dedicated communication hardware, thus solving the problem that general-purpose input / output ports cannot differentiate information, multiple instructions, or multiple states, enabling general-purpose input / output ports to support bidirectional, multi-instruction, and multi-state data interaction.
[0099] In addition, by verifying the validity of a signal based on the number of valid frames and the concentration of signal quality, highly reliable all-digital interaction with multiple instructions and states can be achieved, providing a simple and reliable communication solution for resource-constrained embedded systems.
[0100] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of this application.
[0101] Reference Figure 3 This diagram illustrates a structural schematic of a communication system based on a general purpose input / output (GPIO) port according to an embodiment of this application. The GPIO port includes a first GPIO port deployed on a first device and a second GPIO port deployed on a second device. The first GPIO port is connected to the second GPIO port via a single signal line. Figure 3 As shown, the communication system 30 may include the following modules: The hardware initialization and configuration module 310 is used to configure the direction register of the first general-purpose input / output port so that when the first device sends information to the second device, the first general-purpose input / output port is set to output mode to drive the level, and when the first device receives information sent by the second device, the first general-purpose input / output port is switched to input mode to release the bus and read the information. A two-way communication protocol module 320 is defined to generate a first mapping table between duty cycle and communication information; The communication data determination module 330 is used to determine the first communication information to be sent, and query a first mapping table to determine the first duty cycle corresponding to the first communication information; encode the first communication information into a first pulse signal according to the first duty cycle; and send the first pulse signal to a second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, and the second device is used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; receive the second pulse signal and determine the second duty cycle of the second pulse signal; and query the first mapping table to determine the second communication information corresponding to the second duty cycle.
[0102] In this embodiment of the application, the communication system 30 may include a hardware initialization and configuration module 310, a bidirectional communication protocol formulation module 320, and a communication data determination module 330.
[0103] The hardware initialization and configuration module 310 can configure the port; for example, the hardware initialization and configuration module 310 can dynamically configure the direction register of the first general-purpose input / output port through software, as follows: When transmitting, the first general-purpose input / output port is set to output mode to drive the level; when receiving, it is switched to input mode to release the bus and read the signal, thereby realizing time-division bidirectional communication on a single line.
[0104] During configuration, the hardware initialization and configuration module 310 can configure the first general-purpose input / output port to a quasi-bidirectional or open-drain mode that supports dynamic software switching, enabling it to drive a high-impedance state during transmission and release it to a high-impedance state during reception.
[0105] In addition, the hardware initialization and configuration module 310 can also initialize timer resources, which are used to generate precisely timed transmit pulses and measure the width of receive pulses.
[0106] The bidirectional communication protocol module 320 can be used to generate a first mapping table between duty cycle and communication information. For example, the bidirectional communication protocol module 320 can generate an instruction mapping table between instruction information and duty cycle, a state mapping table between status information and duty cycle, and a second mapping table between communication information and execution action.
[0107] In some embodiments, the bidirectional communication protocol module 320 can also be used for synchronizing the mapping tables in the first device and the second device.
[0108] The communication data determination module 330 can establish communication between the first device and the second device; after the communication is established, when the first device needs to send information to the second device, it first determines the first communication information to be sent.
[0109] After determining the first communication information, the first device can query the first mapping table to determine the first duty cycle corresponding to the first communication information.
[0110] After determining the first duty cycle, the first device can encode the first communication information into a first pulse signal with a specific duty cycle. This specific duty cycle can be the first duty cycle.
[0111] After receiving the first pulse signal, the first device can control the first general-purpose input / output port based on the first pulse signal, and in conjunction with a timer, generate a PWM (Pulse Width Modulation) pulse waveform with a first duty cycle on a single signal line, thereby completing the mapping and physical generation of the analog pulse duty cycle characteristics from digital signals.
[0112] For the second device, after receiving the first pulse signal, it can detect the first pulse signal to determine the first duty cycle of the first pulse signal; then, the second device can determine the communication information corresponding to the first duty cycle as the first communication information; thus, the interaction of complex information is completed.
[0113] In some embodiments, the second device may also send information to the first device; specifically, the first device may, like the first device, first determine the second communication information to be sent.
[0114] After determining the second communication information, in order to distinguish the information, the second device can query the first mapping table to determine the second duty cycle corresponding to the second communication information. If the first communication information and the second communication information are different, then the first duty cycle and the second duty cycle are also different; based on the different duty cycles, the device receiving the communication information can perform accurate parsing, thereby enabling the general-purpose input / output port to support bidirectional, multi-instruction, and multi-state data interaction.
[0115] Upon receiving the second communication information, the first device, like the second device, can first detect the second communication information to determine its second duty cycle. Then, the first device can identify the communication information corresponding to the second duty cycle as the second communication information; thus, the interaction of complex information is completed.
[0116] In some embodiments, the communication data determination module 330 can also determine communication information based on intervals.
[0117] In some embodiments, the communication data determination module 330 can also determine whether the signal is valid; for example, the communication data determination module 330 can first determine whether each received frame (i.e. each second pulse) falls into the duty cycle tolerance interval in the first mapping table.
[0118] If the second pulse does not fall within the duty cycle tolerance range in the first mapping table, the communication data determination module 330 can determine that the second pulse is an invalid frame; if the second pulse falls within the duty cycle tolerance range in the first mapping table, the communication data determination module 330 can determine that the second pulse is a valid frame.
[0119] After judging each second pulse in the second pulse information, the communication data determination module 330 can determine the first number of all valid frames, that is, the total number of second pulses with corresponding second duty cycle fault tolerance intervals.
[0120] Next, the communication data determination module 330 can determine whether the second pulse signal is valid based on the number of valid frames, i.e., a first number. For example, if the ratio of the number of valid frames to the total number of second pulses in the second pulse signal is greater than a preset value, the communication data determination module 330 can determine that the second pulse signal is valid. At this time, subsequent steps can be performed based on the second pulse information.
[0121] Conversely, if the ratio of the number of valid frames to the total number of second pulses in the second pulse signal is not greater than a preset value, the communication data determination module 330 can determine that the second pulse signal is invalid. In this case, the first device can discard the second pulse signal.
[0122] The communication data determination module 330 can also identify all second pulses that have a corresponding second duty cycle tolerance interval. Then, the communication data determination module 330 can calculate the standard deviation of the duty cycle of these second pulses.
[0123] In addition, the communication data determination module 330 can also determine the half-width of the second duty cycle fault tolerance interval; the half-width is half the difference between the maximum endpoint value and the minimum endpoint value of the second duty cycle fault tolerance interval.
[0124] After determining the standard deviation and the half-width of the interval, the communication data determination module 330 can determine the signal quality concentration of the second pulse signal based on the standard deviation and the half-width of the interval; for example, the communication data determination module 330 can use the ratio of the standard deviation to the half-width of the interval as the signal quality concentration.
[0125] After determining the number of valid frames and the signal quality concentration, the communication data determination module 330 can comprehensively consider the valid frame ratio and the signal quality concentration to determine whether the second pulse signal is valid. For example, when the valid frame ratio exceeds a preset ratio and the signal quality concentration also exceeds a preset concentration, the communication data determination module 330 can determine that the second pulse signal is valid. Conversely, if the valid frame ratio does not exceed the preset ratio, or the signal quality concentration does not exceed the preset concentration, the communication data determination module 330 can determine that the second pulse signal is invalid.
[0126] In some embodiments, the hardware initialization and configuration module 310, the bidirectional communication protocol formulation module 320, and the communication data determination module 330 in the communication system 30 can be deployed in the first device or the second device, or they can be deployed as additional devices in the system. This application does not impose any restrictions on this.
[0127] Reference Figure 4 The following is a flowchart illustrating a communication system based on a general-purpose input / output port according to an embodiment of this application: To address the technical contradiction in embedded master-slave device communication, where the reliance on dedicated hardware interfaces leads to pin resource scarcity, while using general-purpose GPIO makes reliable bidirectional, multi-instruction interaction difficult, this application proposes a bidirectional communication method based on single-wire pulse width encoding. This method defines an independent duty cycle mapping between downlink instruction sets and uplink state sets, and integrates interval encoding and majority decision filtering algorithms. This enables highly reliable, multi-instruction, multi-state, all-digital bidirectional communication between master and slave devices using only a single ordinary I / O port, thus eliminating dependence on dedicated hardware resources such as UART and I2C.
[0128] like Figure 4 As shown, the overall framework of the communication system in this application includes: a hardware initialization and configuration module, a bidirectional communication protocol formulation module, and a communication data determination module.
[0129] Hardware initialization and configuration module: IO initialization settings: Connect the designated GPIO pins (i.e., the first general-purpose input / output port and the second general-purpose input / output port) of the master device and the slave device (i.e., the first device and the second device) through a single signal line. On this basis, configure the pins to support quasi-bidirectional or open-drain mode that supports dynamic software switching, so that they can be driven at a high level when transmitting and released to a high-impedance state when receiving.
[0130] Timer configuration: At the same time, timer resources need to be initialized to generate precisely timed transmit pulses and measure the width of receive pulses.
[0131] Configuration method: The direction register of GPIO is dynamically configured by software: when transmitting, the pin is set to output mode to drive the level, and when receiving, it is switched to input mode to release the bus and read the signal, thereby realizing time-division bidirectional communication on a single line.
[0132] For example, configuration can be accomplished by directly reading and writing the microcontroller's GPIO control registers through programming: First, the pin's mode register is configured to push-pull or open-drain output mode. During the transmit phase, the direction register is set to output, and the level value is written through the data register to generate precise pulses in conjunction with a timer. During the receive phase, the direction register is first switched to input to make the pin high-impedance to release the bus. Then, the level is read through the input data register, and the pulse width is measured using the timer's input capture function. The entire switching process is implemented by software directly controlling the registers according to the protocol timing.
[0133] Module for defining a two-way communication protocol: First, a downlink command mapping table is created in the master control device to encode command information into pulse signals with specific duty cycles. The command mapping table is a lookup table that defines the correspondence between command information and pulse duty cycle tolerance intervals. For example, the command to start the motor corresponds to a duty cycle interval of 28% to 32% (center value 30%), and the command to stop the motor corresponds to a duty cycle interval of 68% to 72% (center value 70%). The master control device encodes the command information into pulse signals within the corresponding intervals according to this table, and the slave devices decode and execute the corresponding commands by measuring whether the actual duty cycle of the received pulse falls within that interval.
[0134] The instruction mapping table completes the encoding through software lookup and timing control: The master control device converts instruction information (such as starting a motor) into a specific duty cycle and its fault tolerance range (such as 30%±2%) based on the mapping table. Then, by controlling the GPIO pin and cooperating with the timer, a PWM pulse waveform that meets the requirements of the range is generated on the signal line, i.e., a pulse signal, thereby completing the mapping and physical generation of the analog pulse duty cycle characteristics from digital instructions.
[0135] Simultaneously, an uplink state mapping table is created, and then a unique, non-overlapping duty cycle tolerance interval is assigned to each state, defining the tolerance range to ensure reliable decoding. The state mapping table is a data structure used by the master device to interpret the feedback status of slave devices (such as motor controllers).
[0136] For example, the mapping table can be defined as follows: when a pulse signal with a duty cycle of 20% ± 2% is received, it is decoded as the motor is in normal operation; when the duty cycle is 50% ± 2%, it is decoded as the motor is stalled. After receiving the upward pulse signal, the main control device measures its duty cycle and determines which interval the measured value falls into by looking up this table, thereby obtaining the real-time operating status of the motor.
[0137] When creating the uplink status mapping table, it is first necessary to clarify all the statuses that the slave device needs to report, such as motor start-up and motor failure.
[0138] During the protocol design phase, the slave device pre-stores a status mapping table, which defines a unique pulse duty cycle tolerance range corresponding to each status it needs to report (such as normal operation or fault). When the slave device needs to upload a status, it queries this table based on the current status to obtain the corresponding duty cycle and drives its GPIO to generate the corresponding pulse signal. The master device then uses its stored corresponding status mapping table to decode the signal, thereby achieving uplink communication.
[0139] Finally, each mapping table is stored in the device's program memory in the form of a software-queryable data structure (such as an array or lookup table) for encoding and decoding pulse signals.
[0140] The decoding process using the state mapping table is as follows: The master control device first accurately measures the duty cycle of the pulse signal fed back by the slave device through a timer, and then compares this measurement value with the predefined duty cycle tolerance range of each state in the mapping table; once the measurement value falls into a certain range (e.g., 50% ± 2%), the corresponding state meaning (e.g., motor stall) is determined by looking up the table, thereby completing the decoding from physical pulse characteristics to logical state information.
[0141] In addition, the master control device and the slave device need to store a corresponding instruction parsing table, namely the second mapping table; the instruction parsing table is a query data structure stored inside the device, used to map the decoded instructions or status codes to specific execution actions.
[0142] For example, in a motor control system, the instruction parsing table of a slave device can be defined as: When code 1 is received, the motor start operation is executed; when code 2 is received, the motor stop operation is executed. The parsing table of the main control device is defined as follows: when code 101 is received, it is interpreted as the motor is in normal condition; when code 102 is received, it is interpreted as the motor is in fault condition.
[0143] Instruction parsing tables are typically implemented as arrays and are a crucial link between communication decoding and function execution.
[0144] The instruction parsing table is predefined and created during the protocol design phase based on system functional requirements. Its acquisition process mainly involves three steps: First, based on the system control logic, clearly list all the instructions that the master control device needs to issue (such as start, stop) and all the status information that the slave devices need to report (such as normal, fault).
[0145] Then, a unique numerical code is assigned to each instruction and status information; finally, in the software program of the device (master or slave), these codes are bound to the corresponding processing functions or actions to form the final parsing table, so as to identify and accurately execute the instructions.
[0146] The reason instruction parsing tables can be used to identify and accurately execute instructions lies in their establishment of a definite and unique mapping relationship, embedding the system's functional logic within the device software. Once the device decodes a specific code, it can uniquely determine the corresponding pre-written processing function or operation sequence by querying this table, thereby executing the specific action. This design directly and unambiguously binds the abstract code in the communication protocol to the device's specific functional logic, ensuring consistency in instruction interpretation and determinism in execution results.
[0147] After completing the above-mentioned hardware initialization, protocol definition and other preparatory work, the master control device and the slave device can communicate bidirectionally by simulating and parsing PWM pulse signals with a specific duty cycle according to the protocol.
[0148] Given that the timing accuracy and stability of software-simulated PWM using general-purpose I / O ports are generally inferior to those of hardware PWM, a communication data determination module can be used to ensure communication reliability. First, duty cycle tolerance interval coding is used instead of single-point value coding.
[0149] When creating the instruction mapping table and state mapping table, the instruction information C for each category is... i Instead of an ideal single-point duty cycle value, a duty cycle tolerance range with a certain width and allowing for error is defined. Its mathematical expression is as follows:
[0150] In the formula: D i For instruction information C i The expected duty cycle, Δ i For instruction information C i The absolute deviation tolerance, T i For instruction information C i The duty cycle tolerance range.
[0151] During the protocol design phase, the expected duty cycle, absolute deviation tolerance, and duty cycle fault tolerance range are all predefined as fixed parameters in the system.
[0152] Taking motor control commands as an example: if the expected duty cycle of the start command information is set to 30% and the absolute deviation tolerance is ±2%, then its duty cycle tolerance range is 28% to 32%. Similarly, the stop instruction information can be set to 50% ± 2%, and the duty cycle tolerance range is 48% to 52%. The two communicating parties encode and decode according to this predefined correspondence, thereby achieving reliable identification within the allowable error range.
[0153] To ensure unambiguous decoding, any two different types of instruction information C i and C k The intervals must satisfy the no-intersection principle, which can be expressed mathematically as follows: min(|D i -D k |-(△ i +△ k ))≥G min >0 In the formula: D i D k For instruction information C i C k Expected duty cycle, △ i , △ k For instruction information C i C k The absolute deviation tolerance, G min This refers to the minimum protection interval for the duty cycle of the two types of instructions.
[0154] By tolerating signal deviations within a fault-tolerant range, decoding ambiguity is eliminated under conflict-free conditions. These two mechanisms work together at the protocol layer to achieve inherent fault tolerance to hardware errors and noise interference, thus establishing a robust and deterministic foundation for single-wire communication that does not rely on sophisticated hardware.
[0155] Second, the majority decision filtering algorithm.
[0156] At the transmitting end, each instruction information is encoded and mapped to a set of N pulse signals. Specifically, the target duty cycle and duty cycle tolerance interval corresponding to the instruction information are first obtained by looking up the instruction mapping table. Then, the communication control software, in conjunction with timers and GPIO, continuously generates N (e.g., 5) PWM pulses with the same target duty cycle characteristics on a single signal line. These N pulses are sent out as a whole pulse sequence or frame group.
[0157] Its core purpose is to provide multiple common statistical samples for the decision algorithm at the receiving end, thereby laying a data foundation for subsequent dual statistical decisions based on both quantity proportion and quality concentration. For example, a command to start the motor (target duty cycle 30%) will be mapped to a set of 5 consecutive pulses, with the duty cycle of each pulse remaining stable around 30% (e.g., 29.8%, 30.1%, 30.0%, 29.9%, 30.2%).
[0158] Each of these N pulses has the same expected duty cycle. At the receiving end, to combat random errors in a single transmission, the system makes decisions based on the statistical count of valid frames and their consistency, ensuring high reliability of instruction decoding. Specifically: Valid frame count: The receiver first determines the validity of each received frame (a received frame is the basic unit for measuring and decoding a single physical pulse; its relationship with commands and pulses is hierarchical: a command is encoded at the sending end into a group of N pulses with the same expected duty cycle; each pulse in this group, after being captured and measured at the receiving end, constitutes a received frame. Therefore, one command corresponds to multiple pulses, and one pulse corresponds to one received frame). The receiver determines the validity of the received frame by analyzing whether the measured values (duty cycles) of these N received frames fall within a preset duty cycle tolerance range, and finally determines whether the original command is a valid frame based on the statistical results of all valid frames, defining a valid frame indicator function V. i as follows:
[0159] Where: m i Let T be the duty cycle measured for the i-th frame, and let T be the duty cycle tolerance interval.
[0160] Then the effective frame count (i.e., the first quantity) S in N frames is:
[0161] While the effective frame count S directly reflects the degree of interference in the transmission, it is insufficient to distinguish between real signals and discretely distributed random noise. This application proposes to introduce signal quality concentration as a key criterion, aiming to eliminate false effective frames in principle. The specific formula is as follows:
[0162] In the formula: J is the system's decision result for N consecutive frames (i.e., the entire group of N pulses), J=1 indicates that the decoding command is valid, S is the valid frame count, and N is the total number of frames. The standard deviation of the effective frames. The interval is half width. The mass concentration threshold is 0 < 1. The quantity consistency threshold must be 0.5 < ≤1.0 in, It is a real-time measurement value, calculated by the receiving end based on the duty cycle measurements of all valid frames in the current N pulses, reflecting the consistency of the valid signal itself in this transmission.
[0163] It is preset during system design. Its value is mainly determined based on system hardware (such as timer accuracy and signal edge jitter) and channel noise level to ensure that normal signals can stably fall within the range under no interference or slight interference. Typically, 2% to 10% is used.
[0164] It is pre-defined during system design. The upper limit of this ratio requires that the measurements of the effective frames be concentrated close enough around the expected value to effectively distinguish between real concentrated signals and scattered random noise. It is typically taken between 0.05 and 0.3. For example... =0.1 means that the standard deviation of the effective frame duty cycle must not exceed 10% of the interval half-width, thus ensuring that the signal is highly concentrated.
[0165] It is pre-defined during system design. It specifies the minimum proportion of valid frames that must be achieved, usually greater than 0.5 to ensure majority validity. The specific value balances the ability to resist sudden interference and response speed. Typically, it is taken as 0.6 to 0.9. For example, if = 0.8, then at least 80% of the frames in N consecutive frames are valid frames, to ensure that the signal is clearly dominant in quantity.
[0166] The aforementioned method not only requires a numerical dominance of valid pulses to obtain statistical confidence, but also mathematically guarantees the high homogeneity and purity of the signal by constraining the normalized dispersion of pulse measurements. This mechanism can effectively identify and filter out discrete spurious pulses formed by random noise within the tolerance interval, thus overcoming the misjudgment defects of traditional majority voting under strong noise. The key to the effectiveness of this mechanism in filtering out discrete spurious pulses lies in its utilization of the different statistical characteristics of real signals and random noise: the duty cycle of valid pulses generated by real commands is highly concentrated, while the duty cycle of spurious pulses formed by random noise is discretely distributed within the tolerance interval. While requiring a numerical dominance of valid pulses (quantity judgment), this mechanism further requires that the measurements of these pulses must be highly concentrated (quality concentration criterion), thereby ensuring that the pulse group on which the final decision is based necessarily comes from a homogeneous real signal, rather than discretely distributed random noise.
[0167] In this application embodiment, addressing the pain points of strong dependence on dedicated hardware interfaces and low reliability of general-purpose GPIO communication in embedded device communication, a bidirectional communication method and system based on single-wire pulse width encoding is proposed. It defines a fault-tolerant encoding mechanism with a mapping table at the protocol layer and designs a decision function that integrates dual verification of quantity ratio and quality concentration. This scheme requires only a single general-purpose GPIO pin to achieve highly reliable all-digital interaction across multiple instructions and states, providing a simple and reliable communication solution for resource-constrained embedded systems.
[0168] Reference Figure 5 The diagram illustrates the structure of a communication device with a general-purpose input / output port according to an embodiment of this application, which may include the following modules: The determining module 501 is used for the first device to determine the first communication information to be sent and to query the first mapping table to determine the first duty cycle corresponding to the first communication information; The encoding module 502 is used to encode the first communication information into a first pulse signal according to the first duty cycle; The transceiver module 503 is used to send a first pulse signal to a second device; the second device is used to send a second pulse signal to the first device. The second pulse signal is obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent. The second device is used to determine the second duty cycle corresponding to the second communication information according to the first mapping table. The parsing module 504 is used to receive the second pulse signal, determine the second duty cycle of the second pulse signal, and query the first mapping table to determine the second communication information corresponding to the second duty cycle.
[0169] In some embodiments, the first mapping table includes a mapping relationship between duty cycle fault tolerance intervals and communication information, and there is no intersection between the various duty cycle fault tolerance intervals; the parsing module is used to determine the second duty cycle fault tolerance interval to which the second duty cycle belongs; and to query the first mapping table to determine the second communication information corresponding to the second duty cycle fault tolerance interval.
[0170] In some embodiments, the second pulse signal includes a plurality of second pulses, and the apparatus further includes: The validity determination module is used to determine the first number of second pulses that correspond to the second duty cycle fault tolerance interval; and to determine whether the second pulse signal is valid based on the first number.
[0171] In some embodiments, the validity determination module is used to determine the effective frame ratio based on the first quantity and the total number of second pulses; determine the standard deviation of the second pulses that have a corresponding second duty cycle tolerance interval, and determine the signal quality concentration of the second pulse signal based on the standard deviation and the second duty cycle tolerance interval; and determine whether the second pulse signal is valid based on the effective frame ratio and the signal quality concentration.
[0172] In some embodiments, the first device further stores a second mapping table between communication information and actions performed, and the device further includes: The action execution module is used to query the second mapping table, determine the second execution action corresponding to the second communication information, and execute the second execution action.
[0173] In some embodiments, the communication information includes instruction information and status information, and the first mapping table includes an instruction mapping table of instruction information and duty cycle, and a status mapping table of status information and duty cycle.
[0174] In some embodiments, the apparatus further includes: The configuration module is used to configure the direction register of the first general-purpose input / output port so that when the first device sends information to the second device, the first general-purpose input / output port is set to output mode to drive the level, and when the first device receives information sent by the second device, the first general-purpose input / output port is switched to input mode to release the bus and read the information.
[0175] In this embodiment, a first device determines the first communication information to be sent and queries a first mapping table to determine the first duty cycle corresponding to the first communication information; based on the first duty cycle, the first communication information is encoded into a first pulse signal; the first pulse signal is sent to a second device; the second device sends a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent; the second device determines the second duty cycle corresponding to the second communication information according to the first mapping table. Compared to general-purpose input / output ports that can only implement device start / stop based on binary control logic, the device of this application can encode information through different pulse duty cycles, enabling general-purpose input / output ports to transmit more types of information between devices, such as multiple instruction information and multiple status information, thereby achieving the ability to distinguish multiple instructions and multiple states, and thus solving the problem that general-purpose input / output ports cannot distinguish information, multiple instructions, and multiple states.
[0176] In addition, the first device can encode information using different pulse duty cycles, enabling the general-purpose input / output port to transmit more types of information between devices; the second device can also encode information using different pulse duty cycles, enabling the general-purpose input / output port to transmit more types of information between devices; based on this, both the first and second devices can encode different communication information based on duty cycles and perform bidirectional data interaction, thereby enabling the general-purpose input / output port to support bidirectional, multi-command, and multi-state data interaction.
[0177] This application also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the communication method of the general input / output port as described above.
[0178] This application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, it implements the communication method of the general input / output port as described above.
[0179] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0180] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0181] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0182] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0183] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0184] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0185] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0186] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the statement "comprising a..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0187] The foregoing has provided a detailed description of a communication method, apparatus, medium, and system for a general-purpose input / output port. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A communication method for a universal input / output port, characterized in that, The general purpose input / output (GPIO) ports include a first GPIO port deployed on a first device and a second GPIO port deployed on a second device; the first GPIO port is connected to the second GPIO port via a single signal line, and the first device and the second device store a first mapping table between duty cycle and communication information; the method includes: The first device determines the first communication information to be sent and queries the first mapping table to determine the first duty cycle corresponding to the first communication information; Based on the first duty cycle, the first communication information is encoded into a first pulse signal; The first pulse signal is sent to the second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, and the second device is used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; Receive the second pulse signal and determine the second duty cycle of the second pulse signal; Query the first mapping table to determine the second communication information corresponding to the second duty cycle.
2. The method according to claim 1, characterized in that, The first mapping table includes the mapping relationship between duty cycle fault tolerance intervals and communication information, and there is no intersection between the various duty cycle fault tolerance intervals; The step of querying the first mapping table to determine the second communication information corresponding to the second duty cycle includes: Determine the second duty cycle tolerance range to which the second duty cycle belongs; Query the first mapping table to determine the second communication information corresponding to the second duty cycle fault tolerance interval.
3. The method according to claim 2, characterized in that, The second pulse signal includes a plurality of second pulses, and the method further includes: Determine the first number of second pulses that correspond to the second duty cycle fault-tolerant interval; Based on the first quantity, determine whether the second pulse signal is valid.
4. The method according to claim 3, characterized in that, The step of determining whether the second pulse signal is valid based on the first quantity includes: The effective frame ratio is determined based on the first quantity and the total number of the second pulses; Determine the standard deviation of the second pulse that corresponds to the second duty cycle tolerance interval, and determine the signal quality concentration of the second pulse signal based on the standard deviation and the second duty cycle tolerance interval; The validity of the second pulse signal is determined based on the effective frame ratio and the signal quality concentration.
5. The method according to claim 1, characterized in that, The first device also stores a second mapping table between communication information and executed actions, and the method further includes: Query the second mapping table to determine the second execution action corresponding to the second communication information; Perform the second action.
6. The method according to claim 1, characterized in that, The communication information includes instruction information and status information. The first mapping table includes an instruction mapping table of instruction information and duty cycle, and a status mapping table of status information and duty cycle.
7. The method according to claim 1, characterized in that, The method further includes: Configure the direction register of the first general-purpose input / output port to set the first general-purpose input / output port to output mode to drive the level when the first device sends information to the second device, and to switch the first general-purpose input / output port to input mode to release the bus and read the information when the first device receives information sent by the second device.
8. A communication device with a universal input / output port, characterized in that, The general purpose input / output port includes a first general purpose input / output port deployed on the first device and a second general purpose input / output port deployed on the second device; the first general purpose input / output port is connected to the second general purpose input / output port through a single signal line, and the first device and the second device store a first mapping table of duty cycle and communication information; The device includes: The determination module is used by the first device to determine the first communication information to be sent and to query the first mapping table to determine the first duty cycle corresponding to the first communication information. The encoding module is used to encode the first communication information into a first pulse signal according to the first duty cycle; The transceiver module is used to send the first pulse signal to the second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, and the second device is used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; The parsing module is used to receive the second pulse signal and determine the second duty cycle of the second pulse signal; query the first mapping table to determine the second communication information corresponding to the second duty cycle.
9. A communication system based on a general-purpose input / output port, characterized in that, The general purpose input / output ports include a first general purpose input / output port deployed on the first device and a second general purpose input / output port deployed on the second device; The first general-purpose input / output port is connected to the second general-purpose input / output port via a single signal line; the system includes: The hardware initialization and configuration module is used to configure the direction register of the first general-purpose input / output port so that when the first device sends information to the second device, the first general-purpose input / output port is set to output mode to drive the level, and when the first device receives information sent by the second device, the first general-purpose input / output port is switched to input mode to release the bus and read the information. A two-way communication protocol module is designed to generate the first mapping table between duty cycle and communication information; A communication data determination module is used to determine the first communication information to be sent, and query the first mapping table to determine the first duty cycle corresponding to the first communication information; encode the first communication information into a first pulse signal according to the first duty cycle; and send the first pulse signal to the second device; the second device is used to send a second pulse signal to the first device, the second pulse signal being obtained by the second device encoding the second communication information according to the second duty cycle corresponding to the second communication information to be sent, the second device being used to determine the second duty cycle corresponding to the second communication information according to the first mapping table; receive the second pulse signal and determine the second duty cycle of the second pulse signal; and query the first mapping table to determine the second communication information corresponding to the second duty cycle.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the communication method of the general-purpose input / output port as described in any one of claims 1 to 7.