Device communication method and device based on UART communication protocol, and electronic device

By employing a time-sharing data transmission strategy using the UART communication protocol between the PAD and peripheral devices, the microcontroller is eliminated, achieving low-cost and efficient data transmission, ensuring data accuracy and real-time performance, and improving the user experience.

CN122111923APending Publication Date: 2026-05-29SHANGHAI WINGTECH ELECTRONICS TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI WINGTECH ELECTRONICS TECH
Filing Date
2024-11-22
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In existing technologies, communication between the PAD and peripheral devices requires a dedicated MCU, resulting in high communication costs.

Method used

A time-sharing data transmission strategy based on the UART communication protocol is adopted, which enables electronic devices and peripheral devices to send data alternately through a data transmission channel, eliminating the need for a microcontroller and utilizing a direct connection between the central processing unit and the UART interface.

Benefits of technology

It reduces communication costs, improves the accuracy and real-time performance of data transmission, ensures the effectiveness of data transmission, prevents data loss, and enhances user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122111923A_ABST
    Figure CN122111923A_ABST
Patent Text Reader

Abstract

The application discloses a device communication method and device based on UART communication protocol and electronic equipment, which is applied to communication between electronic equipment and peripheral equipment, the electronic equipment comprises a central processing unit and a UART interface, the peripheral equipment comprises a UART connector, the UART connector and the UART interface both have data receiving pins and data sending pins, a communication connection is established between the data transmission channel and the data receiving pins and the data sending pins of the UART connector, and the method comprises the following steps: configuring a data time-sharing round-robin transmission strategy, so that the peripheral equipment and the electronic equipment both alternately send data according to a preset time length; when the peripheral equipment sends data, the data is transmitted to the data receiving pins of the electronic equipment through the data transmission channel; when the electronic equipment sends data, the data is transmitted to the data receiving pins of the peripheral equipment through the data transmission channel; and based on the time-sharing round-robin transmission strategy, the peripheral equipment and the electronic equipment time-sharing alternately transmit data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data transmission technology, and in particular to a device communication method, apparatus, and electronic device based on the UART communication protocol. Background Technology

[0002] A PAD (Portable Android Device) is a device that can be carried by the user and provides various functions such as making calls, sending and receiving messages, managing schedules, playing games, and playing audio / video. A PAD can be a mobile phone, tablet, laptop, digital multimedia player, etc. PADs are not only lightweight and portable, but also possess powerful processing capabilities and a rich application ecosystem, allowing users to enjoy convenient services and entertainment anytime, anywhere.

[0003] With the continuous development of electronic and communication technologies, communication between tablets and peripheral devices (such as keyboards and touchscreens) has become increasingly important. To meet this need, tablets require a built-in dedicated MCU (Microcontroller Unit) to enable data transmission and communication with peripheral devices. This dedicated MCU processes data from peripheral devices and transmits it to the tablet's central processing unit, thus achieving effective communication and collaborative operation between the tablet and peripheral devices. However, this increases the cost of device communication. Summary of the Invention

[0004] One of the objectives of this invention is to provide a device communication method based on the UART communication protocol that can reduce communication costs.

[0005] To achieve the above objectives, the present invention provides a device communication method based on the UART communication protocol, applied to communication between electronic devices and peripheral devices. The electronic device includes a central processing unit and a UART interface, and the peripheral device includes a UART connector. Both the UART connector and the UART interface have data receiving pins and data transmitting pins. The data transmitting pins of the UART interface and the data receiving pins establish a communication connection with the data receiving pins and data transmitting pins of the UART connector through a data transmission channel. The method includes the following steps:

[0006] A time-sharing data transmission strategy is configured, wherein peripheral devices and electronic devices alternately send data according to a preset time length. When a peripheral device sends data, the data is transmitted to the data receiving pin of the electronic device through the data transmission channel; when an electronic device sends data, the data is transmitted to the data receiving pin of the peripheral device through the data transmission channel.

[0007] Based on the time-sharing transmission strategy, peripheral devices and electronic devices can transmit data alternately in a time-sharing manner.

[0008] Furthermore, the data includes firmware upgrade data for upgrading the peripheral device version and input data of the peripheral device; the step of enabling peripheral devices and electronic devices to alternately transmit data in a time-sharing manner based on the time-sharing transmission strategy specifically includes the following sub-steps:

[0009] The electronic device sends firmware version query data to the peripheral device within a preset time period;

[0010] The peripheral device transmits the current version data to the electronic device within a preset time period after the electronic device's time period has elapsed.

[0011] If the firmware of the peripheral device needs to be upgraded, the peripheral device will separate the firmware upgrade data into several data segments, and based on the transmission rate between the peripheral device and the electronic device, ensure that the content of each data segment is completely transmitted to the peripheral device within each waiting time.

[0012] Furthermore, the step of enabling peripheral devices and electronic devices to alternately transmit data in a time-sharing manner based on the time-sharing transmission strategy also includes the following sub-steps:

