Self-adaptive baud rate method and self-adaptive baud rate device based on single chip microcomputer

By connecting the serial port receive pin and the interrupt pin of the microcontroller, and using a timer to count and identify the minimum level duration, the problem of high cost of dedicated peripherals and poor compatibility with non-standard baud rates in low-cost embedded communication is solved, and the universality and stability of the adaptive baud rate function are realized.

CN121644002APending Publication Date: 2026-03-10HUARUAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-18
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

In low-cost embedded communication applications, dedicated peripherals are expensive, have poor compatibility with non-standard baud rates, and are difficult to implement in resource-constrained MCUs.

Method used

By connecting the serial port receive pin of the microcontroller to an input/output pin that can generate rising or falling edge interrupts, a timer is used to count when the edge changes, identify the minimum level duration width, and calculate the baud rate of serial communication based on the width, thus configuring the microcontroller's serial port communication parameters to achieve adaptive baud rate.

Benefits of technology

Without relying on dedicated hardware, it achieves adaptive identification and configuration of arbitrary baud rates, reduces system costs, improves compatibility with non-standard baud rates, and is suitable for resource-constrained microcontrollers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121644002A_ABST
    Figure CN121644002A_ABST
Patent Text Reader

Abstract

The invention discloses a self-adaptive baud rate method and a self-adaptive baud rate device based on a single chip microcomputer, which are not limited by a data sending mode, a data structure and a standard baud rate or not by judging in a mode that a minimum level width corresponds to a 1-bit time length, can be compatible with various standard and non-standard baud rates, and can be used for realizing the self-adaptive baud rate method and the self-adaptive baud rate device based on the single chip microcomputer. The defect that in the prior art, the non-standard communication rate supporting performance is poor is overcome. Meanwhile, the technology can complete measurement by depending on naturally existing edge flipping, a sending end is not required to use a specific synchronization character, and additional communication overhead does not need to be increased, so that the method has relatively high universality and adaptability. Therefore, according to the scheme, the limitation in the background technology can be overcome comprehensively in the aspects of cost, compatibility, applicable platform and the like, and the self-adaptive baud rate function which is low in cost, wide in compatibility and capable of being deployed on various single-chip microcomputer platforms is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of reverse engineering, in particular to a single-chip microcomputer-based adaptive baud rate method and adaptive baud rate device. BACKGROUND

[0002] Serial asynchronous communication (UART) is one of the most commonly used data communication methods in embedded systems, and is widely used in industrial control, sensor acquisition, consumer electronics and Internet of Things devices and many other fields. UART communication has the characteristics of simple structure, low cost, small protocol overhead, etc., but both parties of communication must work at the same baud rate, otherwise the data cannot be correctly parsed. Therefore, it is of great significance to realize automatic recognition and matching of communication baud rate in the communication initialization link for improving system compatibility, reducing manual configuration and reducing product cost.

[0003] In the prior art, adaptive baud rate is generally realized through a special peripheral chip or an automatic frequency measurement circuit integrated in a high-end microcontroller. Although this type of scheme can automatically identify the communication baud rate, it relies on specific hardware resources, resulting in high system cost, which is not suitable for low-cost MCU products sensitive to cost. At the same time, the existing adaptive scheme is mainly designed for fixed or standard baud rates, and has poor compatibility for non-standard custom baud rates. In addition, some implementation schemes require complex hardware structures or occupy multiple on-chip peripheral resources, which is not conducive to deployment in small controllers with limited hardware resources, limiting its universality in low-cost scenarios.

[0004] Therefore, in low-cost embedded communication applications, the high cost of special peripherals, poor compatibility with non-standard baud rates, and difficulty in implementing adaptive baud rate functions in resource-limited MCUs have become problems that need to be solved. SUMMARY

[0005] The present application provides a single-chip microcomputer-based adaptive baud rate method and adaptive baud rate device, aiming to solve the problems of high cost of special peripherals, poor compatibility with non-standard baud rates, and difficulty in implementing adaptive baud rate functions in resource-limited MCUs in low-cost embedded communication applications.

