A communication method, device, equipment and readable storage medium
The communication method stabilizes MCU operation by processing data and querying its state before transmission, using timers and delay mechanisms to enhance data transmission efficiency and prevent resource waste.
Patent Information
- Application Number
- CN202110240227.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-04
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2041-03-04
AI Technical Summary
Existing communication modules frequently cause MCU to time out or crash due to immediate wake-up and interrupt signals, leading to inefficient data transmission and resource waste.
A communication method that processes data before querying the MCU status, determining its state, and sending data only when the MCU is awake, using variables to record and manage the MCU's state, and employing timers and delay mechanisms to ensure stable operation.
Improves data transmission success rate and prevents resource waste by avoiding unnecessary MCU wake-ups and interrupts, ensuring stable MCU operation.
Smart Images

Figure CN112835826B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer communication technology, and in particular to a communication method, apparatus, device and readable storage medium. Background Art
[0002] Currently, each time a communication module receives an external message, it needs to immediately send an interrupt signal to a Micro Control Unit (MCU) to wake up the MCU.
[0003] However, it should be noted that when the communication module receives an external message, it needs to process the message internally before sending it. Therefore, the MCU is immediately awakened every time an external message is received. The communication module may not be able to send the message in time, causing the MCU to time out after being awakened and enter the sleep state again, resulting in the inability to send data normally.
[0004] Furthermore, if the communication module receives an external message when the MCU is in the awake state, the communication module will still send an interrupt signal to the MCU, thus causing the MCU to frequently enter interruption, resulting in the MCU program crash and a waste of resources.
[0005] Therefore, how to improve the success rate of data transmission and avoid waste of resources is a problem that technical personnel in this field need to solve. Summary of the invention
[0006] In view of this, the purpose of this application is to provide a communication method, device, equipment and readable storage medium to improve the success rate of data transmission and avoid resource waste. The specific scheme is as follows:
[0007] In a first aspect, the present application provides a communication method, applied to a communication module, comprising:
[0008] If data that needs to be sent to the MCU is obtained, after processing the data, query the variable that records the MCU status;
[0009] Determining a current state of the MCU based on a current value assigned to the variable;
[0010] If the MCU is currently in the awake state, the processed data is sent to the MCU.
[0011] Preferably, determining the current state of the MCU according to the current value assigned to the variable comprises:
[0012] If the current value assigned to the variable is a sleep flag value, it is determined that the MCU is currently in a sleep state;
[0013] If the current value assigned to the variable is a wake-up mark value, it is determined that the MCU is currently in a wake-up state.
[0014] Preferably, it also includes:
[0015] If the MCU is currently in a sleep state, the current value of the variable is modified from the sleep flag value to the wake-up flag value;
[0016] The MCU is woken up, and the processed data is sent to the MCU.
[0017] Preferably, waking up the MCU comprises:
[0018] A timer is used to send a pulse signal of a preset duration to the MCU to wake up the MCU.
[0019] Preferably, it also includes:
[0020] If the timer times out, the pulse signal is stopped from being sent.
[0021] Preferably, between waking up the MCU and sending the processed data to the MCU, the method further includes:
[0022] Determine a delay time according to the type of the MCU, and wait for the delay time.
[0023] Preferably, it also includes:
[0024] If a DTR interrupt signal sent by the MCU is received, the wake-up mark value or the sleep mark value is assigned to the variable according to the DTR interrupt signal.
[0025] In a second aspect, the present application provides a communication device, applied to a communication module, including:
[0026] A query module is used to query the variable recording the MCU status after processing the data if the data to be sent to the MCU is obtained;
[0027] A determination module, used to determine the current state of the MCU according to the current value assigned to the variable;
[0028] A sending module is used to send the processed data to the MCU if the MCU is currently in an awake state.
[0029] In a third aspect, the present application provides an electronic device, including:
[0030] Memory for storing computer programs;
[0031] The processor is used to execute the computer program to implement the communication method disclosed above.
[0032] In a fourth aspect, the present application provides a readable storage medium for storing a computer program, wherein the computer program implements the aforementioned disclosed communication method when executed by a processor.
[0033] It can be seen from the above scheme that the present application provides a communication method, which is applied to a communication module, including: if data that needs to be sent to the MCU is obtained, then after processing the data, query the variable that records the MCU status; determine the current state of the MCU according to the current assignment of the variable; if the MCU is currently in a wake-up state, send the processed data to the MCU.
[0034] It can be seen that the present application records the MCU state in a variable. After the communication module obtains the data to be sent to the MCU, it first processes the data. After the processing is completed, the variable recording the MCU state is queried, and the current state of the MCU can be determined according to the current value of the variable. If the MCU is currently in the awake state, no interrupt signal is sent to the MCU, but the processed data is sent directly to the MCU, thereby preventing the MCU from entering the dormant state again due to the lack of new messages after being awakened, improving the success rate of data transmission, and preventing the MCU from frequently entering interrupts, ensuring the stable operation of the MCU program, and avoiding waste of resources.
[0035] Correspondingly, a communication device, equipment and readable storage medium provided by the present application also have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0037] Figure 1 A flow chart of a communication method disclosed in this application;
[0038] Figure 2 A connection structure diagram between an MCU and a communication module disclosed in this application;
[0039] Figure 3 A flow chart of another communication method disclosed in this application;
[0040] Figure 4 A flowchart of using variables to record MCU status disclosed in this application;
[0041] Figure 5 A flow chart of another communication method disclosed in this application;
[0042] Figure 6 A flowchart of determining the current value of a flag after a timer times out disclosed in the present application;
[0043] Figure 7 A schematic diagram of a communication device disclosed in this application;
[0044] Figure 8 A schematic diagram of an electronic device disclosed in this application;
[0045] Fig. 9 This is a schematic diagram of another electronic device disclosed in this application. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0047] At present, when the communication module receives an external message, it needs to process the message internally before sending the message. Therefore, the MCU is immediately awakened every time an external message is received. It may be that the communication module cannot send the message in time, causing the MCU to wait for timeout after being awakened, and then enter the dormant state, resulting in the inability to send data normally. In addition, if the communication module receives an external message when the MCU is in the awakened state, the communication module will still send an interrupt signal to the MCU at this time, thus causing the MCU to frequently enter an interrupt, causing the MCU program to crash and also causing a waste of resources. To this end, the present application provides a communication scheme that can improve the success rate of data transmission and avoid waste of resources.
[0048] See also Figure 1 As shown, the embodiment of the present application discloses a communication method, which is applied to a communication module, including:
[0049] S101. Obtain data to be sent to the MCU.
[0050] In this embodiment, the communication module may be a 2G / 3G / 4G / 5G module, or a Bluetooth module, a Wi-Fi module, etc. The MCU may be any microcontroller unit, such as a single-chip microcomputer, etc.
[0051] The connection structure between MCU and communication module can be seen in Figure 2 .exist Figure 2 In the example, the MCU sends an interrupt signal to the communication module through the DTR pin to control the communication module to sleep or wake up. The communication module sends an interrupt signal to the MCU through the UART_RING pin to wake up the MCU. UART is the communication port between the MCU and the communication module.
[0052] In a specific implementation, the data that the communication module needs to send to the MCU may be external network data, SMS (Short Messaging Service) messages or phone calls, or may be the working status data of the communication module itself, such as abnormal communication status data.
[0053] Generally, the communication module reports its own working status data to the MCU, so that the MCU can know whether the communication module is working normally in time, thereby avoiding the MCU sending AT commands to the communication module when the communication module is abnormal. The communication module can report its own working status data only when the MCU is in the awake state; otherwise, the communication module cannot report its own working status data.
[0054] S102: After the data processing is completed, query the variable recording the MCU status.
[0055] In a specific implementation, the current state of the MCU is determined according to the current value assigned to the variable, including: if the current value assigned to the variable is a sleep mark value (such as: MCU sleep), then it is determined that the MCU is currently in a sleep state; if the current value assigned to the variable is a wake-up mark value (such as: MCU wakeup), then it is determined that the MCU is currently in a wake-up state.
[0056] The present embodiment utilizes variables (such as global variables) to record the MCU state. When the MCU needs to communicate with the outside or wants to know the state of the communication module, the MCU sends a signal to the communication module through the DTR pin to wake up the communication module. At this time, because the MCU has actively woken up the communication module, it is explained that the MCU is in a wake-up state, so the MCU state is recorded as a wake-up state using variables. Of course, the communication module is also in a wake-up state at this time. Correspondingly, when the MCU does not need to communicate with the outside or does not want to know the state of the communication module, the MCU sends a signal to the communication module through the DTR pin to control the communication module to sleep. At this time, because the MCU does not want to know any message, it is explained that the MCU wants to be in a dormant state, so the MCU state is recorded as a dormant state using variables. Of course, the communication module will also enter a dormant state at this time.
[0057] S103: Determine the current state of the MCU according to the current value assigned to the variable.
[0058] S104: If the MCU is currently in the awake state, the processed data is sent to the MCU.
[0059] It should be noted that the communication module needs a certain amount of internal processing time to receive external data or collect its own working status data. Therefore, after the communication module obtains the data that needs to be sent to the MCU, it is not in a hurry to wake up the MCU. Instead, after processing this data, it queries the variables that record the MCU status.
[0060] If the MCU is currently in the awake state according to the current value of the variable, then there is no need to wake up the MCU. Instead, the processed data is sent to the MCU directly. This can prevent the MCU from entering the sleep state again after being awakened due to lack of new messages, thereby improving the success rate of data transmission, preventing the MCU from frequently entering interrupts, ensuring the stable operation of the MCU program, and avoiding waste of resources.
[0061] It can be seen that in this embodiment, the MCU state is recorded in a variable. After the communication module obtains the data to be sent to the MCU, it first processes the data. After the processing is completed, the variable recording the MCU state is queried, and the current state of the MCU can be determined according to the current value of the variable. If the MCU is currently in the awake state, no interrupt signal is sent to the MCU, but the processed data is sent directly to the MCU, thereby preventing the MCU from entering the dormant state again due to the lack of new messages after being awakened, improving the success rate of data transmission, and preventing the MCU from frequently entering interrupts, ensuring the stable operation of the MCU program, and avoiding waste of resources.
[0062] In a specific implementation, if the MCU is currently in a dormant state according to the current value of the variable, the communication module executes the following Figure 3 The steps shown, Figure 3 Specifically include:
[0063] S301, modifying the current value of the variable from the sleep mark value to the wake-up mark value;
[0064] S302, wake up MCU;
[0065] S303, sending the processed data to the MCU.
[0066] In this embodiment, waking up the MCU includes: using a timer to send a pulse signal of a preset duration to the MCU to wake up the MCU. For example, sending a pulse signal of 1000ms through the UART_RING pin to wake up the MCU. If the timer times out, the pulse signal is stopped.
[0067] If the timer times out, the UART_RING pin returns to its original level state. At this time, if there is still data that needs to be sent to the MCU, after the data is processed inside the communication module, the variable that records the MCU status is queried, and the current state of the MCU is determined based on the current value of the variable, so as to execute subsequent steps.
[0068] The execution order of step S301 and step S302 can be interchanged, and the interchange does not affect the implementation of this embodiment. Of course, step S301 and step S302 can also be executed in parallel.
[0069] In order to ensure that the MCU has enough time to switch from the sleep state to the wake-up state, between step S302 and step S303, it also includes: determining the delay time according to the type of MCU, and waiting for the delay time. For example: after sending a pulse signal lasting 1000ms, wait for 50ms, and then send data through UART. It should be noted that the delay time can be determined according to the type of MCU. Generally, the delay time corresponding to the MCU with better performance is shorter, while the delay time corresponding to the MCU with poorer performance is longer.
[0070] Since the communication module needs a certain amount of internal processing time to receive external data or collect its own working status data, after the communication module obtains the data to be sent to the MCU, it is not in a hurry to wake up the MCU. Instead, after processing the data, it queries the variables that record the MCU status.
[0071] If it is determined that the MCU is currently in sleep state based on the current value of the variable, the current value of the variable is changed from the sleep mark value to the wake-up mark value, and the MCU is woken up, so that the processed data is sent to the MCU. This can avoid repeatedly sending interrupt signals to the MCU, ensure the stable operation of the MCU program, and avoid waste of resources.
[0072] In a specific implementation, the specific process of using variables to record the MCU state includes: if the communication module receives a DTR interrupt signal sent by the MCU, assigning a wake-up mark value or a sleep mark value to the variable according to the DTR interrupt signal.
[0073] Specifically, the communication module performs the following steps: Figure 4 The DTR interrupt service steps shown are: Figure 4 Specifically include:
[0074] Step 1: The DTR pin generates an interrupt signal;
[0075] Step 2: Read the DTR level status;
[0076] Step 3: Determine the communication module status according to the DTR level status;
[0077] Step 4: If the DTR level indicates that the communication module is in sleep mode, assign the sleep flag value MCU sleep to the variable flag, that is, Set flag = MCU sleep; and control the communication module to enter the sleep state at the same time;
[0078] Step 5: If the DTR level indicates that the communication module is awake, assign the wake-up flag value MCU wakeup to the variable flag, that is, Set flag = MCU wakeup; and control the communication module to enter the awake state at the same time.
[0079] In this embodiment, flag is a global variable, which is used to save the MCU state. Figure 4 When the MCU pulls DTR to wake up the communication module, the MCU is recorded as being in the awake state; when the MCU pulls DTR to put the communication module into sleep mode, the MCU is recorded as being in the sleep mode (the MCU will enter sleep mode after processing the task).
[0080] After the communication module receives the DTR interrupt signal, it determines whether to put the communication module into sleep or wake up according to the high and low levels of DTR. When the DTR level indicates that the communication module should be woken up, the communication module exits sleep mode, and the MCU is in wake-up mode. At this time, the global variable flag is set to MCU wakeup; when the DTR level indicates that the communication module should be put into sleep mode, the communication module enters sleep mode, and the MCU is about to enter sleep mode. At this time, the global variable flag is set to MCU sleep.
[0081] Among them, the correspondence between the high and low levels of DTR and the wake-up state and the sleep state can be: when DTR is at a high level, it indicates that the communication module is in sleep; when DTR is at a low level, it indicates that the communication module is awake. Of course, it can also be set in reverse, for example: when DTR is at a low level, it indicates that the communication module is in sleep; when DTR is at a high level, it indicates that the communication module is awake. Therefore, the correspondence between the high and low levels of DTR and the wake-up state and the sleep state can be flexibly adjusted. Correspondingly, the correspondence between the high and low levels of the UART_RING pin and the wake-up state and the sleep state can also be flexibly adjusted accordingly.
[0082] See also Figure 5 As shown, the embodiment of the present application discloses another communication method applied to a communication module, including:
[0083] Step 1: Determine that the communication module needs to send data to the MCU. At this time, the data has been processed inside the communication module.
[0084] Step 2: Check the flag status;
[0085] Step 3: If flag = MCU wakeup, send data directly;
[0086] Step 4: If flag = MCU sleep, modify lag = MCU wakeup and set the level state of the UART_RING pin to wake up the MCU; after Delay 50ms, send data to the MCU.
[0087] Among them, the flag variable can be Figure 4 Assign values to the process shown.
[0088] The level state of the UART_RING pin is set to use the timer to send a 1000ms pulse signal. The delay of 50ms is to wait for the MCU to switch from the sleep state to the wake-up state. The delay size can be modified according to different MCUs.
[0089] When the communication module needs to send data to the MCU, it first determines the MCU state according to the flag value. If the MCU is awake at this time, the data is sent directly from the UART. If the MCU is in sleep mode, the communication module needs to modify the flag value and send a pulse signal to wake up the MCU, and then send the data from the UART. The communication module is executed only when it reports data to the MCU. Figure 5 The process shown in the figure is not executed when the communication module receives data. It can be seen that this embodiment takes into account the processing time of data inside the communication module, and the situation where the MCU enters the dormant state again due to lack of new messages after being awakened will not occur.
[0090] The timer is started to determine the duration of the pulse signal, which is 1000ms. If the timer times out, the level of the UART_RING pin is changed, and the pulse signal is sent. If new data needs to be sent at this time, the level of DTR is detected to determine the current value of the flag, so that it can be determined whether to execute when sending new data. Figure 1 The process shown is still executed Figure 3 For details, see the process shown in Figure 6 .
[0091] In this embodiment, when the communication module needs to send data to the MCU, it is determined whether to trigger the UART_RING pin to wake up the MCU according to the MCU state, so as to ensure that the MCU is always in the awake state when sending data to the MCU, thereby avoiding data loss.
[0092] A communication device provided in an embodiment of the present application is introduced below. The communication device described below and the communication method described above can refer to each other.
[0093] See also Figure 7 As shown, the embodiment of the present application discloses a communication device, which is applied to a communication module, including:
[0094] The query module 701 is used to query the variable recording the MCU status after processing the data if the data to be sent to the MCU is obtained;
[0095] A determination module 702, configured to determine a current state of the MCU according to a current value assigned to a variable;
[0096] The sending module 703 is used to send the processed data to the MCU if the MCU is currently in the awake state.
[0097] In a specific implementation, the determination module includes:
[0098] The first unit is used to determine that the MCU is currently in a sleep state if the current value assigned to the variable is a sleep flag value;
[0099] The second unit is used to determine that the MCU is currently in the awake state if the current assignment value of the variable is the awake mark value.
[0100] In a specific embodiment, it also includes:
[0101] A modification module is used to modify the current value of the variable from the sleep mark value to the wake-up mark value if the MCU is currently in sleep mode;
[0102] The wake-up module is used to wake up the MCU and send the processed data to the MCU.
[0103] In a specific implementation, the wake-up module is specifically used to:
[0104] The timer is used to send a pulse signal of a preset duration to the MCU to wake up the MCU.
[0105] In a specific embodiment, it also includes:
[0106] The timeout module is used to stop sending the pulse signal if the timer times out.
[0107] In a specific embodiment, it also includes:
[0108] The delay module is used to determine the delay time according to the type of MCU and wait for the delay time.
[0109] In a specific embodiment, it also includes:
[0110] The variable assignment module is used to assign a wake-up mark value or a sleep mark value to the variable according to the DTR interrupt signal if a DTR interrupt signal sent by the MCU is received.
[0111] Among them, for more specific working processes of each module and unit in this embodiment, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0112] It can be seen that this embodiment provides a communication device, which can ensure that when sending data to the MCU, the MCU is always in the awake state to avoid data loss.
[0113] An electronic device provided in an embodiment of the present application is introduced below. The electronic device described below and the communication method and device described above can refer to each other.
[0114] See also Figure 8 As shown, the embodiment of the present application discloses an electronic device, including:
[0115] Memory 801, used for storing computer programs;
[0116] The processor 802 is used to execute the computer program to implement the method disclosed in any of the above embodiments.
[0117] Please refer to Fig. 9 , Fig. 9 Another electronic device schematic diagram provided for this embodiment, the electronic device may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 322 (for example, one or more processors) and memory 332, one or more storage media 330 (for example, one or more mass storage devices) storing application programs 342 or data 344. Among them, the memory 332 and the storage medium 330 can be short-term storage or permanent storage. The program stored in the storage medium 330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the data processing device. Furthermore, the central processor 322 can be configured to communicate with the storage medium 330 to execute a series of instruction operations in the storage medium 330 on the electronic device 301.
[0118] The electronic device 301 may further include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input / output interfaces 358, and / or one or more operating systems 341. For example, Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0119] exist Fig. 9 In the embodiment, application 342 may be a program for executing a communication method, and data 344 may be data required or generated for executing the communication method.
[0120] The steps in the communication method described above may be implemented by the structure of an electronic device.
[0121] In one embodiment, the electronic device includes a target processor (MCU) and a 5G communication module (communication module). The target processor and the 5G communication module are connected via a USB (Universal Serial Bus) physical interface. The target processor runs a Windows (Microsoft) operating system. The 5G communication module includes an application processor and a baseband processor. The application processor runs an APP operating system, and the baseband processor (MODEM) runs a MODEM operating system. The APP operating system includes a user layer (user space) and an application layer (kernel space). The user layer and the application layer establish a connection through a virtual interface, and the virtual interface can be divided into a read interface and a write interface according to the function. The user layer reads the data of the application layer through the read interface, and the user layer sends data to the application layer through the write interface. The driver runs in the kernel space, and the application runs in the user space. The application layer includes a USB protocol stack, and the USB protocol stack includes UDC (USB Device Controller), Android Gadget Driver, Composite gadgetDriver, and Function Driver. The user layer includes QMIClient (QualcomMessage Interface Client), which is mainly used to send instructions, receive data and parse data. The MODEM operating system includes QMI Server (Qualcom MessageInterface Server), which is mainly used to process instructions and send data, including response data of instructions and data actively sent. QMI Server includes a server that handles different services, such as SMS (Short MessageService), USSD (Unstructured Supplementary Service Data), etc. The server and the client correspond one-to-one, and different services correspond to different clients. Among them, the electronic device can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices.
[0122] A readable storage medium provided in an embodiment of the present application is introduced below. The readable storage medium described below and the communication method, apparatus, and device described above can refer to each other.
[0123] A readable storage medium is used to store a computer program, wherein the computer program, when executed by a processor, implements the communication method disclosed in the above embodiment. The specific steps of the method can refer to the corresponding contents disclosed in the above embodiment, and will not be repeated here.
[0124] The "first", "second", "third", "fourth", etc. (if any) referred to in this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods or devices.
[0125] It should be noted that the descriptions involving "first", "second", etc. in this application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0126] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0127] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of readable storage medium known in the art.
[0128] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A communication method, It is characterized in that Applicable to communication modules, including: If data that needs to be sent to the MCU is obtained, after processing the data, query the variable that records the MCU status; Determining a current state of the MCU based on a current value assigned to the variable; If the MCU is currently in the awake state, no interrupt signal is sent to the MCU, and the processed data is sent to the MCU; Wherein, determining the current state of the MCU according to the current value of the variable includes: If the current value assigned to the variable is a sleep flag value, it is determined that the MCU is currently in a sleep state; If the current value assigned to the variable is a wake-up mark value, it is determined that the MCU is currently in a wake-up state; If a DTR interrupt signal sent by the MCU is received, the wake-up mark value or the sleep mark value is assigned to the variable according to the DTR interrupt signal; wherein, after the DTR pin generates an interrupt signal, the DTR level state is read, and the communication module state is judged according to the DTR level state. If the DTR level indicates that the communication module is dormant, the sleep mark value is assigned to the variable flag, and the communication module is controlled to enter the dormant state. If the DTR level indicates that the communication module is awakened, the wake-up mark value is assigned to the variable flag, and the communication module is controlled to enter the awakened state. If the MCU is currently in a sleep state, the current value of the variable is modified from the sleep flag value to the wake-up flag value; Waking up the MCU and sending the processed data to the MCU; Wherein, between waking up the MCU and sending the processed data to the MCU, the method further includes: Determine a delay time according to the type of the MCU, and wait for the delay time.
2. The communication method according to claim 1, It is characterized in that The waking up the MCU comprises: A timer is used to send a pulse signal of a preset duration to the MCU to wake up the MCU.
3. The communication method according to claim 2, It is characterized in that Also includes: If the timer times out, the pulse signal is stopped from being sent.
4. A communication device, It is characterized in that Applicable to communication modules, including: A query module is used to query the variable recording the MCU status after processing the data if the data to be sent to the MCU is obtained; A determination module, used to determine the current state of the MCU according to the current value assigned to the variable; A sending module, configured to stop sending an interrupt signal to the MCU if the MCU is currently in an awake state, and send the processed data to the MCU; Wherein, the determination module includes: The first unit is used to determine that the MCU is currently in a sleep state if the current value assigned to the variable is a sleep mark value; A second unit is used to determine that the MCU is currently in a wake-up state if the current assigned value of the variable is a wake-up mark value; A variable assignment module, for assigning the wake-up mark value or the sleep mark value to the variable according to the DTR interrupt signal if a DTR interrupt signal sent by the MCU is received; wherein, after the DTR pin generates an interrupt signal, the DTR level state is read, and the communication module state is judged according to the DTR level state; if the DTR level indicates that the communication module is dormant, the sleep mark value is assigned to the variable flag, and the communication module is controlled to enter the dormant state; if the DTR level indicates that the communication module is awakened, the wake-up mark value is assigned to the variable flag, and the communication module is controlled to enter the awakened state; A modification module, configured to modify the current value of the variable from the sleep mark value to the wake-up mark value if the MCU is currently in a sleep state; A wake-up module is used to wake up the MCU and send the processed data to the MCU; wherein, between waking up the MCU and sending the processed data to the MCU, it also includes: determining a delay time according to the type of the MCU and waiting for the delay time.
5. An electronic device, It is characterized in that include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the communication method according to any one of claims 1 to 3.
6. A readable storage medium, It is characterized in that Used to store a computer program, wherein the computer program implements the communication method according to any one of claims 1 to 3 when executed by a processor.