[0013] Based on the input data generated in real time by the peripheral device, if the current time is within the data transmission time of the electronic device, the peripheral device will transmit the input data to the electronic device in the next adjacent time period; if the current time is within the data transmission time of the peripheral device, the peripheral device will transmit the real-time generated input data to the electronic device.

[0014] Furthermore, prior to the step of enabling peripheral devices and electronic devices to alternately transmit data based on a time-sharing transmission strategy, the following steps are also included:

[0015] The central processing unit detects the connection or disconnection of peripheral devices. When the connection of a peripheral device is detected, the central processing unit establishes a communication connection with the UART connector through the UART interface.

[0016] Furthermore, the electronic device includes a Hall sensor, and the peripheral device includes an electromagnetic element for characterizing the connection or disconnection of the peripheral device; in the step of detecting the connection or disconnection of the peripheral device, the connection or disconnection of the electromagnetic element is detected by the Hall sensor.

[0017] Furthermore, when the Hall sensor detects that the electromagnetic element is connected or disconnected, it generates a corresponding interrupt response. When the central processing unit receives the interrupt response, it enables the UART interface to establish a communication connection with the UART connector.

[0018] Furthermore, in the step of detecting the access or disconnection of peripheral devices, when the access of the peripheral device is detected, an input subsystem is created. The input subsystem is used to receive and process input data from the peripheral device and transmit the input data from the peripheral device to the operating system of the electronic device. When the peripheral device is detected to be disconnected, the input subsystem is unloaded.

[0019] Furthermore, the method also includes the following steps:

[0020] Configure UART device: Configure UART device for the peripheral device to realize the processing of data transmission between the electronic device and the peripheral device, and transmit the processed data to the upper layer through the input subsystem;

[0021] Establish a wake-up interrupt thread: It is used to monitor input events from peripheral devices during the sleep process of electronic devices, and wake up electronic devices when the central processing unit receives input events from peripheral devices.

[0022] Another object of the present invention is to provide a device communication apparatus based on the UART communication protocol that can reduce communication costs.

[0023] To achieve the above objectives, the present invention also provides a device communication apparatus based on the UART communication protocol, applied to communication between electronic devices and peripheral devices. The electronic device includes a central processing unit and a UART interface, and the peripheral device includes a UART connector. Both the UART connector and the UART interface have data receiving pins and data transmitting pins. The data transmitting pins of the UART interface and the data receiving pins establish a communication connection with the data receiving pins and data transmitting pins of the UART connector through a data transmission channel. The apparatus includes:

[0024] A transmission strategy configuration module is used to configure a time-division multiplexing (TDM) data transmission strategy for electronic devices and peripheral devices. The TDM data transmission strategy is configured to allow both peripheral devices and electronic devices to send data alternately according to a preset time length. When a peripheral device sends data, the data is transmitted to the data receiving pin of the electronic device through the data transmission channel; when an electronic device sends data, the data is transmitted to the data receiving pin of the peripheral device through the data transmission channel.

[0025] The data transmission module enables peripheral devices and electronic devices to transmit data alternately in a time-sharing manner based on a time-sharing and waiting transmission strategy.

[0026] Another object of the present invention is to provide an electronic device that reduces communication costs.

[0027] To achieve the above objectives, the present invention also provides an electronic device, including a central processing unit, a memory, and a UART interface. The UART interface has data receiving pins and data transmitting pins. The data transmitting pins and data receiving pins of the UART interface establish a communication connection with a peripheral device through a data transmission channel. The memory stores a computer program that can be executed by the central processing unit. When the central processing unit executes the computer program, it implements the method described above.

[0028] In summary, the device communication method, apparatus, and electronic device based on the UART communication protocol described in this invention have the following beneficial effects: By configuring a time-division multiplexing (TDM) data transmission strategy, electronic devices and peripheral devices can send and receive data alternately and orderly through only one data transmission channel. Even without a microcontroller, data transmission between the electronic device and peripheral devices remains unaffected, saving communication costs. The configured TDM data transmission strategy has simple and effective logic, without complex control processing logic, improving data transmission accuracy. The feedback mechanism in the transmission strategy ensures the effectiveness of data transmission and prevents data packet loss. Attached Figure Description

[0029] Figure 1 This is a schematic diagram of the internal structure of one embodiment of the electronic device of the present invention.

[0030] Figure 2a This is a schematic diagram of a structure for connecting an electronic device with peripheral devices in related technologies.

[0031] Figure 2b This is a schematic diagram of another type of electronic device connecting to peripheral devices in related technologies.

[0032] Figure 3 This is a schematic diagram of the structure for connecting an electronic device and a peripheral device in one embodiment of the present invention.

[0033] Figure 4 This is a flowchart of one embodiment of the device communication method based on the UART communication protocol of the present invention.

[0034] Figure 5 This is a flowchart of one embodiment of the device communication method based on the UART communication protocol of the present invention.

[0035] Figure 6 This is a flowchart of one embodiment of the device communication method based on the UART communication protocol of the present invention.

[0036] Figure 7 This is a block diagram of one embodiment of the communication device based on the UART communication protocol of the present invention. Detailed Implementation

