WO2022161004A1 - 一种uart通信的波特率切换方法、装置及发起方终端 - Google Patents
一种uart通信的波特率切换方法、装置及发起方终端 Download PDFInfo
- Publication number
- WO2022161004A1 WO2022161004A1 PCT/CN2021/138768 CN2021138768W WO2022161004A1 WO 2022161004 A1 WO2022161004 A1 WO 2022161004A1 CN 2021138768 W CN2021138768 W CN 2021138768W WO 2022161004 A1 WO2022161004 A1 WO 2022161004A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- baud rate
- terminal
- switching
- uart interface
- information
- Prior art date
Links
- 239000003999 initiator Substances 0.000 title claims abstract description 120
- 238000004891 communication Methods 0.000 title claims abstract description 76
- 238000000034 method Methods 0.000 title claims abstract description 55
- 238000012790 confirmation Methods 0.000 claims description 32
- 238000004590 computer program Methods 0.000 claims description 20
- 230000008569 process Effects 0.000 description 9
- 230000005540 biological transmission Effects 0.000 description 4
- 238000004519 manufacturing process Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- HRANPRDGABOKNQ-ORGXEYTDSA-N (1r,3r,3as,3br,7ar,8as,8bs,8cs,10as)-1-acetyl-5-chloro-3-hydroxy-8b,10a-dimethyl-7-oxo-1,2,3,3a,3b,7,7a,8,8a,8b,8c,9,10,10a-tetradecahydrocyclopenta[a]cyclopropa[g]phenanthren-1-yl acetate Chemical group C1=C(Cl)C2=CC(=O)[C@@H]3C[C@@H]3[C@]2(C)[C@@H]2[C@@H]1[C@@H]1[C@H](O)C[C@@](C(C)=O)(OC(=O)C)[C@@]1(C)CC2 HRANPRDGABOKNQ-ORGXEYTDSA-N 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/0001—Systems modifying transmission characteristics according to link quality, e.g. power backoff
- H04L1/0002—Systems modifying transmission characteristics according to link quality, e.g. power backoff by adapting the transmission rate
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L1/00—Arrangements for detecting or preventing errors in the information received
- H04L1/0001—Systems modifying transmission characteristics according to link quality, e.g. power backoff
- H04L1/0023—Systems modifying transmission characteristics according to link quality, e.g. power backoff characterised by the signalling
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04R—LOUDSPEAKERS, MICROPHONES, GRAMOPHONE PICK-UPS OR LIKE ACOUSTIC ELECTROMECHANICAL TRANSDUCERS; DEAF-AID SETS; PUBLIC ADDRESS SYSTEMS
- H04R1/00—Details of transducers, loudspeakers or microphones
- H04R1/10—Earpieces; Attachments therefor ; Earphones; Monophonic headphones
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04R—LOUDSPEAKERS, MICROPHONES, GRAMOPHONE PICK-UPS OR LIKE ACOUSTIC ELECTROMECHANICAL TRANSDUCERS; DEAF-AID SETS; PUBLIC ADDRESS SYSTEMS
- H04R3/00—Circuits for transducers, loudspeakers or microphones
Definitions
- the present application relates to the technical field of portable listening devices, and in particular, to a baud rate switching method and device for UART communication, an initiator terminal, a controlled terminal, and a computer-readable storage medium.
- USB Universal Serial Bus
- CAN Controller Area Network
- SPI Serial Peripheral Interface
- CPLD Complex Programmable logic device
- TWS earphones trusted wireless interconnected stereo Bluetooth earphones
- all TWS products on the market are in the form of one charging box + two wireless earphones.
- the main functions of earphones and charging boxes include: charging wireless earphones, providing UI operation and display, and providing production support for wireless earphones. This means that communication between the wireless earphone and the charging box must be supported.
- the communication between the wireless earphone and the charging box is usually carried out by UART.
- the purpose of this application is to provide a baud rate switching method, device, initiator terminal, controlled terminal and computer-readable storage medium for UART communication, so as to enable flexible switching between the initiator terminal and the controlled terminal Match the appropriate baud rate, reduce the manual participation process, and improve the efficiency and user experience.
- the present application provides a baud rate switching method for UART communication, including:
- the initiator terminal obtains the data to be sent corresponding to the target baud rate
- the baud rate switching information includes the target baud rate
- the data to be sent is sent to the controlled party terminal through the first UART interface.
- the sending the baud rate switching information to the controlled terminal includes:
- the baud rate switching information is sent to the controlled terminal according to the preset baud rate.
- the baud rate switching information further includes: a protocol version number.
- the switching the baud rate of the first UART interface to the target baud rate includes:
- the baud rate is switched from the preset baud rate to the target baud rate.
- the method further includes:
- the confirmation information corresponding to the handshake information is used as the baud rate switching completion information, and the step of sending the data to be sent to the controlled terminal through the first UART interface is performed.
- the method further includes:
- the step of sending handshake information to the controlled party terminal at the target baud rate through the first UART interface is performed.
- the application also provides a baud rate switching device for UART communication, including:
- the data acquisition module is used to acquire the data to be sent corresponding to the target baud rate
- control module configured to send baud rate switching information to the controlled terminal; wherein, the baud rate switching information includes the target baud rate;
- a switching module for switching the baud rate of the first UART interface to the target baud rate; wherein the first UART interface of the initiator terminal is connected to the second UART interface of the controlled terminal;
- the sending module is configured to send the data to be sent to the controlled terminal through the first UART interface after acquiring the baud rate switching completion information sent by the controlled terminal.
- the present application also provides an initiator terminal, including:
- the processor is used to execute the computer program to realize the acquisition of the data to be sent corresponding to the target baud rate; send the baud rate switching information to the charged terminal; switch the baud rate of the first UART interface to the target baud rate; after obtaining the baud rate switching completion information sent by the controlled terminal, send the data to be sent to the controlled terminal through the first UART interface; wherein the baud rate
- the switching information includes the target baud rate, and the first UART interface of the initiator terminal is connected to the second UART interface of the controlled terminal.
- the application also provides a charged party terminal, including:
- the processor is used for executing the computer program to realize the acquisition of baud rate switching information sent by the initiator terminal; switching the baud rate of the second UART interface to the target baud rate in the baud rate switching information; switching After completion, send baud rate switching completion information to the initiator terminal; receive the data to be sent sent by the controlled terminal through the second UART interface; wherein, the first UART interface of the initiator terminal is connected to the terminal.
- the second UART interface of the charged party terminal is connected.
- the present application also provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the baud rate switching of the UART communication as described above is realized steps of the method.
- a baud rate switching method for UART communication includes: an initiator terminal obtains data to be sent corresponding to a target baud rate; sending baud rate switching information to the controlled terminal; wherein, the baud rate switching The information includes the target baud rate; the baud rate of the first UART interface is switched to the target baud rate; wherein, the first UART interface of the initiator terminal is connected with the second UART interface of the controlled terminal; After the baud rate switching completion information sent by the terminal, send the data to be sent to the controlled terminal through the first UART interface;
- the initiator terminal when the initiator terminal needs to use the switched baud rate of the UART communication to send data to the charged terminal, by sending the baud rate switching information to the charged terminal, the initiator terminal can control the charged terminal.
- the baud rate switching of the UART interface in the middle realizes the flexible switching of the baud rate of the UART communication between the initiator terminal and the controlled terminal, reduces the manual participation process, improves the efficiency and user experience;
- the baud rate switching completion information After the baud rate switching completion information is sent, after obtaining the baud rate switching completion information sent by the controlled terminal, the data to be sent is sent to the controlled terminal through the first UART interface, so as to ensure the accuracy of the baud rate switching. sex.
- the present application also provides a baud rate switching device, system and initiator terminal for UART communication, which also have the above beneficial effects.
- FIG. 2 is a schematic flowchart of another baud rate switching method for UART communication provided by an embodiment of the application;
- FIG. 3 is a flowchart of another baud rate switching method for UART communication provided by an embodiment of the application.
- FIG. 4 is a structural block diagram of a baud rate switching device for UART communication provided by an embodiment of the application.
- FIG. 1 is a flowchart of a baud rate switching method for UART communication provided by an embodiment of the present application.
- the method can include:
- Step 101 The initiator terminal obtains the data to be sent corresponding to the target baud rate.
- the initiator terminal in this embodiment may be one of the two terminal devices that need to perform UART communication and initiates switching of the baud rate of UART communication; correspondingly, the controlled terminal in this embodiment may be Another terminal device among the two terminal devices that need to perform UART communication, that is, the terminal device controlled by the initiator terminal to switch the baud rate of the UART communication.
- the specific device types of the initiator terminal and the controlled terminal in this embodiment can be set by the designer according to practical scenarios and user requirements.
- the initiator terminal and the controlled terminal can be electronic products such as wireless earphones, such as The initiator terminal can be a charging box or a wireless earphone.
- the charged terminal can be a wireless earphone, that is, the UART interface (ie the first UART interface) of the charging box can be connected with the wireless earphone in the charging box.
- the UART interface (ie the second UART interface) of the charging box is wired (such as contact connection);
- the charged terminal can be the charging box, that is, the UART interface of the wireless headset in the charging box (ie the first UART interface).
- the initiator terminal can be connected to the UART interface (ie the second UART interface) of the charging box; the initiator terminal can also be a wireless headset or a smart bracelet that can place a wireless headset, for example, when the initiator terminal is a smart bracelet that can place a wireless headset,
- the accused terminal can be a wireless headset; the initiator terminal and the accused terminal can also be other types of electronic products, such as IoT devices and smart wearable devices, for example, the initiator terminal can be a smart watch, and the accused terminal It can charge devices (such as magnetic chargers) for smart watches.
- the first UART interface of the initiator terminal can be wired with the second UART interface of the controlled terminal to perform UART communication, this embodiment does not impose any limitation on this.
- the data to be sent corresponding to the target baud rate obtained by the processor of the initiator terminal in this step may be the target baud rate that the initiator terminal needs to send to the controlled device through its own UART interface (ie, the first UART interface).
- data sent by the client terminal such as upgrade file data.
- the target baud rate in this step may be the baud rate of the UART communication that needs to be used when the initiator terminal sends the data to be sent to the controlled terminal through the first UART interface.
- This embodiment does not limit the specific value of the target baud rate.
- the target baud rate may be 921600 bits/s during wired upgrade.
- this embodiment does not limit the specific manner in which the processor of the initiator terminal obtains the data to be sent corresponding to the target baud rate.
- the processor can use the wired upgrade method in the prior art. It is implemented in the same or similar manner as the data acquisition method of , and this embodiment does not impose any limitation on this.
- the baud rate switching when the initiator terminal needs to use the target baud rate to send the data to be sent to the controlled terminal through UART communication is used as an example; the corresponding initiator terminal needs to pass
- the UART communication uses the target baud rate to receive the data to be received sent by the controlled terminal, it can be implemented in the same or similar manner as the method provided in this embodiment, which is not limited in this embodiment.
- Step 102 Send baud rate switching information to the controlled terminal; wherein the baud rate switching information includes the target baud rate.
- this step can be that the processor of the initiator terminal obtains the data to be sent corresponding to the target baud rate, that is, when determining that the baud rate of the UART communication with the controlled terminal needs to be switched, through Send baud rate switching information to the controlled terminal, so that the controlled terminal can switch its UART interface (that is, the second UART interface) to the target baud rate according to the received baud rate switching information, so as to realize the control of the controlled terminal. Control the baud rate switching of the UART communication of the party terminal.
- the specific method for the processor of the initiator terminal to send the baud rate switching information to the controlled terminal in this step can be set by the designer according to practical scenarios and user needs.
- the processor can use the first UART interface. , send the baud rate switching information to the charged terminal at the preset baud rate, that is, the initiator terminal can use the preset baud rate UART communication to send the baud rate switching information to the charged terminal;
- the baud rate is different from the target baud rate.
- the preset baud rate can be the same baud rate currently used by the first UART interface and the second UART interface, such as a preset default baud rate that is commonly used, such as commonly used by users 230400 bps used in scene or 115200 bps used in production.
- the processor of the initiator terminal can also send the baud rate switching information to the controlled terminal through other communication methods. Bit rate switching information; for example, the first bluetooth component in the initiator terminal can be connected to the second bluetooth component in the controlled terminal through bluetooth communication. As long as the processor can send the baud rate switching information to the controlled terminal, this embodiment does not impose any limitation on this.
- the specific content of the baud rate switching information in this step can be set by the designer according to practical scenarios and user needs.
- the baud rate switching information can include the target baud rate to inform the terminal UART of the accused party. Baud rate switching target value for communication.
- the baud rate switching information can also include the protocol version number, so that the accused terminal can parse and obtain the target baud rate in the baud rate switching information according to the protocol version number;
- the initiator terminal can use the current baud rate (ie the low baud rate in Figure 2) to send the protocol A (ie the protocol version number and the target baud rate (ie the high baud rate in Figure 2)) through UART communication baud rate switching information), so that device B (that is, the accused device) can parse the message of protocol A according to the protocol version number at the header of the message in protocol A, and obtain the target baud rate in the message.
- the controlled terminal can obtain the target baud rate in the baud rate switching information, so as to switch the baud rate of its own second UART interface to the target baud rate, this embodiment does not impose any restrictions on this.
- Step 103 Switch the baud rate of the first UART interface to the target baud rate; wherein the first UART interface of the initiator terminal is connected to the second UART interface of the controlled terminal.
- the processor of the initiator terminal can switch its own UART interface (that is, the first UART interface) to the target baud rate, so that the first UART interface can be connected with the UART interface of the controlled terminal. (ie the second UART interface) uses the target baud rate for UART communication.
- this embodiment does not limit the specific sequence of this step and step 102.
- step 102 may be performed first and then this step is performed; this step may also be performed first and then step 102, or both steps may be performed simultaneously.
- the baud rate switching information of the first UART interface can be sent to the controlled terminal while the baud rate switching information is sent to the controlled terminal.
- the baud rate is switched to the target baud rate.
- the processor may switch the baud rate of the first UART interface to The target baud rate, that is, after it is determined that the controlled terminal will switch the baud rate of the second UART interface to the target baud rate according to the received baud rate switching information, and then switch the baud rate of the first UART interface to target baud rate to avoid useless baud rate switching of the first UART interface; that is, before this step, the controlled terminal can switch the information according to the received baud rate after receiving the baud rate switching information.
- the UART communication of the baud rate prevents the initiator terminal from switching the baud rate of the first UART interface to the target baud rate.
- the processor in the first preset time (2s in FIG. 2 ) ), the baud rate of the first UART interface is switched from the preset baud rate to the target baud rate; correspondingly, the controlled terminal can receive the baud rate at the preset baud rate through the second UART interface after receiving the After switching the information and determining that the preset baud rate capable of switching the second UART interface is switched to the target baud rate, send confirmation information corresponding to the baud rate switching information to the initiator terminal using the preset baud rate through the second UART interface, And after the first preset time, the baud rate of the second UART interface is switched from the preset baud rate to the target baud rate.
- Step 104 After acquiring the baud rate switching completion information sent by the controlled terminal, send the data to be sent to the controlled terminal through the first UART interface.
- the processor of the initiator terminal obtains the baud rate switching completion information sent by the charged terminal, that is, determines that the charged terminal switches the baud rate of its second UART interface to the target baud rate After the rate is changed, the target baud rate after switching is used to send the data to be sent to the controlled terminal through the first UART interface, so as to realize the baud rate switching and data transmission of the UART communication between the initiator terminal and the controlled terminal.
- the processor sends the data to be sent to the terminal of the charged party through the first UART interface, that is, the specific method for the processor to send the data to be sent to the terminal of the charged party through the first UART interface using the target baud rate can be adopted. It is implemented in the same or similar manner as the data sending method of UART communication in the prior art, and this embodiment does not impose any limitation on this.
- the processor may also include the step of obtaining the baud rate switching completion information sent by the charged terminal, so as to determine that the charged terminal has completed the baud rate switching of its second UART interface.
- the specific method for the processor to obtain the baud rate switching completion information sent by the accused terminal that is, the specific content of the baud rate switching completion information, can be set by the designer according to the usage scenario and user needs.
- the processor can directly
- the confirmation information corresponding to the baud rate switching information sent by the initiator terminal is regarded as the baud rate switching completion information, that is, after the processor receives the confirmation information corresponding to the baud rate switching information, the default initiator terminal can complete the second UART interface. baud rate switch.
- the processor can also use the target baud rate to receive the baud rate switching completion information sent by the controlled terminal through the first UART interface; for example, the processor can directly use the target baud rate to receive the controlled terminal through the first UART interface.
- baud rate switching completion information that is, the controlled terminal can automatically send baud rate switching completion information to the initiator terminal through the second UART interface after switching the second UART interface to the target baud rate to inform the initiator The baud rate switching of the terminal UART communication is completed; the processor can also use the target baud rate to send handshake information to the controlled terminal through the first UART interface (handshake protocol B in Figure 2), and then send the handshake information through the first UART interface.
- the interface uses the confirmation information corresponding to the handshake information sent by the controlled terminal received at the target baud rate as the baud rate switching completion information, so that both the initiator terminal and the controlled terminal can determine that the baud rate switching of the UART communication is completed. For example, after the processor of the initiator terminal switches the baud rate of the first UART interface to the target baud rate, it can send handshake information to the controlled terminal through the first UART interface at the target baud rate; determine the second preset time Whether confirmation information corresponding to the handshake information is received in the segment (2s in FIG. 2 ) through the first UART interface; if so, the confirmation information corresponding to the handshake information is used as baud rate switching completion information, and step 104 is executed.
- the initiator terminal when the initiator terminal needs to use the switched baud rate of the UART communication to send data to the controlled terminal, in this embodiment, the initiator terminal sends baud rate switching information to the controlled terminal, so that the initiator terminal can send data to the controlled terminal.
- Control the baud rate switching of the UART interface in the controlled terminal realize the flexible switching of the baud rate of the UART communication between the initiator terminal and the controlled terminal, reduce the manual participation process, improve the efficiency and user experience;
- the data to be sent is sent to the controlled terminal through the first UART interface, which ensures that the wave Accuracy of bit rate switching.
- FIG. 3 is a flowchart of another baud rate switching method for UART communication provided by an embodiment of the present application.
- the method can include:
- Step 201 The initiator terminal obtains the data to be sent corresponding to the target baud rate.
- the target baud rate in this step can be a high baud rate during wired upgrade, such as 921,600 bits/s.
- the UART communication of the baud rate sends the upgrade file data to the device B (that is, the terminal of the charged party), it is determined that it needs to switch to a high baud rate to upgrade.
- Step 202 Send baud rate switching information to the charged terminal at a preset baud rate through the first UART interface; wherein the baud rate switching information includes the target baud rate and the protocol version number, and the first baud rate of the initiator terminal is:
- the UART interface is connected with the second UART interface of the charged party terminal.
- the processor of the initiator terminal can use the preset baud rate to send the baud rate switching information to the controlled terminal through the first UART interface, so as to control the receiver through the UART communication of the preset baud rate.
- the controlling terminal performs baud rate switching; correspondingly, the controlled terminal can receive the baud rate switching information at the preset baud rate through the second UART interface, and determine whether the second UART can be switched according to the baud rate switching information.
- the baud rate of the interface is switched to the target baud rate; if so, the confirmation information corresponding to the baud rate switching information is sent to the initiator terminal through the second UART interface according to the preset baud rate, and the baud rate of the second UART interface is changed. If not, send the non-switchable information corresponding to the baud rate switching information to the initiator terminal through the second UART interface at the preset baud rate, so that the initiator terminal can end the switching process.
- device A can use the current baud rate (ie preset baud rate) to send protocol A (ie baud rate switching information) to device B, and protocol A can include: protocol version number and target baud rate.
- protocol A ie baud rate switching information
- device B when device B receives protocol A of device A, it can check the current environment, and if it can be switched, it will reply the switchable Ack (that is, the confirmation message) to the initiator A, and the interval is 2 seconds (that is, the first preset After the time), switch the baud rate to the target baud rate.
- the environment does not allow switching, it will reply the Ack that cannot be switched to the initiator, so that when device A receives the Ack that does not allow switching (that is, the information that cannot be switched), it will stop switching. flow, otherwise continue to execute; the initiator A, after receiving the switchable Ack, goes to step 203 to switch the baud rate to the target baud rate.
- the device B When the device B runs to switch the baud rate and switches to the target baud rate, it can start the timer and wait for the next handshake protocol B from the initiator A, if it does not receive the second preset time (such as 2 seconds) If the protocol B of initiator A is used, it can be considered that the device of initiator A has not been switched successfully, and device B will fall back to the default low baud rate of 115200.
- the second preset time such as 2 seconds
- Step 203 After receiving the confirmation information corresponding to the baud rate switching information sent by the controlled terminal at the preset baud rate through the first UART interface, after the first preset time, change the baud rate of the first UART interface to the preset baud rate. Set the baud rate to switch to the target baud rate.
- the processor of the initiator terminal can receive confirmation information corresponding to the baud rate switching information sent by the controlled terminal at a preset baud rate through the first UART interface, that is, it is determined that the controlled terminal can switch the UART After the baud rate of the communication is determined, the baud rate of the first UART interface is switched from the preset baud rate to the target baud rate after the first preset time, so as to complete the switching of the baud rate of the UART communication by itself.
- this embodiment does not limit the specific time value of the first preset time.
- the first preset time may be 2 seconds.
- Step 204 Send the handshake information to the controlled terminal at the target baud rate through the first UART interface.
- the processor of the initiator terminal sends handshake information to the controlled terminal by using the target baud rate that has been switched, so that the controlled terminal can determine that the baud rate switch of the initiator terminal is completed after receiving the handshake information.
- the accused terminal can send confirmation information corresponding to the handshake information to the initiator terminal through the second UART interface at the target baud rate to inform the initiator terminal that the UART communication switching is completed.
- handshake protocol B ie, handshake information
- Step 205 determine whether the confirmation information corresponding to the handshake information is received through the first UART interface within the second preset time period; if yes, go to step 206 .
- this step can be for the processor of the initiator terminal to determine whether the terminal of the accused party has completed the wave by judging whether the confirmation information corresponding to the handshake information is received through the first UART interface within the second preset time period. Baud rate switching; if yes, it can be determined that the charged terminal has completed the baud rate switching, that is, the baud rate switching of the UART communication is completed, and the process can proceed to step 206 .
- the baud rate of the first UART interface can be directly switched back to the preset baud rate to end.
- This process it is also possible to judge whether the threshold of the number of transmissions is reached; if the threshold of the number of transmissions is reached, the baud rate of the first UART interface is switched from the target baud rate to the preset baud rate; if the threshold of the number of transmissions is not reached, it returns Step 204, using the target baud rate again to send the handshake information.
- This embodiment does not impose any limitation on this.
- device A after switching the baud rate to the target baud rate, device A can start sending handshake protocol B (that is, handshake information) to device B, and at the same time start a timer to wait for device B to return to the handshake protocol.
- Ack of B that is, confirmation information
- the timer period that is, the second preset time
- the timer period can be defined by itself according to the situation, such as 2 seconds in FIG. 2 .
- the device B If the device B receives the handshake protocol B, it will reply the Ack of the handshake protocol B to the device A, so that the device A can confirm that the baud rate of both parties has been switched successfully according to the Ack of the handshake protocol B, and can execute the subsequent process, if the initiator A times out If it is not received, the initiator A will re-send protocol B, and retries 3 times (that is, the threshold of sending times is 4). If the Ack reply from device B is not received, it is considered that the switching fails and the baud rate is switched back to the default. of 115200.
- Step 206 Send the data to be sent to the controlled terminal through the first UART interface.
- the processor of the initiator terminal uses the target baud rate to send the controlled terminal to the controlled terminal through the first UART interface.
- the party terminal sends the data to be sent.
- the initiator terminal of the embodiment of this application uses the UART communication of the first UART interface to complete the control of the baud rate switching of the controlled terminal, avoiding the use of other communication methods; and by judging the second preset Whether the confirmation information corresponding to the handshake information is received through the first UART interface within the time period can accurately determine whether the baud rate switching of the controlled terminal is completed, which ensures the accuracy of the baud rate switching.
- FIG. 4 is a structural block diagram of a baud rate switching device for UART communication provided by an embodiment of the present application.
- the device can be applied to the initiator terminal, and can include:
- the data acquisition module 10 is used for acquiring the data to be sent corresponding to the target baud rate
- the control module 20 is used for sending baud rate switching information to the controlled terminal; wherein, the baud rate switching information includes the target baud rate;
- the switching module 30 is used for switching the baud rate of the first UART interface to the target baud rate; wherein, the first UART interface of the initiator terminal is connected with the second UART interface of the controlled terminal;
- the sending module 40 is configured to send the data to be sent to the controlled terminal through the first UART interface after acquiring the baud rate switching completion information sent by the controlled terminal.
- control module 20 may be specifically configured to send the baud rate switching information to the controlled terminal at a preset baud rate through the first UART interface.
- the baud rate switching information further includes: a protocol version number.
- the switching module 30 may be specifically configured to, after receiving the confirmation information corresponding to the baud rate switching information sent by the controlled terminal at a preset baud rate through the first UART interface, switch the first baud rate after the first preset time.
- the baud rate of the UART interface is switched from the preset baud rate to the target baud rate.
- the device may also include:
- the handshake sending module is used to send handshake information to the controlled terminal according to the target baud rate through the first UART interface;
- the judgment module is used for judging whether the confirmation information corresponding to the handshake information is received through the first UART interface within the second preset time period; Send start signal.
- the device may also include:
- the number of times judgment module is used to judge whether the threshold of the times of sending is reached when the confirmation information corresponding to the handshake information is not received within the second preset time period; if the threshold of the times of sending is reached, the baud rate of the first UART interface The baud rate is switched to the preset baud rate; if the threshold of sending times is not reached, a start signal is sent to the handshake sending module.
- the initiator terminal when the initiator terminal needs to use the switched baud rate of the UART communication to send data to the controlled terminal, in this embodiment, the initiator terminal sends baud rate switching information to the controlled terminal, so that the initiator terminal can send data to the controlled terminal.
- Control the baud rate switching of the UART interface in the controlled terminal realize the flexible switching of the baud rate of the UART communication between the initiator terminal and the controlled terminal, reduce the manual participation process, improve the efficiency and user experience;
- the data to be sent is sent to the controlled terminal through the first UART interface, which ensures that the wave Accuracy of bit rate switching.
- Embodiments of the present application also provide an initiator terminal, including: a memory for storing a computer program; a processor for executing the computer program to obtain data to be sent corresponding to a target baud rate; sending data to the accused terminal Baud rate switching information; switch the baud rate of the first UART interface to the target baud rate; after obtaining the baud rate switching completion information sent by the controlled terminal, send the waiting information to the controlled terminal through the first UART interface.
- the initiator terminal may specifically be a wireless earphone or a charging box.
- the embodiment of the present application also provides an initiator terminal, including: a memory for storing a computer program; a processor for executing the computer program to realize the acquisition of baud rate switching information sent by the initiator terminal; a second UART
- the baud rate of the interface is switched to the target baud rate in the baud rate switching information; after the switching is completed, the baud rate switching completion information is sent to the initiator terminal; the data to be sent sent by the controlled terminal is received through the second UART interface ; wherein, the first UART interface of the initiator terminal is connected with the second UART interface of the charged party terminal.
- the initiator terminal may be a wireless earphone or a charging box.
- the charged terminal may be a charging box.
- the embodiments of the present application also provide a computer-readable storage medium on which a computer program is stored.
- the storage medium may include: U disk, removable hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes.
Landscapes
- Engineering & Computer Science (AREA)
- Signal Processing (AREA)
- Quality & Reliability (AREA)
- Computer Networks & Wireless Communication (AREA)
- Physics & Mathematics (AREA)
- Acoustics & Sound (AREA)
- Communication Control (AREA)
Abstract
本申请公开了一种UART通信的波特率切换方法、装置、系统及发起方终端,该方法包括:发起方终端获取目标波特率对应的待发送数据;向被控方终端发送波特率切换信息;其中,波特率切换信息包括目标波特率;将第一UART接口的波特率切换至目标波特率;在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据;本申请在发起方终端需要利用切换后的UART通信的波特率向被控方终端发送数据时,通过向被控方终端发送波特率切换信息,使发起方终端控制被控方终端中UART接口的波特率切换,实现发起方终端与被控方终端之间UART通信的波特率的灵活切换,减少了人为参与过程,提升效率和用户体验。
Description
本申请要求于2021年1月28日提交中国专利局、申请号202110118503.9、申请名称为“一种UART通信的波特率切换方法、装置及发起方终端”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及便携式收听设备技术领域,特别涉及一种UART通信的波特率切换方法、装置、发起方终端、被控方终端及计算机可读存储介质。
近年以来虽然出现了多种串行总线通信技术,例如USB(通用串行总线)、CAN(Controller Area Network,控制器局域网络)、SPI(Serial Peripheral Interface,串行外设接口)和CPLD(复杂可编程逻辑器件)等,UART(Universal Asynchronous Receiver/Transmitter,通用异步收发传输器)通信凭借协议简单、所需接口线较少(可使用一根线进行单线通信)和稳定可靠等优点,使其在电子产品的有线通信中依然占有重要地位。
UART通信中双方波特率保持一致是可以正常通信的基础,但是在TWS上可能不同场景需要使用不用的串口波特率,例如生产时使用低波特率(如115200),用户常用场景时使用230400波特率,有线升级时使用高波特率(如921600)等。这就意味着产品需要支持波特率的切换以适应不同的使用场景,否则就会出现因为波特率不同导致双方无法通信的情况。
以电子产品中的无线耳机产品为例,随着TWS耳机(真正无线互连立体声蓝牙耳机)日益成为无线耳机产品的主流,市面上所有的TWS产品的形态均为一台充电盒+两台无线耳机,充电盒的主要作用包括:为无线耳机充电、提供UI操作和显示以及为无线耳机提供生产支持等。这意味着无线耳机与充电盒之间必须支持通信,而目前市面上TWS耳机中,无线耳机与充电盒之间通常也采用UART方式进行通信。
现有技术中,往往采用先分别单独给无线耳机和充电盒切换到目标波特率,然后再将双方组合到一起的方法进行波特率切换,这种方法比较原始,而且效率较低。因此,如何能够使两个设备之间能够灵活地切换匹配适合的波特率,减少人为参与过程,提升效率和用户体验,是现今急需解决的问题。
发明内容
本申请的目的是提供一种UART通信的波特率切换方法、装置、发起方终端、被控方终端及计算机可读存储介质,以使发起方终端与被控方终端之间能够灵活地切换匹配适合的波特率,减少人为参与过程,提升效率和用户体验。
为解决上述技术问题,本申请提供一种UART通信的波特率切换方法,包括:
发起方终端获取目标波特率对应的待发送数据;
向被控方终端发送波特率切换信息;其中,所述波特率切换信息包括所述目标波特率;
将第一UART接口的波特率切换至所述目标波特率;其中,所述发起方终端的所述第一UART接口与所述被控方终端的第二UART接口连接;
在获取所述被控方终端发送的波特率切换完成信息后,通过所述第一UART接口向所述被控方终端发送所述待发送数据。
可选的,所述向被控方终端发送波特率切换信息,包括:
通过所述第一UART接口,按预设波特率向所述被控方终端发送波特率切换信息。
可选的,所述波特率切换信息还包括:协议版本号。
可选的,所述将第一UART接口的波特率切换至所述目标波特率,包括:
通过所述第一UART接口按所述预设波特率接收所述被控方终端发送的所述波特率切换信息对应的确认信息后,在第一预设时间后将第一UART接口的波特率由所述预设波特率切换至所述目标波特率。
可选的,所述将第一UART接口的波特率切换至所述目标波特率之后,还包括:
通过所述第一UART接口,按所述目标波特率向所述被控方终端发送握手信息;
判断第二预设时间段内是否通过所述第一UART接口接收到所述握手信息对应的确认信息;
若是,则将所述握手信息对应的确认信息作为所述波特率切换完成信息,执行所述通过所述第一UART接口向所述被控方终端发送所述待发送数据的步骤。
可选的,所述判断第二预设时间段内是否通过所述第一UART接口接收到所述握手信息对应的确认信息之后,还包括:
在所述第二预设时间段内未接收到所述握手信息对应的确认信息时,判断是否达到发送次数阈值;
若达到所述发送次数阈值,则将所述第一UART接口的波特率由所述目标波特率切换至所述预设波特率;
若未达到所述发送次数阈值,则执行所述通过所述第一UART接口,按所述目标波特率向所述被控方终端发送握手信息的步骤。
本申请还提供了一种UART通信的波特率切换装置,包括:
数据获取模块,用于获取目标波特率对应的待发送数据;
控制模块,用于向被控方终端发送波特率切换信息;其中,所述波特率切换信息包括所述目标波特率;
切换模块,用于将第一UART接口的波特率切换至所述目标波特率;其中,发起方终端的所述第一UART接口与所述被控方终端的第二UART接口连接;
发送模块,用于在获取所述被控方终端发送的波特率切换完成信息后,通过所述第一UART接口向所述被控方终端发送所述待发送数据。
本申请还提供了一种发起方终端,包括:
存储器,用于存储计算机程序;
处理器,用于执行所述计算机程序,实现实现获取目标波特率对应的待发送数据;向被控方终端发送波特率切换信息;将第一UART接口的波特率切换至所述目标波特率;在获 取所述被控方终端发送的波特率切换完成信息后,通过所述第一UART接口向所述被控方终端发送所述待发送数据;其中,所述波特率切换信息包括所述目标波特率,所述发起方终端的所述第一UART接口与所述被控方终端的第二UART接口连接。
本申请还提供了一种被控方终端,包括:
存储器,用于存储计算机程序;
处理器,用于执行所述计算机程序,实现获取发起方终端发送的波特率切换信息;将第二UART接口的波特率切换至所述波特率切换信息中的目标波特率;切换完成后,向所述发起方终端发送波特率切换完成信息;通过所述第二UART接口接收所述被控方终端发送的待发送数据;其中,所述发起方终端的第一UART接口与所述被控方终端的所述第二UART接口连接。
此外,本申请还提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如上述所述的UART通信的波特率切换方法的步骤。
本申请所提供的一种UART通信的波特率切换方法,包括:发起方终端获取目标波特率对应的待发送数据;向被控方终端发送波特率切换信息;其中,波特率切换信息包括目标波特率;将第一UART接口的波特率切换至目标波特率;其中,发起方终端的第一UART接口与被控方终端的第二UART接口连接;在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据;
可见,本申请在发起方终端需要利用切换后的UART通信的波特率向被控方终端发送数据时,通过向被控方终端发送波特率切换信息,使发起方终端控制被控方终端中UART接口的波特率切换,实现发起方终端与被控方终端之间UART通信的波特率的灵活切换,减少了人为参与过程,提升效率和用户体验;并且通过在获取被控方终端发送的波特率切换完成信息后,通过在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据,保证了波特率切换的准确性。此外,本申请还提供了一种UART通信的波特率切换装置、系统及发起方终端,同样具有上述有益效果。
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。
图1为本申请实施例所提供的一种UART通信的波特率切换方法的流程图;
图2为本申请实施例所提供的另一种UART通信的波特率切换方法的流程示意图;
图3为本申请实施例所提供的另一种UART通信的波特率切换方法的流程图;
图4为本申请实施例所提供的一种UART通信的波特率切换装置的结构框图。
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
请参考图1,图1为本申请实施例所提供的一种UART通信的波特率切换方法的流程图。该方法可以包括:
步骤101:发起方终端获取目标波特率对应的待发送数据。
其中,本实施例中的发起方终端可以为需要进行UART通信的两个终端设备中的一个发起切换UART通信的波特率的终端设备;相应的,本实施例中的被控方终端可以为需要进行UART通信的两个终端设备中的另一个终端设备,即被发起方终端控制切换UART通信的波特率的终端设备。对于本实施例中发起方终端和被控方终端的具体设备类型,可以由设计人员根据实用场景和用户需求自行设置,如发起方终端和被控方终端可以为无线耳机类的电子产品,如发起方终端可以为充电盒或无线耳机,例如发起方终端为充电盒时,被控方终端可以为无线耳机,即充电盒的UART接口(即第一UART接口)可以与充电盒中的无线耳机的UART接口(即第二UART接口)有线连接(如接触连接);发起方终端为无线耳机时,被控方终端可以为充电盒,即充电盒中无线耳机的UART接口(即第一UART接口)可以与充电盒的UART接口(即第二UART接口)连接;发起方终端也可以为无线耳机或能够放置无线耳机的智能手环,例如发起方终端为能够放置无线耳机的智能手环时,被控方终端可以为无线耳机;发起方终端和被控方终端也可以为其它类型的电子产品,如物联网设备和智能穿戴设备等,例如发起方终端可以为智能腕表,被控方终端可以为智能腕表的充电设备(如磁吸式充电器)。只要发起方终端的第一UART接口可以与被控方终端的第二UART接口有线连接并进行UART通信,本实施例对此不作任何限制。
具体的,本步骤中发起方终端的处理器获取的目标波特率对应的待发送数据,可以为发起方终端需要通过自身的UART接口(即第一UART接口)使用目标波特率向被控方终端发送的数据,如升级文件数据。本步骤中的目标波特率可以为发起方终端通过第一UART接口向被控方终端发送待发送数据时所需要使用的UART通信的波特率。本实施例并不限定目标波特率的具体数值,如待发送数据为升级文件数据时,目标波特率可以为有线升级时的 921600位/秒。
对应的,本实施例并不限定发起方终端的处理器获取目标波特率对应的待发送数据的具体方式,如待发送数据为升级文件数据时,处理器可以采用与现有技术中有线升级的数据获取方法相同或相似的方式实现,本实施例对此不做任何限制。
需要说明的是,本实施例是以发起方终端需要通过UART通信使用目标波特率向被控方终端发送待发送数据时的波特率切换为例进行的展示;对应的发起方终端需要通过UART通信使用目标波特率接收被控方终端发送的待接收数据时,可以采用与本实施例所提供的方法相同或相似的方式实现,本实施例对此不做任何限制。
步骤102:向被控方终端发送波特率切换信息;其中,波特率切换信息包括目标波特率。
可以理解的是,本步骤的目的可以为发起方终端的处理器在获取目标波特率对应的待发送数据,即确定需要切换与被控方终端之间的UART通信的波特率时,通过向被控方终端发送波特率切换信息,使被控方终端能够根据接收的波特率切换信息,将其UART接口(即第二UART接口)切换至目标波特率,从而实现对被控方终端的UART通信的波特率切换的控制。
对应的,对于本步骤中发起方终端的处理器向被控方终端发送波特率切换信息的具体方式,可以由设计人员根据实用场景和用户需求自行设置,如处理器可以通过第一UART接口,按预设波特率向被控方终端发送波特率切换信息,即发起方终端可以使用预设波特率的UART通信向被控方终端发送波特率切换信息;其中,预设波特率与目标波特率为不同数据,预设波特率可以为第一UART接口和第二UART接口当前相同的波特率,如预设的一个默认常规使用的波特率,例如用户常用场景时使用的230400位/秒或生产时使用的115200位/秒。发起方终端的处理器也可以通过其他通信方式向被控方终端发送波特率切换信息,如处理器可以利用发起方终端中的无线通讯部件(如蓝牙部件),向被控方终端发送波特率切换信息;例如发起方终端中的第一蓝牙部件可以与被控方终端中的第二蓝牙部件蓝牙通讯连接。只要处理器可以将波特率切换信息发送到被控方终端,本实施例对此不做任何限制。
具体的,对于本步骤中的波特率切换信息的具体内容,可以由设计人员根据实用场景和用户需求自行设置,如波特率切换信息可以包括目标波特率,以告知被控方终端UART通信的波特率切换目标值。波特率切换信息还可以包括协议版本号,以使被控方终端可以根据协议版本号解析得到波特率切换信息中的目标波特率;如图2所示,本步骤中设备A(即发起方终端)可以通过UART通信使用当前波特率(即图2中的低波特率)发送包括协议版本 号和目标波特率(即图2中的高波特率)的协议A(即波特率切换信息),使设备B(即被控方设备)能够根据协议A中报文头处的协议版本号对协议A的报文进行解析,得到报文中的目标波特率。只要被控方终端能够获取波特率切换信息中的目标波特率,从而将自身的第二UART接口的波特率切换至目标波特率,本实施例对此不做任何限制。
步骤103:将第一UART接口的波特率切换至目标波特率;其中,发起方终端的第一UART接口与被控方终端的第二UART接口连接。
可以理解的是,本步骤的目的可以发起方终端的处理器通过将自身的UART接口(即第一UART接口)切换至目标波特率,使第一UART接口可以与被控方终端的UART接口(即第二UART接口)使用目标波特率进行UART通信。
对应的,本实施例并不限定本步骤与步骤102的具体先后顺序,可以本实施例所示先进行步骤102再进行本步骤;也可以先进行本步骤再进行步骤102,或者两个步骤同时进行,如步骤102使用UART通信之外的其它通信方式向被控方终端发送波特率切换信息时,可以在向被控方终端发送波特率切换信息的同时,将第一UART接口的波特率切换至目标波特率。
具体的,本步骤中处理器可以在获取被控方终端发送的波特率切换信息对应的确认信息(如图2中的协议A的Ack)后,将第一UART接口的波特率切换至目标波特率,即在确定被控方终端会根据接收到波特率切换信息将第二UART接口的波特率切换至目标波特率后,再将第一UART接口的波特率切换至目标波特率,以避免无用的第一UART接口的波特率切换;也就是说,本步骤之前被控方终端可以在接收到波特率切换信息后,根据接收的波特率切换信息,确定是否能够将第二UART接口的波特率切换至目标波特率;若是,则向发起方终端发送波特率切换信息对应的确认信息,并将第二UART接口的波特率切换至目标波特率;若否,则不向发起方终端发送波特率切换信息对应的确认信息,或向发起方终端发送波特率切换信息对应的不可切换信息,以告知发起方终端当前无法进行目标波特率的UART通信,避免发起方终端将第一UART接口的波特率切换至目标波特率。
例如,本步骤中处理器在通过第一UART接口按预设波特率接收被控方终端发送的波特率切换信息对应的确认信息后,在第一预设时间(如图2中的2s)后将第一UART接口的波特率由预设波特率切换至目标波特率;相应的,被控方终端可以在接收到通过第二UART接口按预设波特率接收波特率切换信息且确定能够切换第二UART接口的预设波特率切换至目标波特率后,通过第二UART接口使用预设波特率向发起方终端发送波特率切换信息对应的确认信息,并在第一预设时间后将第二UART接口的波特率由预设波特率切换至目标波特率。
步骤104:在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据。
具体的,本步骤的目的可以发起方终端的处理器在获取被控方终端发送的波特率切换完成信息,即确定被控方终端将其第二UART接口的波特率切换至目标波特率后,通过第一UART接口使用切换完成的目标波特率向被控方终端发送待发送数据,以实现发起方终端和被控方终端之间的UART通信的波特率切换和数据传输。
其中,本步骤中处理器通过第一UART接口向被控方终端发送待发送数据,即处理器通过第一UART接口使用目标波特率向被控方终端发送待发送数据的具体方式,可以采用与现有技术中的UART通信的数据发送方法相同或相似方式实现,本实施例对此不做任何限制。
可以理解的是,本步骤之前还可以包括处理器获取被控方终端发送的波特率切换完成信息的步骤,以确定被控方终端完成了其第二UART接口的波特率切换。对于处理器获取被控方终端发送的波特率切换完成信息的具体方式,即波特率切换完成信息的具体内容,可以由设计人员根据使用场景和用户需求自行设置,如处理器可以直接将发起方终端发送的波特率切换信息对应的确认信息作为波特率切换完成信息,即处理器可以在接收到波特率切换信息对应的确认信息后,默认发起方终端能够完成第二UART接口的波特率切换。处理器也可以通过第一UART接口使用目标波特率接收的被控方终端发送的波特率切换完成信息;如处理器可以直接通过第一UART接口使用目标波特率接收被控方终端发送的波特率切换完成信息,即被控方终端可以在将第二UART接口的切换至目标波特率之后自动通过第二UART接口向发起方终端发送波特率切换完成信息,以告知发起方终端UART通信的波特率切换完成;处理器也可以先通过第一UART接口使用目标波特率向被控方终端发送握手信息(如图2中的握手协议B),之后将通过第一UART接口使用目标波特率接收的被控方终端发送的握手信息对应的确认信息作为波特率切换完成信息,以使发起方终端和被控方终端均能确定UART通信的波特率切换完成。例如发起方终端的处理器将第一UART接口的波特率切换至目标波特率后,可以通过第一UART接口按目标波特率向被控方终端发送握手信息;判断第二预设时间段(如图2中的2s)内是否通过第一UART接口接收到握手信息对应的确认信息;若是,则将握手信息对应的确认信息作为波特率切换完成信息,执行步骤104。
本实施例中,本申请实施例在发起方终端需要利用切换后的UART通信的波特率向被控方终端发送数据时,通过向被控方终端发送波特率切换信息,使发起方终端控制被控方终端中UART接口的波特率切换,实现发起方终端与被控方终端之间UART通信的波特率的灵活 切换,减少了人为参与过程,提升效率和用户体验;并且通过在获取被控方终端发送的波特率切换完成信息后,通过在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据,保证了波特率切换的准确性。
请参考图3,图3为本申请实施例所提供的另一种UART通信的波特率切换方法的流程图。该方法可以包括:
步骤201:发起方终端获取目标波特率对应的待发送数据。
具体的,如图2所示,本步骤中的目标波特率可以为有线升级时的高波特率,如921600位/秒,本步骤中设备A(即发起方终端)可以获取需要通过高波特率的UART通信向设备B(即被控方终端)发送的升级文件数据时,确定需要切往高波特率进行升级。
步骤202:通过第一UART接口,按预设波特率向被控方终端发送波特率切换信息;其中,波特率切换信息包括目标波特率和协议版本号,发起方终端的第一UART接口与被控方终端的第二UART接口连接。
可以理解的是,本步骤中发起方终端的处理器可以使用预设波特率通过第一UART接口向被控方终端发送波特率切换信息,以通过预设波特率的UART通信控制被控方终端进行波特率切换;对应的,被控方终端可以通过第二UART接口,按预设波特率接收波特率切换信息后,根据特率切换信息,确定是否能够将第二UART接口的波特率切换至目标波特率;若是,则通过第二UART接口按预设波特率向发起方终端发送波特率切换信息对应的确认信息,并将第二UART接口的波特率切换至目标波特率;若否,则通过第二UART接口按预设波特率向发起方终端发送波特率切换信息对应的不可切换信息,以使发起方终端能够结束切换流程。
具体的,如图2所示,本步骤中设备A可以使用当前波特率(即预设波特率)发送协议A(即波特率切换信息)给设备B,协议A可以包括:协议版本号和目标波特率。相应的,当设备B收到设备A的协议A时,可以检查当前环境,如果可以切换,则回复可以切换的Ack(即确认信息)给发起方A,同时间隔2秒(即第一预设时间)后将波特率切换至目标波特率,如果环境不允许切换,则回复不能切换的Ack给发起方,使得设备A接到不允许切换的Ack(即不可切换信息)时,停止切换流程,否则继续执行;发起方A在收到可以切换的Ack后进入步骤203将波特率切换至目标波特率。当设备B运行切换波特率,并且切换至目标波特率后,可以起定时器,等待发起方A的下一条握手协议B,如果在第二预设时间(如2秒)内 未收到发起方A的协议B,则可以认为发起方A设备未切换成功,设备B回退至默认的115200的低波特率。
步骤203:通过第一UART接口按预设波特率接收被控方终端发送的波特率切换信息对应的确认信息后,在第一预设时间后将第一UART接口的波特率由预设波特率切换至目标波特率。
其中,本步骤中发起方终端的处理器可以在通过第一UART接口按预设波特率接收被控方终端发送的波特率切换信息对应的确认信息,即确定被控方终端能够切换UART通信的波特率后,在第一预设时间后将第一UART接口的波特率由预设波特率切换至目标波特率,完成自身对UART通信的波特率的切换。
具体的,本实施例并不限定第一预设时间的具体时间值,如图2所示,第一预设时间可以为2秒。
步骤204:通过第一UART接口,按目标波特率向被控方终端发送握手信息。
其中,本步骤中发起方终端的处理器通过利用切换完成的目标波特率向被控方终端发送握手信息,使被控方终端接收到握手信息后能够确定发起方终端的波特率切换完成;对应的,被控方终端可以通过第二UART接口,按目标波特率向发起方终端发送握手信息对应的确认信息,以告知发起方终端UART通信切换完成。如图2所示,设备A可以在将波特率切换至目标波特率后,开始发送握手协议B(即握手信息)给设备B。
步骤205:判断第二预设时间段内是否通过第一UART接口接收到握手信息对应的确认信息;若是,则进入步骤206。
可以理解的是,本步骤的目的可以为发起方终端的处理器通过判断第二预设时间段内是否通过第一UART接口接收到握手信息对应的确认信息,确定被控方终端是否完成了波特率切换;若是,则可以确定被控方终端完成了波特率切换,即UART通信的波特率切换完成,可以进入步骤206。
对应的,对于本步骤中第二预设时间段内未通过第一UART接口接收到握手信息对应的确认信息的情况,可以直接将第一UART接口的波特率切换回预设波特率结束本流程;也可以判断是否达到发送次数阈值;若达到发送次数阈值,则将第一UART接口的波特率由目标波特率切换至预设波特率;若未达到发送次数阈值,则返回步骤204,再次利用目标波特率发送握手信息。本实施例对此不作任何限制。
具体的,如图2所示,设备A可以在将波特率切换至目标波特率后,开始发送握手协议B (即握手信息)给设备B,同时起定时器,等待设备B返回握手协议B的Ack(即确认信息);其中,定时器周期(即第二预设时间)可根据情况自行定义,如图2中的2秒。设备B如果收到握手协议B,则回复握手协议B的Ack给设备A,使设备A可以根据握手协议B的Ack,确定双方波特率已经切换成功,可以执行后续流程,如果发起方A超时后没有收到,则发起方A再重新发送协议B,重试3次(即发送次数阈值为4)如果没有收到设备B回复的Ack,则认为切换失败,将波特率切回至默认的115200。
步骤206:通过第一UART接口向被控方终端发送待发送数据。
可以理解的是,本步骤中发起方终端的处理器在确定被控方终端将第二UART接口的波特率切换至目标波特率后,通过第一UART接口使用目标波特率向被控方终端发送待发送数据。
本实施例中,本申请实施例发起方终端使用第一UART接口的UART通信,完成对被控方终端的波特率切换的控制,避免了其它通信方式的使用;并且通过判断第二预设时间段内是否通过第一UART接口接收到握手信息对应的确认信息,能够准确地确定被控方终端的波特率切换是否切换完成,保证了波特率切换的准确性。
请参考图4,图4为本申请实施例所提供的一种UART通信的波特率切换装置的结构框图。该装置可以应用于发起方终端,可以包括:
数据获取模块10,用于获取目标波特率对应的待发送数据;
控制模块20,用于向被控方终端发送波特率切换信息;其中,波特率切换信息包括目标波特率;
切换模块30,用于将第一UART接口的波特率切换至目标波特率;其中,发起方终端的第一UART接口与被控方终端的第二UART接口连接;
发送模块40,用于在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据。
可选的,控制模块20可以具体用于通过第一UART接口,按预设波特率向被控方终端发送波特率切换信息。
可选的,波特率切换信息还包括:协议版本号。
可选的,切换模块30可以具体用于通过第一UART接口按预设波特率接收被控方终端发送的波特率切换信息对应的确认信息后,在第一预设时间后将第一UART接口的波特率由预 设波特率切换至目标波特率。
可选的,该装置还可以包括:
握手发送模块,用于通过第一UART接口,按目标波特率向被控方终端发送握手信息;
判断模块,用于判断第二预设时间段内是否通过第一UART接口接收到握手信息对应的确认信息;若是,则将握手信息对应的确认信息作为波特率切换完成信息,向发送模块40发送启动信号。
可选的,该装置还可以包括:
次数判断模块,用于在第二预设时间段内未接收到握手信息对应的确认信息时,判断是否达到发送次数阈值;若达到发送次数阈值,则将第一UART接口的波特率由目标波特率切换至预设波特率;若未达到发送次数阈值,则向握手发送模块发送启动信号。
本实施例中,本申请实施例在发起方终端需要利用切换后的UART通信的波特率向被控方终端发送数据时,通过向被控方终端发送波特率切换信息,使发起方终端控制被控方终端中UART接口的波特率切换,实现发起方终端与被控方终端之间UART通信的波特率的灵活切换,减少了人为参与过程,提升效率和用户体验;并且通过在获取被控方终端发送的波特率切换完成信息后,通过在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据,保证了波特率切换的准确性。
本申请实施例还提供了一种发起方终端,包括:存储器,用于存储计算机程序;处理器,用于执行计算机程序,实现获取目标波特率对应的待发送数据;向被控方终端发送波特率切换信息;将第一UART接口的波特率切换至目标波特率;在获取被控方终端发送的波特率切换完成信息后,通过第一UART接口向被控方终端发送待发送数据;其中,波特率切换信息包括目标波特率,发起方终端的第一UART接口与被控方终端的第二UART接口连接。
也就是说,发起方终端的处理器执行存储器中存储的计算机程序时,可以实现上述任一实施例所提供的UART通信的波特率切换方法中发起方终端对应的步骤。
具体的,本实施例并不限定发起方终端的具体设备类型,如发起方终端可以具体为无线耳机或充电盒。
本申请实施例还提供了一种发起方终端,包括:存储器,用于存储计算机程序;处理器,用于执行计算机程序,实现实现获取发起方终端发送的波特率切换信息;将第二UART 接口的波特率切换至波特率切换信息中的目标波特率;切换完成后,向发起方终端发送波特率切换完成信息;通过第二UART接口接收被控方终端发送的待发送数据;其中,发起方终端的第一UART接口与被控方终端的第二UART接口连接。
也就是说,被控方终端的处理器执行存储器中存储的计算机程序时,可以实现上述任一实施例所提供的UART通信的波特率切换方法中被控方终端对应的步骤。
具体的,本实施例并不限定发起方终端的具体设备类型,如发起方终端可以具体为无线耳机或充电盒,例如发起方终端具体为无线耳机时,被控方终端可以具体为充电盒。
此外,本申请实施例还提供了一种计算机可读存储介质,其上存有计算机程序,该计算机程序被执行时可以实现上述实施例所提供的UART通信的波特率切换方法的步骤。该存储介质可以包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似部分互相参见即可。对于实施例公开的装置、系统、发起方终端、被控方终端及计算机可读存储介质而言,由于其与实施例公开的方法相对应,所以描述的比较简单,相关之处参见方法部分说明即可。
以上对本申请所提供的一种UART通信的波特率切换方法、装置、系统、发起方终端、被控方终端及计算机可读存储介质进行了详细介绍。本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想。应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以对本申请进行若干改进和修饰,这些改进和修饰也落入本申请权利要求的保护范围内。
Claims (10)
- 一种UART通信的波特率切换方法,其特征在于,包括:发起方终端获取目标波特率对应的待发送数据;向被控方终端发送波特率切换信息;其中,所述波特率切换信息包括所述目标波特率;将第一UART接口的波特率切换至所述目标波特率;其中,所述发起方终端的所述第一UART接口与所述被控方终端的第二UART接口连接;在获取所述被控方终端发送的波特率切换完成信息后,通过所述第一UART接口向所述被控方终端发送所述待发送数据。
- 根据权利要求1所述的UART通信的波特率切换方法,其特征在于,所述向被控方终端发送波特率切换信息,包括:通过所述第一UART接口,按预设波特率向所述被控方终端发送波特率切换信息。
- 根据权利要求2所述的UART通信的波特率切换方法,其特征在于,所述波特率切换信息还包括:协议版本号。
- 根据权利要求2所述的UART通信的波特率切换方法,其特征在于,所述将第一UART接口的波特率切换至所述目标波特率,包括:通过所述第一UART接口按所述预设波特率接收所述被控方终端发送的所述波特率切换信息对应的确认信息后,在第一预设时间后将第一UART接口的波特率由所述预设波特率切换至所述目标波特率。
- 根据权利要求1至4任一项所述的UART通信的波特率切换方法,其特征在于,所述将第一UART接口的波特率切换至所述目标波特率之后,还包括:通过所述第一UART接口,按所述目标波特率向所述被控方终端发送握手信息;判断第二预设时间段内是否通过所述第一UART接口接收到所述握手信息对应的确认信息;若是,则将所述握手信息对应的确认信息作为所述波特率切换完成信息,执行所述通过所述第一UART接口向所述被控方终端发送所述待发送数据的步骤。
- 根据权利要求5所述的UART通信的波特率切换方法,其特征在于,所述判断第二预设时间段内是否通过所述第一UART接口接收到所述握手信息对应的确认信息之后,还包括:在所述第二预设时间段内未接收到所述握手信息对应的确认信息时,判断是否达到发送次数阈值;若达到所述发送次数阈值,则将所述第一UART接口的波特率由所述目标波特率切换至所述预设波特率;若未达到所述发送次数阈值,则执行所述通过所述第一UART接口,按所述目标波特率向所述被控方终端发送握手信息的步骤。
- 一种UART通信的波特率切换装置,其特征在于,包括:数据获取模块,用于获取目标波特率对应的待发送数据;控制模块,用于向被控方终端发送波特率切换信息;其中,所述波特率切换信息包括所述目标波特率;切换模块,用于将第一UART接口的波特率切换至所述目标波特率;其中,发起方终端的所述第一UART接口与所述被控方终端的第二UART接口连接;发送模块,用于在获取所述被控方终端发送的波特率切换完成信息后,通过所述第一UART接口向所述被控方终端发送所述待发送数据。
- 一种发起方终端,其特征在于,包括:存储器,用于存储计算机程序;处理器,用于执行所述计算机程序,实现获取目标波特率对应的待发送数据;向被控方终端发送波特率切换信息;将第一UART接口的波特率切换至所述目标波特率;在获取所述被控方终端发送的波特率切换完成信息后,通过所述第一UART接口向所述被控方终端发送所述待发送数据;其中,所述波特率切换信息包括所述目标波特率,所述发起方终端的所述第一UART接口与所述被控方终端的第二UART接口连接。
- 一种被控方终端,其特征在于,包括:存储器,用于存储计算机程序;处理器,用于执行所述计算机程序,实现获取发起方终端发送的波特率切换信息;将第二UART接口的波特率切换至所述波特率切换信息中的目标波特率;切换完成后,向所述发起方终端发送波特率切换完成信息;通过所述第二UART接口接收所述被控方终端发送的待发送数据;其中,所述发起方终端的第一UART接口与所述被控方终端的所述第二UART接口连接。
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至6任一项所述的UART通信的波特率切换方法的步骤。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110118503.9 | 2021-01-28 | ||
CN202110118503.9A CN112968752B (zh) | 2021-01-28 | 2021-01-28 | 一种uart通信的波特率切换方法、装置及发起方终端 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022161004A1 true WO2022161004A1 (zh) | 2022-08-04 |
Family
ID=76271921
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2021/138768 WO2022161004A1 (zh) | 2021-01-28 | 2021-12-16 | 一种uart通信的波特率切换方法、装置及发起方终端 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN112968752B (zh) |
WO (1) | WO2022161004A1 (zh) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117254884A (zh) * | 2023-11-14 | 2023-12-19 | 深圳市顾美科技有限公司 | 通讯波特率调试方法、装置、设备及存储介质 |
CN117640016A (zh) * | 2024-01-26 | 2024-03-01 | 北京智芯微电子科技有限公司 | 波特率协商方法、装置、计算机设备、芯片及存储介质 |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112968752B (zh) * | 2021-01-28 | 2023-01-24 | 歌尔科技有限公司 | 一种uart通信的波特率切换方法、装置及发起方终端 |
CN113556210B (zh) * | 2021-07-16 | 2024-02-27 | 青岛信芯微电子科技股份有限公司 | 一种上位机和建立通信连接的方法 |
CN114189316A (zh) * | 2021-12-06 | 2022-03-15 | 经纬恒润(天津)研究开发有限公司 | 一种波特率和报文协议的自适应方法及装置 |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5901191A (en) * | 1995-01-18 | 1999-05-04 | Nec Corporation | Baud rate mixing transmission system |
US7116739B1 (en) * | 2002-10-31 | 2006-10-03 | Zilog, Inc. | Auto baud system and method and single pin communication interface |
CN101409716A (zh) * | 2008-11-25 | 2009-04-15 | 中国网络通信集团公司 | 无线通信模块与外部应用模块的通信速率匹配方法 |
CN111694785A (zh) * | 2020-05-20 | 2020-09-22 | 哈尔滨工业大学 | 反馈型的uart自适应波特率系统及自适应波特率方法 |
CN112217603A (zh) * | 2020-05-06 | 2021-01-12 | 青岛鼎信通讯股份有限公司 | 一种基于电表串口的波特率自适应设计 |
CN112968752A (zh) * | 2021-01-28 | 2021-06-15 | 歌尔科技有限公司 | 一种uart通信的波特率切换方法、装置及发起方终端 |
Family Cites Families (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7606575B2 (en) * | 1988-08-04 | 2009-10-20 | Broadcom Corporation | Remote radio data communication system with data rate switching |
US5923705A (en) * | 1996-07-18 | 1999-07-13 | Qualcomm Incorporated | UART based autobauding without data loss |
DK0918421T3 (da) * | 1997-11-13 | 2000-08-07 | Optimay Gmbh | Baudfrekvensdetektering ved seriel datatransmission |
JP3366277B2 (ja) * | 1999-03-25 | 2003-01-14 | 日本電気株式会社 | Atコマンド受信回路 |
TW200844760A (en) * | 2007-05-08 | 2008-11-16 | Mitac Int Corp | Data transmission rate adjustment system and method thereof |
CN103995480B (zh) * | 2014-06-10 | 2016-09-14 | 北京芯创睿胜科技有限公司 | 一种通过耳机插座交换数据的系统和方法 |
CN105653461B (zh) * | 2016-03-17 | 2018-08-03 | 烽火通信科技股份有限公司 | 一种单usb接口转多uart调试接口的转换系统 |
CN107547315B (zh) * | 2016-06-24 | 2020-09-08 | 九阳股份有限公司 | 一种优化数据通信的方法和装置 |
CN107241161B (zh) * | 2016-11-24 | 2019-12-31 | 天地融科技股份有限公司 | 一种数据传输方法及装置 |
CN107241162B (zh) * | 2016-11-24 | 2020-04-10 | 天地融科技股份有限公司 | 一种数据传输方法及装置 |
JP7251324B2 (ja) * | 2019-05-31 | 2023-04-04 | 株式会社富士通ゼネラル | 通信装置、ボーレート自動設定方法及び通信システム |
CN112230948B (zh) * | 2019-06-30 | 2022-01-07 | 比亚迪股份有限公司 | 整车can通信系统和软件升级方法、设备、系统及车辆 |
CN111163387B (zh) * | 2019-12-29 | 2021-08-24 | 歌尔科技有限公司 | 一种tws耳机升级方法、装置、充电盒及存储介质 |
CN111431668B (zh) * | 2020-04-22 | 2021-04-06 | 珠海格力电器股份有限公司 | 基于多节点uart通讯的波特率切换方法、空调系统及处理器 |
CN111786944A (zh) * | 2020-05-15 | 2020-10-16 | 广州亚美智造科技有限公司 | 车辆排放监测方法、装置、设备和存储介质 |
-
2021
- 2021-01-28 CN CN202110118503.9A patent/CN112968752B/zh active Active
- 2021-12-16 WO PCT/CN2021/138768 patent/WO2022161004A1/zh active Application Filing
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5901191A (en) * | 1995-01-18 | 1999-05-04 | Nec Corporation | Baud rate mixing transmission system |
US7116739B1 (en) * | 2002-10-31 | 2006-10-03 | Zilog, Inc. | Auto baud system and method and single pin communication interface |
CN101409716A (zh) * | 2008-11-25 | 2009-04-15 | 中国网络通信集团公司 | 无线通信模块与外部应用模块的通信速率匹配方法 |
CN112217603A (zh) * | 2020-05-06 | 2021-01-12 | 青岛鼎信通讯股份有限公司 | 一种基于电表串口的波特率自适应设计 |
CN111694785A (zh) * | 2020-05-20 | 2020-09-22 | 哈尔滨工业大学 | 反馈型的uart自适应波特率系统及自适应波特率方法 |
CN112968752A (zh) * | 2021-01-28 | 2021-06-15 | 歌尔科技有限公司 | 一种uart通信的波特率切换方法、装置及发起方终端 |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117254884A (zh) * | 2023-11-14 | 2023-12-19 | 深圳市顾美科技有限公司 | 通讯波特率调试方法、装置、设备及存储介质 |
CN117254884B (zh) * | 2023-11-14 | 2024-01-30 | 深圳市顾美科技有限公司 | 通讯波特率调试方法、装置、设备及存储介质 |
CN117640016A (zh) * | 2024-01-26 | 2024-03-01 | 北京智芯微电子科技有限公司 | 波特率协商方法、装置、计算机设备、芯片及存储介质 |
CN117640016B (zh) * | 2024-01-26 | 2024-05-17 | 北京智芯微电子科技有限公司 | 波特率协商方法、装置、计算机设备、芯片及存储介质 |
Also Published As
Publication number | Publication date |
---|---|
CN112968752B (zh) | 2023-01-24 |
CN112968752A (zh) | 2021-06-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2022161004A1 (zh) | 一种uart通信的波特率切换方法、装置及发起方终端 | |
US20210219041A1 (en) | Voice data transmission method, wireless earphone and tws earphone | |
CN108600892B (zh) | 一种升级方法、装置、无线耳机、tws耳机及充电盒 | |
WO2019192586A1 (zh) | 数据传输方法、装置、存储介质及电子设备 | |
US20200245386A1 (en) | Wireless connection method and device | |
US10389153B2 (en) | Charging control method and mobile terminal | |
US9712266B2 (en) | Synchronization of multi-channel audio communicated over bluetooth low energy | |
WO2016179817A1 (zh) | 快速充电方法、电源适配器和移动终端 | |
WO2019134306A1 (zh) | 消息处理方法、装置、终端设备及可读存储介质 | |
WO2017049548A1 (zh) | 移动终端、电源适配器及其升级方法 | |
WO2017049553A1 (zh) | 移动终端、电源适配器及其升级方法 | |
US11800337B2 (en) | Method and apparatus for establishing Bluetooth data channel | |
US20210235183A1 (en) | Method and system for upgrading program of tws headset, and tws headset | |
CN109768596B (zh) | 一种电量显示方法、耳机充电装置及耳机 | |
CN103338144B (zh) | 一种会话数据同步方法和装置 | |
US20150350855A1 (en) | Data Sending Method and Apparatus | |
WO2017049549A1 (zh) | 移动终端、电源适配器及其升级方法 | |
EP3923608A1 (en) | Data transmission method between tws bluetooth devices and tws bluetooth device therefor | |
CN111277988B (zh) | 一种提高微信小程序蓝牙传输速度的方法 | |
CN112437371B (zh) | Ble链路的切换方法、设备、耳机对、芯片及介质 | |
CN113038317A (zh) | 耳机控制方法、装置、蓝牙耳机及存储介质 | |
KR20200110086A (ko) | 무선 통신 링크의 설정 방법 및 이를 지원하는 전자 장치 | |
CN110764806B (zh) | 一种tws耳机及其升级方法及装置 | |
EP3720178A1 (en) | Method and apparatus for remapping qos flow, and computer storage medium | |
WO2022267269A1 (zh) | 通话处理方法、装置、系统、电子设备及介质 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 21922594 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 21922594 Country of ref document: EP Kind code of ref document: A1 |