[0006] In a first aspect, a single-chip microcomputer-based adaptive baud rate method is provided, which includes the following steps:

[0007] Step 1: Connect the serial port receive pin UART_RX of the single-chip microcomputer to the same serial communication line as the input / output pin capable of generating a rising edge or falling edge interrupt, and receive the serial port signal of the external sending end through the serial communication line;

[0008] Step 2: reading a current count value of a timer connected to the input / output pin when one of rising edges or falling edges of the serial port signal is detected, storing the current count value as a level maintenance time width sample, and resetting the timer to restart timing;

[0009] Step 3: determining a minimum level maintenance time width from the stored multiple level maintenance time width samples after receiving multiple rising edges and / or falling edges and repeating the step 2;

[0010] Step 4: taking the minimum level maintenance time width as a level time length corresponding to 1 bit in the serial port signal, and calculating a baud rate of current serial communication according to the level time length corresponding to the 1 bit;

[0011] Step 5: configuring serial communication parameters in the single-chip microcomputer according to the baud rate of the current serial communication, so that the serial port of the single-chip microcomputer performs data communication according to the baud rate of the current serial communication.

[0012] In the above scheme, optionally, the input / output pin capable of generating rising edge or falling edge interruption is:

[0013] a PCA gate level pin connected to a pulse width capture / comparison module;

[0014] a timer gate level pin connected to a timer capture / gating unit;

[0015] any general input / output pin with interruption function.

[0016] In the above scheme, optionally, the rising edge or falling edge corresponding serial port timing includes:

[0017] During sending of a byte at a sending end, a rising edge generated when a least significant bit is 1, a level flip edge generated when a most significant bit is 0 and a stop bit is entered after termination, and continuous level flip edges generated when “010” or “101” appears in a data bit sequence, are all used to obtain corresponding level maintenance time width samples, starting from a start bit.

[0018] In the above scheme, optionally, before determining the minimum level maintenance time width, the method further includes:

[0019] performing validity judgment on each level maintenance time width sample, eliminating abnormal samples greater than or smaller than a preset threshold, and selecting a minimum level maintenance time width from remaining samples as the level time length corresponding to the 1 bit.

[0020] In the above scheme, optionally, the data transmitted in the serial port signal includes:

[0021] The method selects the minimum level maintaining time width as the level time length corresponding to the 1 bit in the level maintaining time width sample obtained by timing the level flip edge corresponding to the data byte.

[0022] In a second aspect, an adaptive baud rate device is provided, and the device comprises:

[0023] a single-chip microcomputer;

[0024] a serial port module arranged in the single-chip microcomputer, configured to perform serial asynchronous communication with an external serial communication device;

[0025] a timer module arranged in the single-chip microcomputer;

[0026] an input / output pin connected to the UART_RX pin of the serial port module, configured to generate an interrupt and trigger the count reading of the timer module when detecting a rising edge or a falling edge of a serial port signal;

[0027] The single-chip microcomputer is configured to perform the method according to the first aspect, collect and process the count value of the timer module, and configure the baud rate parameter of the serial port module.

[0028] In the above scheme, the count clock frequency of the timer module is greater than several times of the target serial communication baud rate, and the interrupt response time of the input / output pin is less than the preset level maintaining time width resolution, and correspondingly, the level maintaining time width sample meeting the accuracy requirement is obtained.

[0029] In a third aspect, a serial communication system is provided, comprising an adaptive baud rate device and an external serial port device connected to the adaptive baud rate device through serial asynchronous communication;

[0030] The adaptive baud rate device is the adaptive baud rate device according to the second aspect; the transmitting pin of the external serial port device is connected to the UART_RX pin and the input / output pin of the adaptive baud rate device on the serial communication line, and the adaptive baud rate device realizes the identification of the communication baud rate of the external serial port device and the configuration of the serial port parameter by detecting the edge of the serial port signal on the serial communication line and counting the timer.