[0037] The following description, in conjunction with the accompanying drawings and specific embodiments, will further explain the device communication method, apparatus, and electronic device based on the UART communication protocol described in this invention. However, this explanation does not constitute an improper limitation on the technical solution of this invention.

[0038] Please see Figure 1 , Figure 1 A schematic diagram of the internal structure of an electronic device according to one embodiment is shown. The electronic device 100 may include portable Android devices such as mobile phones, tablets, laptops, and digital multimedia players. Internally, the electronic device 100 may include a central processing unit (CPU) 101, a memory 102 connected to the CPU 101, a display screen 103, a camera 104, and a UART interface 10 for communication with peripheral devices via UART (Universal Asynchronous Receiver / Transmitter). The electronic device 100 may also include external devices such as a speaker 105 and a microphone 106. When the electronic device 100 communicates wirelessly, it may also include a radio frequency (RF) circuit 107 and a connected antenna, a wireless Fidelity (WiFi) module 108 and a connected antenna, etc. Furthermore, the electronic device 100 includes a power supply 109 for powering it. Those skilled in the art will understand that… Figure 1 The internal structure of the electronic device 100 shown does not constitute a limitation on the electronic device 100 and may include, but is not limited to, other components. Figure 1 Showing more or fewer components, or combining certain components, or different component arrangements.

[0039] The following text combines Figure 1The various components of the electronic device 100 are described in detail below. The memory 102 can be used to store programs and data. The central processing unit 101 executes various functional applications and data processing of the electronic device 100 by running programs stored in the memory 102, such as executing the communication methods described below by running corresponding computer programs stored in the memory 102. The memory 102 may mainly include a program storage area and a data storage area. The program storage area may store the operating system (e.g., Android or iOS operating system), at least one application required for a function (e.g., sound playback function, image playback function, device communication function, etc.), etc.; the data storage area may store data created based on the use of the electronic device 100 (e.g., audio data, text data, phone book, etc.). Furthermore, the memory 102 may include a high-speed random access memory 102, and may also include non-volatile memory 102, such as at least one disk storage device 102, a flash memory device, or other volatile solid-state memory 102.

[0040] The central processing unit 101 is the control and processing center of the electronic device 100. It connects various parts of the electronic device 100 via various interfaces and lines, and performs various functions and processes data by running or executing programs (or "modules") stored in the memory 102 and calling data stored in the memory 102, thereby providing overall monitoring of the electronic device 100. Optionally, the central processing unit 101 may include at least one processing unit; alternatively, the central processing unit 101 may integrate an application central processing unit 101 and a modem central processing unit 101. The application central processing unit 101 primarily handles the operating system, user interface, and applications, while the modem central processing unit 101 primarily handles wireless communication. It is understood that the modem central processing unit 101 may also not be integrated into the central processing unit 101. The central processing unit 101 executes the operating system stored in the memory 102, calls applications, and performs the functions provided by the applications.

[0041] In this embodiment, the operating system in the electronic device 100 calls the program stored in the memory 102 to complete the device communication method based on the UART communication protocol provided in this embodiment of the invention when the electronic device 100 establishes a UART communication connection with the peripheral device.

[0042] The RF circuit 107 can be used to send and receive information or, during a call, to complete the reception and transmission of signals. Specifically, after receiving downlink information sent by the base station, it hands the downlink information over to the central processing unit 101 for processing; additionally, it sends uplink data to the base station. Typically, the RF circuit 107 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, the RF circuit 107 can also communicate wirelessly with networks and other devices. The wireless communication can use any communication standard or protocol, including but not limited to: Global System for Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0043] Figure 1 In this configuration, the audio circuit, speaker 105, and microphone 106 provide an audio interface between the user and the electronic device 100. The audio circuit converts the received audio data into electrical signals and transmits them to the speaker 105, where the speaker 105 converts them into sound signals for output. On the other hand, the microphone 106 converts the collected sound signals into electrical signals, which are then received by the audio circuit, converted into audio data, and output to the RF circuit 107 for transmission to other electronic devices 100, such as a mobile phone, or to the memory 102 for further processing.

[0044] WiFi is a short-range wireless transmission technology. Electronic device 100, through WiFi module 108, can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 1 WiFi module 108 is shown, but it is understood that it is not a necessary component of electronic device 100 and can be omitted as needed without changing the essence of the embodiments of the present invention.

[0045] The power supply 109 can be logically connected to the central processing unit 101 through a power management system, thereby enabling the management of charging, discharging, and power consumption. The electronic device 100 may also include sensors 110 (e.g., light sensors, motion sensors, etc.). Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display unit according to the ambient light level, and the proximity sensor can turn off the display unit and / or backlight when the electronic device 100 is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes), and when stationary, it can detect the magnitude and direction of gravity. It can be used for applications that recognize the phone's posture (e.g., landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition functions (e.g., pedometer, tapping), etc.

