A communication method, system and device based on USART
By setting the slave device to transmit mode and the host device to receive mode on the USART interface, and switching modes alternately, combined with data transmission priority processing, the congestion problem caused by the master and slave devices sending data packets at the same time is solved, achieving high efficiency and stability. data transmission.
Patent Information
- Application Number
- CN202211119515.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-14
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-09-14
AI Technical Summary
The full-duplex design of the USART interface may cause the host and slave to send data packets at the same time, leading to data congestion. It is difficult to effectively solve this problem with existing technology.
By setting the slave device to default to transmit mode and the host device to default to receive mode, using the start of transmission interrupt control register and the transmission completion interrupt control register, the master and slave devices alternately switch between transmission and reception modes, and according to the preset data transmission priority sequence Arrange the data packets to be sent to ensure the order and priority of data transmission.
It achieves data transmission synchronization between master and slave devices, avoids data congestion, and ensures the correctness and stability of data transmission. The data transmission error rate is 0 and the transmission rate is high.
Smart Images

Figure CN115567080B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information technology, and in particular to a communication technology based on USART. Background Art
[0002] USART (Universal Synchronous / Asynchronous Receiver / Transmitter) is a full-duplex universal synchronous / asynchronous serial transceiver module. This interface is a highly flexible serial communication device. Since the TX (Transmit) port and RX (Receive) port of USART are connected to the same line, it is possible that the master and the slave send data packets at the same time, and the host or slave modules send data packets at the same time, which will cause data congestion. Summary of the invention
[0003] An object of the present application is to provide a communication method, system and device based on USART.
[0004] According to one aspect of the present application, a USART-based communication method is provided, wherein the method comprises:
[0005] The host device and the slave device are connected based on USART, the slave device is set to a sending mode by default, and the host device is set to a receiving mode by default;
[0006] If the host device and the slave device both send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, and combines the start sending interrupt control register and the sending completion interrupt control register, and the slave device and the host device alternately switch to the sending mode or the receiving mode. If one of them has no data to send, the data is skipped and not sent.
[0007] Furthermore, the method further comprises:
[0008] If the modules of the host device or the slave device send data packets at the same time, the data to be sent by each module are arranged in order of priority according to the preset data sending priority of each module;
[0009] When the host device or the slave device is in the sending mode, the to-be-sent data of each module are sent according to the priority order.
[0010] Furthermore, if the host device and the slave device both send data packets at the same time, the specific steps include:
[0011] The slave device initiates the transmission of the first handshake data packet, and the slave device initiates an internal start-sending interrupt based on USART; at this time, the host device detects the start-sending interrupt and immediately switches to the receiving mode;
[0012] After the slave device sends the data packet, the slave device initiates an internal transmission completion interrupt based on USART, the slave device switches to the receiving mode, and the host device switches to the sending mode, and the cycle is repeated;
[0013] When the host device is about to send a data packet, the host device initiates an internal start-sending interrupt based on USART; at this time, the slave device detects the start-sending interrupt and immediately switches to the receiving mode;
[0014] After the host device sends the data packet, the host device initiates an internal transmission completion interrupt based on USART, the host device switches to the receiving mode, and the slave device switches to the sending mode.
[0015] Furthermore, if the modules of the host device or the slave device send data packets simultaneously, the specific steps include:
[0016] According to the preset data transmission priority of each module, the data to be sent from each module are arranged in order of priority;
[0017] When the slave device is in the sending mode, the data packets of the first priority module are sent in order of priority, and after the sending is completed, the data packets of the second priority module are sent in turn, and so on;
[0018] When the host device is in the sending mode, the data packets of the first priority module are sent in order of priority. After the sending is completed, the data packets of the second priority module are sent in turn, and so on.
[0019] Furthermore, the host device and the slave device are connected based on USART, including:
[0020] The host device is connected to the slave device via a single-line Pogo Pin of USART.
[0021] Furthermore, the host device is a keyboard, and the slave device is a tablet computer.
[0022] According to another aspect of the present application, a USART-based communication system is also provided, wherein the system includes a host device and a slave device;
[0023] The host device is connected to the slave device based on USART, the slave device is set to a sending mode by default, and the host device is set to a receiving mode by default;
[0024] If the host device and the slave device both send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, and combines the start sending interrupt control register and the sending completion interrupt control register, and the slave device and the host device alternately switch to the sending mode or the receiving mode. If one of them has no data to send, the data is skipped and not sent.
[0025] Furthermore, if the modules of the host device or the slave device send data packets at the same time, the data to be sent of each module are arranged in order of priority according to the preset data sending priority of each module;
[0026] When the host device or the slave device is in the sending mode, the to-be-sent data of each module are sent according to the priority order.
[0027] According to another aspect of the present application, a computing device is also provided, wherein the device includes a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute the USART-based communication method.
[0028] According to another aspect of the present application, a computer-readable medium is provided, on which computer program instructions are stored. The computer-readable instructions can be executed by a processor to implement the USART-based communication method.
[0029] In the scheme provided by the present application, the host device and the slave device are connected based on USART, the slave device is set to the sending mode by default, and the host device is set to the receiving mode by default; if the host device and the slave device send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, and combines the start sending interrupt control register and the sending completion interrupt control register, the slave device and the host device alternately switch to the sending mode or the receiving mode, and skip not sending when one party has no data to send. Compared with the prior art, the present application provides a communication synchronization mechanism based on USART between the host device and the slave device, which solves the congestion problem of the master and the slave sending data at the same time. The data transmission bit error rate of the present application is 0, and the data transmission rate is high, which ensures the data transmission correctness and use stability of the device. In addition, the present application solves the congestion problem of the host device or the slave device sending data packets at the same time by setting the data transmission priority of the module and matching the sending processing logic. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0031] Figure 1 is a flow chart of a communication method based on USART according to an embodiment of the present application;
[0032] Figure 2 It is a schematic diagram of a host device and a slave device connected based on USART according to an embodiment of the present application;
[0033] Figure 3 is a schematic diagram of a communication synchronization mechanism between a host device and a slave device according to an embodiment of the present application;
[0034] Figure 4 It is a schematic diagram of a communication mechanism in which modules of a host device or a slave device simultaneously send data packets according to an embodiment of the present application.
[0035] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION
[0036] The present application is described in further detail below in conjunction with the accompanying drawings.
[0037] In a typical configuration of the present application, the terminal, the device of the service network and the trusted party all include one or more processors (CPU), input / output interfaces, network interfaces and memories.
[0038] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0039] Computer readable media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be a device that can be computer-readable instructions, data structures, programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission medium that can be used to store information that can be accessed by a computing device.
[0040] The embodiment of the present application provides a communication method based on USART, which solves the congestion problem of the master and slave sending data at the same time, and solves the congestion problem of the host device or the slave device sending data packets at the same time. The data transmission bit error rate of the embodiment of the present application is 0, the data transmission rate is high, and the data transmission correctness and use stability of the device are ensured.
[0041] In actual scenarios, the device implementing the method may be a user device, a network device, or a device formed by integrating a user device and a network device through a network. The user device includes but is not limited to terminal devices such as smart phones, tablet computers, and personal computers, and the network device includes but is not limited to a network host, a single network server, a set of multiple network servers, or a set of computers based on cloud computing. Here, the cloud is composed of a large number of hosts or network servers based on cloud computing (Cloud Computing), wherein cloud computing is a type of distributed computing, a virtual computer composed of a group of loosely coupled computer sets.
[0042] Figure 1 It is a flow chart of a communication method based on USART according to an embodiment of the present application, and the method includes step S101 and step S102.
[0043] In step S101 , a host device and a slave device are connected based on USART, the slave device is set to a transmit (TX) mode by default, and the host device is set to a receive (RX) mode by default.
[0044] For example, the host device and the slave device are connected via USART single-line adsorption, and the TX (Transmit) port and RX (Receive) port of the USART of both parties are connected together.
[0045] In some embodiments, Figure 2 As shown, the host device is a keyboard, and the slave device is a tablet computer. In actual use scenarios, the tablet computer and the keyboard are connected through the USART single-line communication interface. Compared with the existing Bluetooth connection solution, it can avoid environmental interference, improve the stability of the connection, and optimize the user experience.
[0046] In some embodiments, Figure 2 As shown, the host device and the slave device are connected via a single-line Pogo Pin of USART, wherein Pogo Pin is a precision connector used in various electronic products and plays a connecting role.
[0047] Step S102, if the host device and the slave device both send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, combined with the start of the transmission interrupt control register and the transmission completion interrupt control register, such as Figure 3 As shown, the slave device and the host device switch alternately to the sending mode or the receiving mode, and when one of them has no data to send, the sending is skipped.
[0048] In some embodiments, after the slave device is connected to the host device, Figure 3 As shown, the USART communication interface of the slave device is set to the transmit (TX, Transmit) mode by default when it is turned on, and the USART communication interface of the host device is set to the receive (RX, Receive) mode by default. If the host device and the slave device both send data packets at the same time, the specific steps include: the slave device initiates the transmission of the first handshake data packet, and the slave device initiates an internal start-sending interrupt based on USART; at this time, the host device detects the start-sending interrupt and immediately switches to the receiving mode; if the host device also has data to send at this time, because it has detected that it is currently switched to the receiving mode, it will send data again in the time slot of the next sending mode. After the slave device sends the data packet, the slave device initiates an internal sending completion interrupt based on USART, the slave device switches to the receiving mode, and the host device switches to the sending mode, and the cycle is in sequence; when the host device wants to send a data packet, the host device initiates an internal start-sending interrupt based on USART; at this time, the slave device detects the start-sending interrupt and immediately switches to the receiving mode; if the slave device also has data to send at this time, because it has detected that it is currently switched to the receiving mode, it will send data again in the time slot of the next sending mode. After the host device sends the data packet, the host device initiates an internal transmission completion interrupt based on USART, the host device switches to the receiving mode, and the slave device switches to the sending mode. When both parties have no data to send, both parties will automatically not execute the sending (TX, Transmit) and receiving (RX, Receive) interrupt processing functions.
[0049] In some embodiments, the USART-based communication method further includes: if the host device or each module of the slave device sends a data packet at the same time, such as Figure 4 As shown, according to the preset data transmission priority of each module, the data to be sent of each module are arranged in order of priority; when the host device or the slave device is in the transmission mode, the data to be sent of each module are sent according to the order of priority.
[0050] For example, the slave device has many peripheral modules, and each module runs on the system at the same time. The data to be sent is generated randomly, and there are more than two modules at random time points and data packets are sent at the same time, resulting in data congestion. The host device has relatively few modules, but there is also a scenario where module data packets are sent at the same time. In this embodiment, the data transmission priority of each module is pre-set by code, and the data transmission priority of the module can be adjusted in the encoding according to the importance of the data. When the host device or the slave device is in the sending mode, the data packets of each module are sent in order of priority, thereby solving the data congestion problem.
[0051] In some embodiments, if the host device or each module of the slave device sends a data packet at the same time, the specific steps include: Figure 4 As shown, according to the pre-set data transmission priority of each module, the data to be sent of each module are arranged in priority order; when the slave device is in the sending mode, the data packets of the first priority module are sent in priority order, and after the sending is completed, the data packets of the second priority module are sent in turn, and so on; when the host device is in the sending mode, the data packets of the first priority module are sent in priority order, and after the sending is completed, the data packets of the second priority module are sent in turn, and so on.
[0052] According to another aspect of the present application, a USART-based communication system is also provided, wherein the system includes a host device and a slave device; the host device and the slave device are connected based on USART, the slave device is set to a sending mode by default, and the host device is set to a receiving mode by default.
[0053] For example, the host device and the slave device are connected via USART single-line adsorption, and the TX (Transmit) port and RX (Receive) port of the USART of both parties are connected together.
[0054] In some embodiments, Figure 2 As shown, the host device is a keyboard, and the slave device is a tablet computer. In actual use scenarios, the tablet computer and the keyboard are connected through the USART single-line communication interface. Compared with the existing Bluetooth connection solution, it can avoid environmental interference, improve the stability of the connection, and optimize the user experience.
[0055] In some embodiments, Figure 2 As shown, the host device and the slave device are connected via a single-line Pogo Pin of USART, wherein Pogo Pin is a precision connector used in various electronic products and plays a connecting role.
[0056] In this embodiment, if the host device and the slave device both send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, combined with the start sending interrupt control register and the sending completion interrupt control register, such as Figure 3 As shown, the slave device and the host device switch alternately to the sending mode or the receiving mode, and when one of them has no data to send, the sending is skipped.
[0057] In some embodiments, after the slave device is connected to the host device, Figure 3 As shown, the USART communication interface of the slave device is set to the transmit (TX, Transmit) mode by default when it is turned on, and the USART communication interface of the host device is set to the receive (RX, Receive) mode by default. If the host device and the slave device both send data packets at the same time, the specific steps include: the slave device initiates the transmission of the first handshake data packet, and the slave device initiates an internal start-sending interrupt based on USART; at this time, the host device detects the start-sending interrupt and immediately switches to the receiving mode; if the host device also has data to send at this time, because it has detected that it is currently switched to the receiving mode, it will send data again in the time slot of the next sending mode. After the slave device sends the data packet, the slave device initiates an internal sending completion interrupt based on USART, the slave device switches to the receiving mode, and the host device switches to the sending mode, and the cycle is in sequence; when the host device wants to send a data packet, the host device initiates an internal start-sending interrupt based on USART; at this time, the slave device detects the start-sending interrupt and immediately switches to the receiving mode; if the slave device also has data to send at this time, because it has detected that it is currently switched to the receiving mode, it will send data again in the time slot of the next sending mode. After the host device sends the data packet, the host device initiates an internal transmission completion interrupt based on USART, the host device switches to the receiving mode, and the slave device switches to the sending mode. When both parties have no data to send, both parties will automatically not execute the sending (TX, Transmit) and receiving (RX, Receive) interrupt processing functions.
[0058] In some embodiments, if the host device or the modules of the slave device send data packets at the same time, such as Figure 4 As shown, according to the preset data transmission priority of each module, the data to be sent of each module are arranged in order of priority; when the host device or the slave device is in the transmission mode, the data to be sent of each module are sent according to the order of priority.
[0059] For example, the slave device has many peripheral modules, and each module runs on the system at the same time. The data to be sent is generated randomly, and there are more than two modules at random time points and data packets are sent at the same time, resulting in data congestion. The host device has relatively few modules, but there is also a scenario where module data packets are sent at the same time. In this embodiment, the data transmission priority of each module is pre-set by code, and the data transmission priority of the module can be adjusted in the encoding according to the importance of the data. When the host device or the slave device is in the sending mode, the data packets of each module are sent in order of priority, thereby solving the data congestion problem.
[0060] In some embodiments, if the host device or each module of the slave device sends a data packet at the same time, the specific steps include: Figure 4 As shown, according to the pre-set data transmission priority of each module, the data to be sent of each module are arranged in priority order; when the slave device is in the sending mode, the data packets of the first priority module are sent in priority order, and after the sending is completed, the data packets of the second priority module are sent in turn, and so on; when the host device is in the sending mode, the data packets of the first priority module are sent in priority order, and after the sending is completed, the data packets of the second priority module are sent in turn, and so on.
[0061] In summary, the embodiment of the present application provides a communication synchronization mechanism based on USART between a host device and a slave device, which solves the congestion problem of data being sent simultaneously by both the master and the slave. In addition, the embodiment of the present application solves the congestion problem of data packets being sent simultaneously by each module of the host device or the slave device by setting the data sending priority of the module and matching the sending processing logic. The data transmission bit error rate of the embodiment of the present application is 0, and the data transmission rate is high, which ensures the data transmission correctness and use stability of the device.
[0062] In addition, a part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present application through the operation of the computer. The program instruction for calling the method of the present application may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in a working memory of a computer device that runs according to the program instruction. Here, some embodiments of the present application provide a computing device, which includes a memory for storing computer program instructions and a processor for executing computer program instructions, wherein when the computer program instruction is executed by the processor, the device is triggered to execute the methods and / or technical solutions of the aforementioned multiple embodiments of the present application.
[0063] In addition, some embodiments of the present application further provide a computer-readable medium on which computer program instructions are stored. The computer-readable instructions can be executed by a processor to implement the methods and / or technical solutions of the aforementioned multiple embodiments of the present application.
[0064] It should be noted that the present application can be implemented in software and / or a combination of software and hardware, for example, can be implemented using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In certain embodiments, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including related data structures) can be stored in a computer-readable recording medium, for example, a RAM memory, a magnetic or optical drive or a floppy disk and similar devices. In addition, some steps or functions of the present application can be implemented using hardware, for example, as a circuit that cooperates with a processor to perform each step or function.
[0065] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present application is limited by the attached claims rather than the above description, so it is intended to include all changes that fall within the meaning and scope of the equivalent elements of the claims in the present application. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
Claims
1. A communication method based on USART, in, The method comprises: The host device and the slave device are connected based on USART, the slave device is set to a sending mode by default, and the host device is set to a receiving mode by default; If the host device and the slave device both send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, and in combination with the start sending interrupt control register and the sending completion interrupt control register, the slave device and the host device alternately switch to the sending mode or the receiving mode, and skip sending when one of them has no data to send; Wherein, if the host device and the slave device both send data packets at the same time, the specific steps include: the slave device initiates the transmission of the first handshake data packet, and the slave device initiates an internal start sending interrupt based on USART; at this time, the host device detects the start sending interrupt and immediately switches to the receiving mode; after the slave device sends the data packet, the slave device initiates an internal sending completion interrupt based on USART, the slave device switches to the receiving mode, and the host device switches to the sending mode, and the cycle is repeated in sequence; when the host device wants to send a data packet, the host device initiates an internal start sending interrupt based on USART; at this time, the slave device detects the start sending interrupt and immediately switches to the receiving mode; after the host device sends the data packet, the host device initiates an internal sending completion interrupt based on USART, the host device switches to the receiving mode, and the slave device switches to the sending mode.
2. The method according to claim 1, in, The method further comprises: If the modules of the host device or the slave device send data packets at the same time, the data to be sent by each module are arranged in order of priority according to the preset data sending priority of each module; When the host device or the slave device is in the sending mode, the to-be-sent data of each module are sent according to the priority order.
3. The method according to claim 2, in, If the host device or the modules of the slave device send data packets at the same time, the specific steps include: According to the preset data transmission priority of each module, the data to be sent from each module are arranged in order of priority; When the slave device is in the sending mode, the data packets of the first priority module are sent in order of priority, and after the sending is completed, the data packets of the second priority module are sent in turn, and so on; When the host device is in the sending mode, the data packets of the first priority module are sent in order of priority. After the sending is completed, the data packets of the second priority module are sent in turn, and so on.
4. The method according to any one of claims 1 to 3, in, The host device and the slave device are connected based on USART, including: The host device is connected to the slave device via a single-line Pogo Pin of USART.
5. The method according to claim 1, in, The host device is a keyboard, and the slave device is a tablet computer.
6. A communication system based on USART, in, The system includes a host device and a slave device; The host device is connected to the slave device based on USART, the slave device is set to a sending mode by default, and the host device is set to a receiving mode by default; If the host device and the slave device both send data packets at the same time, the slave device initiates the transmission of the first handshake data packet, and combines the start sending interrupt control register and the sending completion interrupt control register, and the slave device and the host device alternately switch to the sending mode or the receiving mode. If one of them has no data to send, the data is skipped and not sent.
7. The system according to claim 6, in, If the modules of the host device or the slave device send data packets at the same time, the data to be sent by each module are arranged in order of priority according to the preset data sending priority of each module; When the host device or the slave device is in the sending mode, the to-be-sent data of each module are sent according to the priority order.
8. A computing device, in, The device comprises a memory for storing computer program instructions and a processor for executing the computer program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute the method according to any one of claims 1 to 5.
9. A computer readable medium having computer program instructions stored thereon, wherein the computer program instructions can be executed by a processor to implement the method according to any one of claims 1 to 5.