[0031] In a fourth aspect, a computer readable storage medium having stored thereon a computer program, the computer program being executed by a processor to implement the single-chip microcomputer-based adaptive baud rate method according to the first aspect.

[0032] In a fifth aspect, a single-chip microcomputer chip includes: a serial communication module and a timer module, and at least one input / output pin capable of generating a rising edge or falling edge interrupt;

[0033] The single-chip microcomputer chip has a computer program pre-stored therein, and the computer program is executed by a processing unit of the single-chip microcomputer chip to control the serial communication module, the timer module, and the input / output pin to execute the method according to the first aspect.

[0034] Compared with the prior art, the present application has at least the following beneficial effects:

[0035] Based on further analysis and research on the problems of the prior art, it is realized that in low-cost embedded communication applications, the cost of special peripherals is high, the compatibility with non-standard baud rates is poor, and it is difficult to implement adaptive baud rate functions in resource-limited MCUs. By triggering timer counting reading at the edge change of the serial input signal and using the minimum level holding time width as the 1bit time length, the external serial communication baud rate is directly measured and automatically identified, so that the single-chip microcomputer can complete the self-adaptation configuration of the communication rate without relying on special automatic baud rate detection hardware. Since this method only relies on the constant timer and interrupt resources, it can run stably in low-cost, resource-limited controllers, effectively avoiding the problem of rising system cost caused by the use of high-end controllers or special peripheral chips in the prior art. By judging in the way of minimum level width corresponding to 1bit time length, it is not limited by the transmission data mode, data structure, and whether it is a standard baud rate, and can be compatible with various standard and non-standard baud rates, solving the problem of poor support for non-standard communication rates in the prior art. At the same time, this technology can complete the measurement by relying on the naturally existing edge flip, without requiring the use of specific synchronization characters on the sending end, and without increasing additional communication overhead, so that the method has strong universality and adaptability. Therefore, this scheme can overcome the limitations in the background art in terms of cost, compatibility, and applicable platform, and realize a low-cost, widely compatible, and deployable adaptive baud rate function on various single-chip microcomputer platforms. BRIEF DESCRIPTION OF DRAWINGS

[0036] Figure 1 A flowchart of a single-chip microcomputer-based adaptive baud rate method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and should not be used to limit the present application.

[0038] In the description of the present application: unless otherwise specified, the meaning of "a plurality of" is two or more. The terms "first", "second", "third" and the like in the present application are intended to distinguish the objects referred to, and do not have a special meaning in the technical connotation aspect (for example, it should not be understood as emphasizing importance or order, etc.). The expressions "include", "contain", "have" and the like also mean "not limited to" (some units, components, materials, steps, etc.).

[0039] In one embodiment, as shown in Figure 1 A single-chip microcomputer-based adaptive baud rate method is provided, comprising the following steps:

[0040] Step 1: Connect the serial port receiving pin UART_RX of the single-chip microcomputer to the same serial communication line with the input / output pin capable of generating rising edge or falling edge interrupt, and receive the serial port signal of the external sending end through the serial communication line;

[0041] Step 2: When one of the rising edge or falling edge of the serial port signal is detected, read the current count value of the timer connected to the input / output pin, store the current count value as a level maintenance time width sample, and reset the timer to restart timing;

[0042] Step 3: After receiving a plurality of the rising edge and / or falling edge and repeating the step 2, determine the minimum level maintenance time width from the plurality of stored level maintenance time width samples;

[0043] Step 4: Take the minimum level maintenance time width as the level time length corresponding to 1 bit in the serial port signal, and calculate the baud rate of the current serial communication according to the level time length corresponding to the 1 bit;

[0044] Step 5: According to the baud rate of the current serial communication, configure the serial communication parameters in the single-chip microcomputer, so that the serial port of the single-chip microcomputer communicates data at the baud rate of the current serial communication.

[0045] In the present embodiment, the input / output pin capable of generating rising edge or falling edge interrupt is:

[0046] PCA gate level pin connected to pulse width capture / comparison module;

[0047] Timer gate level pin connected to timer capture / gating unit;

[0048] Any general input / output pin with interrupt function.