[0046] Other sensors that may be configured on the electronic device 100, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here. Furthermore, the electronic device 100 may also include NFC (Near Field Communication) modules, Bluetooth modules, etc., which will also not be described in detail here.

[0047] The following describes a device communication method and apparatus based on the UART communication protocol according to embodiments of the present invention.

[0048] In related technologies, the UART communication protocol is one of the most commonly used device-to-device communication protocols. It refers to a serial, asynchronous, full-duplex communication protocol that can transmit data bit by bit. The UART communication protocol typically requires a pair of data transmission channels to achieve bidirectional communication, including a data receiving channel and a data transmitting channel. However, since current electronic devices 100 and peripheral devices 200 usually have three probe interfaces and two probes (two of which are needed to establish power and ground channels), only one probe interface and one probe can be used to establish the data transmission channel.

[0049] To avoid data conflicts when electronic device 100 and peripheral device 200 transmit data through this data transmission channel, electronic device 100 needs to be equipped with a microcontroller unit (MCU) to control data transmission and reception. Specifically, such as... Figure 2a As shown, Figure 2aThis is a schematic diagram illustrating the connection between an electronic device 100 and a peripheral device 200 in related technologies. The electronic device 100 and the peripheral transmission device use a connection channel DATA as the data transmission channel. Furthermore, when the electronic device 100 does not include a microcontroller 11, the electronic device 100 typically requires four probe interfaces, and the peripheral device 200 requires four probes. Two probes (a data receiving probe and a data transmitting probe) are connected to two probe interfaces of the electronic device 100 respectively to establish a data receiving channel and a data transmitting channel. Specifically, as shown... Figure 2b As shown, Figure 2b This is a schematic diagram of another structure in the related technology where an electronic device 100 connects to a peripheral device 200. The electronic device 100 and the peripheral transmission device use a connection channel RX (Receive X) as the data receiving channel and a connection channel TX (Transmit X) as the data sending channel. Therefore, the cost of device communication between the electronic device 100 and the peripheral device 200 is relatively high.

[0050] Please see Figure 3 To address the aforementioned issue of high communication costs, the electronic device 100 of this invention enables a direct connection between the central processing unit and the UART interface 10. This allows the electronic device 100 to connect to the UART connector 20 of the peripheral device 200 via the UART interface 10, achieving data communication between the electronic device 100 and the peripheral device 200 based on the UART communication protocol. This eliminates the need for a microcontroller 11, saving communication costs. Both the UART interface 10 and the UART connector 20 (probe connector) have data receiving pins and data transmitting pins. The data transmitting pins of the UART interface 10 and the data receiving pins establish a communication connection with the data receiving pins and data transmitting pins of the UART connector 20 through a data transmission channel (DATA). The UART connector 20 has multiple probes, such as three probes, which are a data transmission probe, a power probe, and a ground probe. The UART interface 10 has a data probe interface, a power probe interface, and a ground probe interface that are respectively connected to the multiple probes, such as the three probes. After the data probe interface is connected to the data transmission probe, a data transmission channel (DATA) is established. After the power probe interface is connected to the power probe, a power channel (VDD) is established. After the ground probe interface is connected to the ground probe, a ground channel (GND) is established.

[0051] Please see Figure 4 , Figure 4This is a flowchart illustrating one embodiment of the device communication method based on the UART communication protocol of the present invention. This method is applied to data communication between an electronic device 100 and a peripheral device 200. The electronic device 100 and the peripheral device 200 transmit data through a data transmission channel. The peripheral device 200 typically refers to a peripheral input device, such as a keyboard, touchscreen, or scanner. The method includes the following steps:

[0052] S101. Configure a time-sharing data transmission strategy. The time-sharing data transmission strategy is configured to allow peripheral devices and electronic devices 100 to send data alternately according to a preset time length. When the peripheral device 200 sends data, the data is transmitted to the data receiving pin of the electronic device 100 through the data transmission channel. When the electronic device 100 sends data, the data is transmitted to the data receiving pin of the peripheral device 200 through the data transmission channel.

[0053] In configuring a time-sharing data transmission strategy: First, both electronic device 100 and peripheral device 200 are configured with a time length that both must adhere to (e.g., 3ms, 5ms, 8ms, 10ms, 15ms, or 20ms). Under this time constraint, whether electronic device 100 or peripheral device 200 is sending or receiving data, each data transmission must occur within the configured time length. Second, a waiting-alternating transmission mechanism is configured based on the configured time length. For example, the data transmission (sending or receiving) of electronic device 100 is represented by Ta, and the data transmission (sending or receiving) of peripheral device 200 is represented by Tb. When electronic device 100 and peripheral device 200 establish a connection, electronic device 100 can be the first to transmit, and the waiting-alternating transmission mechanism can be represented as Ta-Tb-Ta-Tb-Ta-Tb… When electronic device 100 and peripheral device 200 establish a connection, peripheral device 200 can also be the first to transmit, and the waiting-alternating transmission mechanism can be represented as Tb-Ta-Tb-Ta-Tb-Ta…

[0054] S102. Based on the time-sharing transmission strategy, the peripheral device 200 and the electronic device 100 transmit data alternately in a time-sharing manner.

[0055] After electronic device 100 establishes a connection with peripheral device 200, when peripheral device 200 generates an input event, if the current transmission status and duration are both on the electronic device 100 side, peripheral device 200 waits for the current transmission duration on the electronic device 100 side, and then transmits the input data to the electronic device 100 side within the immediately following time duration (on the peripheral device 200 side). If the current transmission status and duration are both on the peripheral device 200 side, the input data is transmitted to the electronic device 100 side. Preferably, if the current transmission status and duration are both on the peripheral device 200 side, based on a pre-set data priority strategy, the input data and the data being transmitted or waiting to be transmitted are sorted according to priority, and the data is transmitted to the electronic device 100 side in descending order of priority. For example, the priority of real-time input data generated by peripheral device 200 is higher than the response data from peripheral device 200 to electronic device 100. In this way, electronic device 100 can respond quickly to input events from peripheral device 200, reducing latency and improving the user experience from an application perspective. Even after removing the microcontroller 11, the electronic device 100 can still maintain a fast response speed to real-time input events from the peripheral device 200.

[0056] This embodiment uses a keyboard as an example of a peripheral device 200. The electronic device 100 contains version data (firmware upgrade data) for the keyboard. When the version data in the electronic device 100 is upgraded, and the electronic device 100 establishes a connection with the keyboard, the electronic device 100, as the data initiator, first sends the version query data to the keyboard through the data transmission channel within a first time period. The keyboard's data receiving pin then receives the version query data through the data transmission channel within the same first time period.

[0057] After the first time period ends, the keyboard's data transmission pin sends the current version data to the electronic device 100 through the data transmission channel during the second time period. The electronic device 100 receives the current version data through the data transmission channel via its data reception pin during the second time period and processes it to determine whether the keyboard needs to upgrade its firmware.

[0058] If the keyboard does not require a firmware upgrade (i.e., the current version of the keyboard is the latest version), optionally, neither the electronic device 100 nor the keyboard needs to perform any processing. If the keyboard requires a firmware upgrade, after the second time period ends, the data transmission pin of the electronic device 100 sends upgrade notification data to the keyboard through the data transmission channel within a third time period, and the data reception pin of the keyboard receives the notification data through the data transmission channel within the third time period.

[0059] After the third time period ends, the keyboard's data receiving pin sends ready feedback data to the electronic device 100 through the data transmission channel during the fourth time period.

[0060] After the fourth time period ends, the electronic device 100 begins transmitting firmware upgrade data from the fifth time period. After the upgrade data is transmitted to the keyboard within each time period, the keyboard transmits feedback information to the electronic device 100 in the immediately following time period. If the electronic device 100 does not receive feedback, it can repeatedly send the corresponding data (for which no feedback was received) to the keyboard multiple times through the configured transmission mechanism until feedback is received from the keyboard. Similarly, when the keyboard sends data to the electronic device 100 and requires feedback, if the electronic device 100 does not provide feedback, it repeatedly sends the corresponding data (for which no feedback was received) to the electronic device 100 until feedback is received from the electronic device 100.

[0061] In this embodiment of the invention, by configuring a time-sharing data transmission strategy, the electronic device 100 and the peripheral device 200 can send and receive data alternately and orderly through only one data transmission channel. Even without the microcontroller 11, data transmission between the electronic device 100 and the peripheral device 200 remains unaffected, saving communication costs. The transmission strategy in this embodiment is simple and effective, without complex control processing logic, improving data transmission accuracy. The configured feedback mechanism ensures data transmission effectiveness and prevents data packet loss. By configuring data priority levels, real-time input events from the peripheral device 200 are treated as high-priority data, improving the response speed of real-time input events and enhancing user verification from an application perspective.

[0062] Please see Figure 5 , Figure 5 This is a flowchart illustrating one embodiment of the device communication method based on the UART communication protocol of the present invention. This method is applied to data communication between an electronic device 100 and a peripheral device 200, wherein the electronic device 100 and the peripheral device 200 transmit data through a data transmission channel. The method includes the following steps:

[0063] S201. Configure a time-sharing data transmission strategy. This strategy is configured so that both the peripheral device and the electronic device 100 alternately send data according to a preset time length. The data includes firmware upgrade data for upgrading the peripheral device 200 and input data from the peripheral device 200. Specifically, when the peripheral device 200 sends data, it transmits the data to the data receiving pin of the electronic device 100 through the data transmission channel; when the electronic device 100 sends data, it transmits the data to the data receiving pin of the peripheral device 200 through the data transmission channel.

[0064] S202, the electronic device 100 sends firmware version query data to the peripheral device 200 within a preset time period.

[0065] When the UART connector 20 of the peripheral device 200 is inserted into the UART interface 10, the peripheral device 200 establishes a communication connection with the electronic device 100. Each time a communication connection is established, the electronic device 100 acts as the first sender, and its transmit pin sends version query data to the peripheral device 200 through the data transmission channel within the first time period.