[0049] In the embodiment, the rising edge or falling edge corresponding serial port timing includes:

[0050] During the transmission of a byte at the sending end, the rising edge generated when the least significant bit is 1, the level transition edge generated when the most significant bit is 0 and the stop bit is entered, and the continuous level transition edge generated when “010” or “101” appears in the data bit sequence, all from the start bit, are used to obtain the corresponding level maintenance time width sample.

[0051] In the embodiment, before determining the minimum level maintenance time width, the method further includes:

[0052] The level maintenance time width samples are judged for validity, abnormal samples greater than or less than a preset threshold are removed, and the minimum level maintenance time width is selected from the remaining samples as the level time length corresponding to the 1 bit.

[0053] In the embodiment, the data transmitted in the serial port signal includes:

[0054] At least one data byte with the least significant bit being 1 and / or at least one data byte with the most significant bit being 0 and / or a data byte containing the bit sequence “010” or “101”, the method selects the minimum level maintenance time width from the level maintenance time width samples obtained by timing the level transition edge corresponding to the data byte as the level time length corresponding to the 1 bit.

[0055] In the embodiment, the serial port receiving pin UART_RX of the single-chip microcomputer is physically connected to the same serial communication line as an input / output pin capable of generating a rising edge or falling edge interrupt (for example, a PCA capture pin, a timer gate pin or a general interrupt IO). The serial communication line is also connected to the TX pin of the external serial port sending end, so that the UART_RX and the interrupt pin can both receive the serial port level signal output by the external sending end. By arranging the two types of pins on the same line, the timer counting and the edge change of the serial port data can be completely synchronized, thereby improving the accuracy of the baud rate identification.

[0056] When the single-chip microcomputer receives an external serial port signal, the interrupt pin first responds to the rising edge or falling edge of the input signal. When a one-time edge triggering event is detected, the interrupt service program immediately reads the current count value of the timer associated with the pin, and records the count value as the current level maintenance time width sample. The timer counter is then cleared, so that it starts timing again. Since the serial port data frame has a start bit, data bit, check bit (if present), and stop bit structure, and the level change between different bits will form a series of edges, the timer count value can reflect the length of time corresponding to the level duration.

[0057] During the process of continuously sending at least one data byte at the serial port sending end, the interrupt pin will constantly trigger the timer reading operation every time a level flip (including rising edge or falling edge) occurs, thereby collecting multiple level maintenance time width samples. In actual applications, since the start bit of the UART data frame is always low, and the stop bit is always high, and the bit values of different data bits will cause level flips in different directions, multiple level duration intervals of different lengths can be naturally formed. The present embodiment records all level maintenance time widths to form a sample set.

[0058] After the sample set reaches a preset number or the external serial port data transmission is complete, the single-chip microcomputer software selects the smallest count value from the recorded multiple level maintenance time width samples as the actual time width corresponding to 1 bit of level. The reason is that each bit of serial communication has a fixed duration, and since the data bit sequence may contain consecutive same levels (for example, "0000" and "11111"), these segments will cause the level maintenance time to be 2 bits, 3 bits, or more. Therefore, by finding the smallest continuous level duration width, the shortest unit time, i.e., the duration corresponding to 1 bit, can be identified, thereby realizing the reverse calculation of the actual baud rate of the sending end.

[0059] After obtaining the minimum level width, the single-chip microcomputer calculates the actual time corresponding to the width based on the clock frequency of the timer, and calculates the true baud rate of the external serial port device. Subsequently, the baud rate register of the internal serial port module of the single-chip microcomputer is configured by software, and the communication rate of the serial port module is set to the calculated baud rate, so that the single-chip microcomputer can perform subsequent data analysis and interaction at the same communication rate as the external device, realizing the automatic baud rate adaptation function.

[0060] The above embodiment measures the level maintenance time width of the serial port input signal in real time under the edge interrupt trigger, and reverses the baud rate of the sending end based on the minimum level width, so that the single-chip microcomputer can realize self-adaptive identification of any serial port baud rate without relying on a dedicated automatic baud rate detection peripheral. The technical scheme has the following significant technical effects:

[0061] By directly measuring the level duration using a timer timing method, the scheme does not rely on a special hardware baud rate frequency measurement module, and can realize the adaptive baud rate function on a general low-cost single-chip microcomputer, thereby avoiding the problem of rising system cost caused by using a high-end controller or a special peripheral chip. Since only the timer and the interrupt function are used to realize the baud rate recognition, the occupation of hardware resources is extremely low, and it is particularly suitable for deployment in a microcontroller with limited resources, thereby solving the problem that the adaptive baud rate is difficult to realize on a low-cost platform due to the limitation of special hardware in the prior art.

[0062] The scheme can recognize standard baud rate, non-standard baud rate, and user-defined baud rate, and other communication rates by directly timing the edge change of the serial port signal, and does not rely on any internal clock calibration mode or fixed baud rate ratio matching logic. Therefore, the problem of poor compatibility with non-standard baud rate that exists in the prior art can be avoided, and more types of serial port devices can be adapted in a mixed device communication scene, thereby improving the communication adaptability and expansibility of the system.

[0063] The scheme can effectively resist the influence of factors such as jitter, noise, interference, and differences in transmission data structure on baud rate judgment by determining the 1-bit width by taking the minimum value of multiple level maintenance time samples. Since there is a bit structure that triggers the shortest level flip (such as the start bit + data bit, the “010” or “101” combination in the data, etc.) in the UART data frame, the minimum level duration has natural stability, so that the baud rate recognition process has high reliability, thereby solving the limitation of the traditional recognition method based on a specific frame structure that relies on special data or a specific synchronization byte.

[0064] In addition, the scheme continuously collects multiple level width samples during detection, so that the baud rate recognition does not need to rely on a specific initial synchronization character, and even if the external device transmits any byte data, it can also extract effective samples from the natural bit sequence, thereby making the scheme have high universality, and solving the problem that the adaptive baud rate method in the prior art relies heavily on a predetermined synchronization byte.

[0065] The embodiment recognizes the serial port baud rate based on the edge-triggered timer measurement method, not only reduces the hardware cost and improves the compatibility with different baud rate formats, but also can realize stable and reliable automatic baud rate recognition function in a low-cost single-chip microcomputer with limited resources, thereby effectively solving the problems of high cost of special peripherals, difficulty in compatibility with non-standard baud rate, and difficulty in implementation in a small controller in the background technology.

[0066] In one embodiment, an adaptive baud rate device is provided, and the device comprises:

[0067] Single-chip microcomputer;

[0068] A serial port module arranged in the single-chip microcomputer is used for serial asynchronous communication with an external serial communication device;

[0069] A timer module arranged in the single-chip microcomputer;

[0070] An input / output pin connected in network with a UART_RX pin of the serial port module, the input / output pin being used for generating an interrupt and triggering a count reading of the timer module when a rising edge or a falling edge of a serial port signal is detected;

[0071] The single-chip microcomputer is configured to perform the single-chip microcomputer-based adaptive baud rate method, collect and process a count value of the timer module, and configure a baud rate parameter of the serial port module.

[0072] In the embodiment, a count clock frequency of the timer module is greater than several times of a target serial communication baud rate, and an interrupt response time of the input / output pin is less than a preset level maintaining time width resolution, which is correspondingly used for obtaining a level maintaining time width sample satisfying an accuracy requirement.

[0073] In one embodiment, a level time can be calculated by using the single-chip microcomputer to collect a rising-falling interval of a measured serial port signal, a minimum value of all collected level times is searched, and a corresponding time length of 1 bit is taken as a 1-bit corresponding time length, so as to inversely deduce a corresponding baud rate.

[0074] After a start bit is sent by a sender, a falling edge is captured and a last level width is saved, if an LSB is equal to 1, a rising edge is generated and a level width is saved, during which, a bus level generates a rising-falling edge interrupt according to data, until an MSB is sent by the sender, if the MSB is 0, a stop bit is sent in a next baud rate period and an interrupt is triggered once, after the stop bit is sent, a start bit of a next byte generates a falling edge interrupt fixedly, and an interrupt level width is fixed as a baud rate period.