[0066] S203. After the time limit of the electronic device 100 is reached, the peripheral device 200 transmits the current version data to the electronic device 100 within a preset time limit.

[0067] S204. If the firmware of the peripheral device 200 needs to be upgraded, the peripheral device 200 will separate the firmware upgrade data into several data segments, and based on the transmission rate between the peripheral device 200 and the electronic device 100, ensure that the content of each data segment is completely transmitted to the peripheral device 200 within each waiting time.

[0068] Steps S202 to S204 described above are used to perform the data transmission process for firmware upgrade when the electronic device 100 establishes a connection with the peripheral device 200. For details, please refer to the description of the previous embodiment.

[0069] S205. Based on the input data generated in real time by the peripheral device 200, if the current time is within the data transmission time of the electronic device 100, then the peripheral device 200 transmits the input data to the electronic device 100 in the next adjacent time period; if the current time is within the data transmission time of the peripheral device 200, then the peripheral device 200 transmits the real-time generated input data to the electronic device 100.

[0070] During firmware upgrade transmission, if peripheral device 200 sends input data within its transmission cycle, electronic device 100, upon receiving the input data within that cycle, immediately processes and responds, and then sends feedback data to peripheral device 200 within the subsequent transmission cycle of electronic device 100. The feedback data is typically a very small data segment; even if it is sent together with the firmware upgrade data segment within the same cycle, it can be completely transmitted to peripheral device 200 within that cycle. That is, when separating firmware upgrade data, based on the transmission rate and time length, the content of each data segment can be transmitted within a time period shorter than the stated time length. This ensures that electronic device 100 responds promptly and transmits feedback data (such as acknowledgment data) to peripheral device 200. In this way, the transmission of input events of peripheral devices 200 is not affected by data with large data space. They will transmit their respective data in an orderly and alternating manner according to the pre-configured time-sharing transmission strategy, which not only ensures the timeliness of the input data of peripheral devices 200 and the transmission of data with large data space from electronic device 100 to peripheral devices 200, but also ensures that the transmission of data with large data space is not affected.

[0071] In this embodiment of the invention, when transmitting large amounts of data such as firmware upgrade data, the data is divided into several data segments based on the UART communication transmission rate and a preset time length, ensuring that each data segment is fully transmitted to the receiving side within its corresponding time length. This ensures that the electronic device 100 and the peripheral device 200 can send and receive data in an orderly and alternating manner according to the configured time-sharing transmission strategy. When the peripheral device 200 is a peripheral input device, the electronic device 100 actively sends data with low timeliness requirements, such as firmware upgrade data. All other data with high timeliness requirements are generated and actively sent by the peripheral device 200. This type of data is typically input data generated by real-time input events of the electronic device 100, and its space usage is usually very small (such as keycode data generated by keyboard presses and releases). Therefore, in this embodiment, separating this type of low-time-requirement data into several data segments for time-interval transmission has little or no impact on either device, is imperceptible to the user, and ensures a good user experience.

[0072] Please see Figure 6 , Figure 6 This is a flowchart illustrating one embodiment of the device communication method based on the UART communication protocol of the present invention. This method is applied to data communication between an electronic device 100 and a peripheral device 200, wherein the electronic device 100 and the peripheral device 200 transmit data through a data transmission channel. The method includes the following steps:

[0073] S301. Configure a data time-sharing transmission strategy in the electronic device 100.

[0074] S302. Detect the access or disconnection of the peripheral device 200. When the peripheral device 200 is detected to be connected, the central processing unit establishes a communication connection with the UART connector 20 through the UART interface 10.

[0075] The electronic device 100 includes a Hall sensor, and the peripheral device 200 includes an electromagnetic element used to characterize the connection or disconnection of the peripheral device 200. In this step, the connection or disconnection of the electromagnetic element is detected by the Hall sensor.

[0076] Specifically, when the Hall sensor detects the connection or disconnection of the electromagnetic element, it generates a corresponding interrupt response. When the central processing unit receives this interrupt response, it establishes a communication connection between the UART interface 10 and the UART connector 20. When the peripheral device 200 is detected to be connected, an input subsystem is created. This input subsystem is used to receive and process input data from the peripheral device 200 and transmit the input data to the operating system of the electronic device 100. When the peripheral device 200 is detected to be disconnected, the input subsystem is unloaded. In this way, the device can correctly identify whether the keyboard connection is broken, and thus correctly display on the electronic device 100 whether the keyboard peripheral device 200 is present.

[0077] The operating system kernel of electronic device 100 may include a Linux kernel. This input subsystem is used to process peripheral devices 200, receiving input events from peripheral devices 200 and transmitting input data from peripheral devices 200 to the operating system of electronic device 100. Specifically, the Linux kernel is the core part of the operating system, used to manage hardware resources and provide system services so that other applications can run on electronic device 100. Linux is a multitasking operating system, and multiple applications may run simultaneously on it, each needing to process user input. The input subsystem enables the Linux kernel to uniformly manage and distribute input events from different peripheral devices 200, such as keyboard key presses, mouse clicks, and screen touches, thereby ensuring that input events are correctly delivered to the corresponding applications.

[0078] S303. Configure UART device: Configure UART device for peripheral device 200 to process data transmission between electronic device 100 and peripheral device 200, and transmit the processed data to the upper layer through input subsystem. During data transmission, data is obtained from registers (such as FIFO register) in UART driver and processed (such as button data, upgrade data, button data can be divided into single button and multiple button data) and accurately reported.

[0079] S304. Based on the time-sharing transmission strategy, peripheral device 200 and electronic device 100 alternately transmit data in a time-sharing manner.

[0080] The data format, data length, data type (such as firmware upgrade data type, input data type of peripheral device 200), and data verification of electronic device 100 and peripheral device 200 can be freely agreed upon, making data processing more flexible and secure. The reporting of input data from peripheral device 200 is freely achieved through the input subsystem based on agreed-upon protocols. Taking a keyboard as an example, this implementation can accurately report data for a single key press, multiple keys pressed simultaneously, or keys released.

[0081] Preceding data Header data length Type Code Data content CRC verification 0X66 0XFF 8 2 XXXX crc16

[0082] Table 1

[0083] Specifically, please refer to Table 1, which exemplarily illustrates the agreed-upon data. The content of the preamble and header data can be customized based on the needs of different implementation methods, serving as agreed-upon data between electronic device 100 and peripheral device 200. The data length is the actual size of the data, the type code indicates the specific type of the data segment (such as button reporting data, button release data, or firmware upgrade data), the data content indicates the specific content of the data segment, and CRC (Cyclic Redundancy Check) is a commonly used error detection technique used to ensure that no errors occur during data transmission or storage. It generates a checksum by performing mathematical operations on the data, and verifies the integrity of the data by comparing the checksum.

[0084] S305. Establish a wake-up interrupt thread: It is used to monitor input events from peripheral devices 200 during the sleep process of electronic device 100, and wake up electronic device 100 when the central processing unit obtains the input event from peripheral devices 200.

[0085] Those skilled in the art will understand that there is no temporal sequence relationship between steps S301 to S305.

[0086] In this embodiment of the invention, by recreating a UART device, data can be transmitted directly using the UART device. Compared to the traditional method of obtaining data from the native Linux driver, processing it, and then transmitting the data through a file node, this embodiment is simpler and bypasses the file node, thus not being limited by the kernel version.

[0087] Please see Figure 7 , Figure 7 This is a block diagram illustrating one embodiment of the communication device based on the UART communication protocol of the present invention. The device of this embodiment is applied to an electronic device 100, which includes a central processing unit and a UART interface 10. The peripheral device 200 includes a UART connector 20. Both the UART connector 20 and the UART interface 10 have data receiving pins and data transmitting pins. The data transmitting pins of the UART interface 10 and the data receiving pins establish a communication connection with the data receiving pins and data transmitting pins of the UART connector 20 through a data transmission channel. The communication device based on the UART communication protocol includes a transmission strategy configuration module 30 and a data transmission module 40.

[0088] The transmission strategy configuration module 30 is used to configure a time-division multiplexing (TDM) data transmission strategy for the electronic device 100 and the peripheral device 200. This TDM strategy is configured so that both the peripheral device and the electronic device 100 alternately transmit data according to a preset time length. Specifically, when the peripheral device 200 transmits data, it sends the data to the data receiving pin of the electronic device 100 through the data transmission channel; conversely, when the electronic device 100 transmits data, it sends the data to the data receiving pin of the peripheral device 200 through the data transmission channel. The data transmission module 40 is used to enable the peripheral device 200 and the electronic device 100 to transmit data alternately based on the TDM strategy. In addition, the transmission strategy configuration module 30 and the data transmission module 40 can also implement the processing logic described in the above method implementation, which will not be elaborated further here.

[0089] It should be noted that the scope of protection of the prior art in this invention is not limited to the embodiments given in this application. All prior art that does not contradict the solution of this invention, including but not limited to prior patent documents, prior publications, prior public uses, etc., can be included in the scope of protection of this invention.

[0090] Furthermore, the combination of the technical features in this case is not limited to the combination methods described in the claims of this case or the combination methods described in the specific embodiments. All technical features described in this case can be freely combined or combined in any way, unless they contradict each other.

[0091] It should also be noted that the embodiments listed above are merely specific embodiments of the present invention. Obviously, the present invention is not limited to the above embodiments, and similar changes or modifications made thereto are those that can be directly derived or easily conceived by those skilled in the art from the content disclosed in the present invention, and should all fall within the protection scope of the present invention.

Claims