[0075] If an LSB is equal to 1 or an MSB is equal to 0, a shortest 1-bit time width is generated;

[0076] If a data contains a “010” or “101” bit segment, a shortest 1-bit time width is generated;

[0077] According to the above, if a lowest bit is 1 or a highest bit is 0, or a data contains a 010101 bit segment, a 1-bit time level width is generated, and a corresponding baud rate can be calculated linearly, in an actual use process, a shortest 1-bit time width can be obtained when data meets the above several points.

[0078] Hardware connection: Connect the UARTRX pin of the controller and a certain PCA gate or timer gate IO to the same network and connect to the TX sending pin to be communicated. If there is no extra PCA or timer gate IO, it can be connected to any interruptable IO (the interrupt performance of the connected peripheral will affect the upper limit of the adaptive baud rate).

[0079] 1. Internal PCA gate / timer gate / interrupt IO / control a certain timer gate (timer resolution affects accuracy);

[0080] 2. When the IO state is at the rising or falling edge, take the value of the previous timer and save it;

[0081] 3. Make the timer restart counting;

[0082] 4. Repeat steps 2 to 4 several times, and after the number of samples collected is sufficient, proceed to step 5;

[0083] 5. Find the minimum value in the sample, which is the 1-bit low-level time width;

[0084] 6. According to the low-level time width, the corresponding baud rate can be linearly calculated;

[0085] 7. Modify the serial communication baud rate parameter to the corresponding baud rate to complete the adaptive baud rate function.

[0086] Compared with the prior art, the embodiment has the following advantages:

[0087] No need for special peripheral chips, saving cost, and can use lower-cost control to achieve the function;

[0088] When using non-standard baud rate, the scheme can be linearly compatible;

[0089] The embodiment uses the rising and falling edge interrupts of the serial input signal to trigger the timer to count, measure the level width, and inversely calculate the communication baud rate according to the 1-bit level width corresponding to the minimum value.

[0090] In one embodiment, taking the transmission of 0x01 and 0x02 two bytes as an example, assuming the baud rate is 9600bps, then a bit width is 1 / 9600 seconds for convenience. 1 / 9600 seconds is 1 tick.

[0091]

[0092] The shortest time to obtain the level is 1, that is, 1 / 9600 seconds; that is, the current baud rate is 9600bps.

[0093] In one embodiment, a serial communication system is provided, comprising an adaptive baud rate device, and an external serial port device connected with the adaptive baud rate device through a serial asynchronous communication connection;

[0094] The adaptive baud rate device is connected with the external serial port device through a serial asynchronous communication connection, and the adaptive baud rate device is connected with the external serial port device through a serial asynchronous communication connection.

[0095] In one embodiment, a computer readable storage medium is provided, which stores a computer program, and the computer program is executed by a processor to implement the adaptive baud rate method based on a single-chip microcomputer.

[0096] In one embodiment, a single-chip microcomputer chip is provided, comprising a serial communication module and a timer module, and at least one input / output pin capable of generating rising edge or falling edge interrupt;

[0097] The single-chip microcomputer chip is internally preset with a computer program, and the computer program is executed by a processing unit of the single-chip microcomputer chip to control the serial communication module, the timer module and the input / output pin to execute the adaptive baud rate method based on a single-chip microcomputer.

[0098] The technical features of the above embodiments can be combined in any manner. To make the description concise, not all possible combinations of the technical features in the above embodiments are described, however, as long as the combinations of the technical features do not exist contradictions, they should be considered as the scope of the present disclosure.

Claims