1. A device communication method based on the UART communication protocol, applied to communication between an electronic device and a peripheral device, wherein the electronic device includes a central processing unit and a UART interface, the peripheral device includes a UART connector, both the UART connector and the UART interface have data receiving pins and data transmitting pins, and the data transmitting pins of the UART interface and the data receiving pins establish a communication connection with the data receiving pins and data transmitting pins of the UART connector through a data transmission channel, characterized in that... The method includes the following steps: A time-sharing data transmission strategy is configured, wherein peripheral devices and electronic devices alternately send data according to a preset time length. When a peripheral device sends data, the data is transmitted to the data receiving pin of the electronic device through the data transmission channel; when an electronic device sends data, the data is transmitted to the data receiving pin of the peripheral device through the data transmission channel. Based on the time-sharing transmission strategy, peripheral devices and electronic devices can transmit data alternately in a time-sharing manner.

2. The device communication method based on the UART communication protocol as described in claim 1, characterized in that, The data includes firmware upgrade data for upgrading peripheral device versions and input data from peripheral devices; the step of enabling peripheral devices and electronic devices to alternately transmit data in a time-sharing manner based on a time-sharing transmission strategy specifically includes the following sub-steps: The electronic device sends firmware version query data to the peripheral device within a preset time period; The peripheral device transmits the current version data to the electronic device within a preset time period after the electronic device's time period has elapsed. If the firmware of the peripheral device needs to be upgraded, the peripheral device will separate the firmware upgrade data into several data segments, and based on the transmission rate between the peripheral device and the electronic device, ensure that the content of each data segment is completely transmitted to the peripheral device within each waiting time.

3. The device communication method based on the UART communication protocol as described in claim 2, characterized in that, The step of enabling peripheral devices and electronic devices to alternately transmit data in a time-sharing manner based on the time-sharing transmission strategy further includes the following sub-steps: Based on the input data generated in real time by the peripheral device, if the current time is within the data transmission time of the electronic device, the peripheral device will transmit the input data to the electronic device in the next adjacent time period. If the current time falls within the data transmission time of the peripheral device, the peripheral device will transmit the real-time generated input data to the electronic device.

4. The device communication method based on the UART communication protocol as described in claim 2, characterized in that, Before the step of enabling peripheral devices and electronic devices to alternately transmit data in a time-sharing manner based on the time-sharing transmission strategy, the following steps are also included: The central processing unit detects the connection or disconnection of peripheral devices. When the connection of a peripheral device is detected, the central processing unit establishes a communication connection with the UART connector through the UART interface.

5. The device communication method based on the UART communication protocol as described in claim 4, characterized in that: The electronic device includes a Hall sensor, and the peripheral device includes an electromagnetic element for characterizing the connection or disconnection of the peripheral device; in the step of detecting the connection or disconnection of the peripheral device, the connection or disconnection of the electromagnetic element is detected by the Hall sensor.

6. The device communication method based on the UART communication protocol as described in claim 5, characterized in that: When the Hall sensor detects that the electromagnetic element is connected or disconnected, it generates a corresponding interrupt response. When the central processing unit receives the interrupt response, it enables the UART interface to establish a communication connection with the UART connector.

7. The device communication method based on the UART communication protocol as described in claim 4, characterized in that, In the step of detecting the access or disconnection of peripheral devices, when the access of the peripheral device is detected, an input subsystem is created. The input subsystem is used to receive and process input data from the peripheral device and transmit the input data from the peripheral device to the operating system of the electronic device. When the peripheral device is detected to be disconnected, the input subsystem is unloaded.

8. The device communication method based on the UART communication protocol as described in claim 7, characterized in that, It also includes the following steps: Configure UART device: Configure UART device for the peripheral device to realize the processing of data transmission between the electronic device and the peripheral device, and transmit the processed data to the upper layer through the input subsystem; Establish a wake-up interrupt thread: It is used to monitor input events from peripheral devices during the sleep process of electronic devices, and wake up electronic devices when the central processing unit receives input events from peripheral devices.

9. A device communication apparatus based on the UART communication protocol, used for communication between an electronic device and a peripheral device, wherein the electronic device includes a central processing unit and a UART interface, the peripheral device includes a UART connector, both the UART connector and the UART interface have data receiving pins and data transmitting pins, and the data transmitting pins of the UART interface and the data receiving pins establish a communication connection with the data receiving pins and data transmitting pins of the UART connector through a data transmission channel, characterized in that... include: A transmission strategy configuration module is used to configure a time-division multiplexing (TDM) data transmission strategy for electronic devices and peripheral devices. The TDM data transmission strategy is configured to allow both peripheral devices and electronic devices to send data alternately according to a preset time length. When a peripheral device sends data, the data is transmitted to the data receiving pin of the electronic device through the data transmission channel; when an electronic device sends data, the data is transmitted to the data receiving pin of the peripheral device through the data transmission channel. The data transmission module enables peripheral devices and electronic devices to transmit data alternately in a time-sharing manner based on a time-sharing and waiting transmission strategy.

10. An electronic device comprising a central processing unit, a memory, and a UART interface, wherein each UART interface has a data receiving pin and a data transmitting pin, and the data transmitting pin and the data receiving pin of the UART interface are connected to a peripheral device through a data transmission channel, wherein the memory stores a computer program that can be executed by the central processing unit, and the central processing unit implements the method of any one of claims 1 to 8 when executing the computer program.