1. A method for adaptive baud rate based on a single chip microcomputer, characterized by, The method comprises: Step 1: connecting the serial port receiving pin UART_RX of the single-chip microcomputer to the same serial communication line as the input / output pin capable of generating rising edge or falling edge interrupt, and receiving the serial port signal of the external sending end through the serial communication line; Step 2: when one of the rising edge or falling edge of the serial port signal is detected, reading the current count value of the timer connected to the input / output pin, storing the current count value as a level maintenance time width sample, and resetting the timer to restart timing; Step 3: after receiving multiple rising edges and / or falling edges and repeating step 2, determining the minimum level maintenance time width from the stored multiple level maintenance time width samples; Step 4: taking the minimum level maintenance time width as the level time length corresponding to 1 bit in the serial port signal, and calculating the baud rate of the current serial communication according to the level time length corresponding to 1 bit; Step 5: configuring the serial communication parameters in the single-chip microcomputer according to the baud rate of the current serial communication, so that the serial port of the single-chip microcomputer communicates data at the baud rate of the current serial communication.

2. The method of claim 1, wherein, The input / output pin capable of generating rising edge or falling edge interrupt is: a PCA gate level pin connected to a pulse width capture / comparison module; a timer gate level pin connected to a timer capture / gated unit; any general-purpose input / output pin with interrupt function.

3. The method of claim 1, wherein, The rising edge or falling edge corresponding serial port timing comprises: during the sending of a byte by the sending end, the rising edge generated when the least significant bit is 1, the level flip edge generated when the most significant bit is 0 and then enters the stop bit, and the continuous level flip edge generated when "010" or "101" appears in the data bit sequence, all of which are used to obtain the corresponding level maintenance time width sample.

4. The method of claim 1, wherein, Before determining the minimum level maintenance time width, it further comprises: validity judgment is performed on each level maintenance time width sample, abnormal samples greater than or less than a preset threshold are removed, and the minimum level maintenance time width is selected from the remaining samples as the level time length corresponding to 1 bit.

5. The method of claim 1, wherein, The data transmitted in the serial port signal comprises: at least one data byte with the least significant bit being 1 and / or at least one data byte with the most significant bit being 0 and / or a data byte containing the bit sequence "010" or "101", and the minimum level maintenance time width is selected as the level time length corresponding to 1 bit from the level maintenance time width samples obtained by timing the level flip edge corresponding to the data byte.

6. An adaptive baud rate device, comprising: The device comprises: a single-chip microcomputer; a serial port module arranged in the single-chip microcomputer, used for serial asynchronous communication with an external serial communication device; a timer module arranged in the single-chip microcomputer; an input / output pin connected in network with a UART_RX pin of the serial port module, the input / output pin being used to generate an interrupt and trigger a count reading of the timer module when a rising edge or a falling edge of a serial port signal is detected; wherein the single-chip microcomputer is configured to execute the method according to any one of claims 1 to 5, collect and process a count value of the timer module, and configure a baud rate parameter of the serial port module.

7. The adaptive baud rate device of claim 6, wherein, The count clock frequency of the timer module is greater than several times of a target serial communication baud rate, and the interrupt response time of the input / output pin is less than a preset level maintaining time width resolution, which is correspondingly used to obtain a level maintaining time width sample satisfying an accuracy requirement.

8. A serial communication system, characterized by The adaptive baud rate device is connected with an external serial port device through serial asynchronous communication. The adaptive baud rate device is the adaptive baud rate device according to claim 6 or 7; a transmitting pin of the external serial port device is connected to a UART_RX pin of the adaptive baud rate device and a serial communication line where the input / output pin is located; and the adaptive baud rate device realizes identification of a communication baud rate of the external serial port device and configuration of serial port parameters by performing edge detection and timer counting on a serial port signal on the serial communication line. 9.A computer readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the single-chip microcomputer-based adaptive baud rate method according to any one of claims 1 to 5.

10. A single-chip microcomputer, characterized by comprising: The adaptive baud rate device comprises: a serial port communication module and a timer module, and at least one input / output pin capable of generating a rising edge or a falling edge interrupt; wherein the single-chip microcomputer chip is internally preset with a computer program, the computer program being executed by a processing unit of the single-chip microcomputer chip to control the serial port communication module, the timer module and the input / output pin to execute the method according to any one of claims 1 to 5.