Baud rate adjusting method and device, electronic equipment and storage medium
By dynamically adjusting the baud rate in the UART interface, calculating the target baud rate according to the ambient temperature changes and adjusting it, the communication failure problem caused by baud rate error at high or low temperatures is solved, and the stability and reliability of the communication are achieved.
Patent Information
- Application Number
- CN202411772057.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2044-12-04
AI Technical Summary
In high or low temperature environments, the baud rate of the UART interface exceeds a certain range due to the frequency change of the RC oscillator, resulting in communication reception or transmission failure.
By obtaining the current ambient temperature of the device and the ambient temperature at the previous moment, when the temperature difference is greater than the preset temperature, the sampling times of the current baud rate coarse adjustment value, the current clock frequency and the communication rate are determined, the target baud rate is calculated, and the current baud rate is adjusted to the target baud rate.
When the temperature changes, dynamically adjusting the baud rate can avoid communication failure caused by baud rate errors, ensuring the stability and reliability of the communication.
Smart Images

Figure CN119788241A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a baud rate adjustment method, a baud rate adjustment device, an electronic device and a computer-readable storage medium. Background Art
[0002] With the development of smart homes, air conditioning equipment has become an indispensable household appliance in people's lives. When the indoor and outdoor units of air conditioning equipment communicate, they are generally based on the UART (Universal Asynchronous Receiver / Transmitter) interface. The internal chip of the air conditioning equipment generally uses a crystal oscillator or a ceramic oscillator as a clock source. At present, the crystal oscillator inside the chip is mostly an RC (Resistor-Capacitor) oscillator. However, since the ambient temperature has a great influence on the RC oscillator, when the clock corresponding to the UART interface uses an RC oscillator, it may cause the error between the UART baud rate and the actual requirement to exceed a certain range when working at high or low temperatures, which may cause the communication reception or transmission to fail. Summary of the invention
[0003] In view of the above problems, embodiments of the present invention are proposed to provide a baud rate adjustment method, a baud rate adjustment device, an electronic device and a computer-readable storage medium that overcome the above problems or at least partially solve the above problems.
[0004] In order to solve the above problem, an embodiment of the present invention discloses a baud rate adjustment method, the method comprising:
[0005] Get the current ambient temperature and the ambient temperature of the device at the last moment;
[0006] When the temperature difference between the current ambient temperature and the ambient temperature at the previous moment is greater than a preset temperature, determining a current baud rate coarse adjustment value, a current clock frequency, and a sampling number for a communication rate of the device;
[0007] Determining a target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times;
[0008] A current baud rate is determined, and the current baud rate is adjusted to a target baud rate.
[0009] Optionally, determining a current baud rate coarse adjustment value, a current clock frequency, and a number of sampling times for a communication rate of the device includes:
[0010] Obtaining the current clock frequency, the number of samples of the communication rate of the device, the clock frequency at the last moment, and the baud rate at the last moment;
[0011] Determining a baud rate coarse adjustment value at a previous moment according to the number of sampling times, the clock frequency at a previous moment, and the baud rate at a previous moment;
[0012] The current baud rate coarse adjustment value is determined according to the baud rate coarse adjustment value at the previous moment.
[0013] Optionally, determining the current baud rate coarse adjustment value according to the baud rate coarse adjustment value at the previous moment includes:
[0014] A current baud rate coarse adjustment value is determined according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times and the baud rate at the last moment.
[0015] Optionally, determining the current baud rate and adjusting the current baud rate to the target baud rate includes:
[0016] Determine the current baud rate according to the baud rate coarse adjustment value at the previous moment, the current clock frequency and the number of sampling times;
[0017] The current baud rate is adjusted to a target baud rate.
[0018] Optionally, determining the baud rate coarse adjustment value at the last moment according to the number of sampling times, the clock frequency at the last moment, and the baud rate at the last moment includes:
[0019] The baud rate coarse adjustment value at the previous moment is calculated according to the following formula:
[0020] Br1=UC1 / (STV*BC1)
[0021] Among them, the Br1 is the baud rate at the previous moment; the UC1 is the clock frequency at the previous moment; the STV is the sampling number; and the BC1 is the coarse adjustment value of the baud rate at the previous moment.
[0022] Optionally, determining the current baud rate according to the baud rate coarse adjustment value at the previous moment, the current clock frequency, and the number of sampling times includes:
[0023] The current baud rate is calculated according to the following formula:
[0024] Br2=UC2 / (STV*BC1)
[0025] Among them, Br2 is the current baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC1 is the baud rate coarse adjustment value at the previous moment.
[0026] Optionally, determining the current baud rate coarse adjustment value according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times and the baud rate at the last moment includes:
[0027] The current baud rate coarse adjustment value is calculated according to the following formula:
[0028] BC2=UC1(1+N*Temp-M) / (STV*Br1)
[0029] Among them, BC2 is the current baud rate coarse adjustment value; UC1 is the clock frequency at the previous moment; Temp is the current ambient temperature; STV is the number of sampling times; Br1 is the baud rate at the previous moment; N is the first preset parameter; and M is the second preset parameter.
[0030] Optionally, determining the target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times includes:
[0031] The target baud rate is calculated according to the following formula:
[0032] Br2=UC2 / (STV*BC2)
[0033] Among them, Br2 is the target baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC2 is the current baud rate coarse adjustment value.
[0034] The embodiment of the present invention further discloses a baud rate adjustment device, the device comprising:
[0035] The acquisition module is used to obtain the current ambient temperature of the device and the ambient temperature of the previous moment;
[0036] A first determination module, configured to determine a current baud rate coarse adjustment value, a current clock frequency, and a number of sampling times for a communication rate of the device when a temperature difference between the current ambient temperature and the ambient temperature at the previous moment is greater than a preset temperature;
[0037] A second determination module is used to determine a target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times;
[0038] The adjustment module is used to determine the current baud rate and adjust the current baud rate to the target baud rate.
[0039] Optionally, the first determining module includes:
[0040] An acquisition submodule, used to acquire the current clock frequency, the number of sampling times for the communication rate of the device, the clock frequency at the last moment, and the baud rate at the last moment;
[0041] A first determination submodule, used to determine a baud rate coarse adjustment value at a previous moment according to the number of sampling times, the clock frequency at a previous moment, and the baud rate at a previous moment;
[0042] The second determination submodule is used to determine the current baud rate coarse adjustment value according to the baud rate coarse adjustment value at the previous moment.
[0043] Optionally, the second determining submodule includes:
[0044] The determination unit is used to determine the current baud rate coarse adjustment value according to the clock frequency at the previous moment, the current ambient temperature, the number of sampling times and the baud rate at the previous moment.
[0045] Optionally, the adjustment module includes:
[0046] A third determination submodule, configured to determine a current baud rate according to the baud rate coarse adjustment value at the previous moment, the current clock frequency and the number of sampling times;
[0047] The adjustment submodule is used to adjust the current baud rate to the target baud rate.
[0048] Optionally, the first determining submodule includes:
[0049] The first calculation unit is used to calculate the baud rate coarse adjustment value at the previous moment according to the following formula:
[0050] Br1=UC1 / (STV*BC1)
[0051] Among them, the Br1 is the baud rate at the previous moment; the UC1 is the clock frequency at the previous moment; the STV is the sampling number; and the BC1 is the coarse adjustment value of the baud rate at the previous moment.
[0052] Optionally, the third determining submodule includes:
[0053] The second calculation unit is used to calculate the current baud rate according to the following formula:
[0054] Br2=UC2 / (STV*BC1)
[0055] Among them, Br2 is the current baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC1 is the baud rate coarse adjustment value at the previous moment.
[0056] Optionally, the determining unit includes:
[0057] The calculation subunit is used to calculate the current baud rate coarse adjustment value according to the following formula:
[0058] BC2=UC1(1+N*Temp-M) / (STV*Br1)
[0059] Among them, BC2 is the current baud rate coarse adjustment value; UC1 is the clock frequency at the previous moment; Temp is the current ambient temperature; STV is the number of sampling times; Br1 is the baud rate at the previous moment; N is the first preset parameter; and M is the second preset parameter.
[0060] Optionally, the second determining module includes:
[0061] The third calculation unit is used to calculate the target baud rate according to the following formula:
[0062] Br2=UC2 / (STV*BC2)
[0063] Among them, Br2 is the target baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC2 is the current baud rate coarse adjustment value.
[0064] The present invention also discloses an electronic device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the baud rate adjustment method as described above when executing the computer program.
[0065] The present invention also discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the baud rate adjustment method as described above are implemented.
[0066] The embodiments of the present invention include the following advantages:
[0067] In an embodiment of the present invention, the current ambient temperature of the device and the ambient temperature of the previous moment are first obtained. When the difference between the current ambient temperature and the ambient temperature of the previous moment is greater than the preset temperature, the current baud rate needs to be adjusted. At this time, the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times for the communication rate of the device can be determined. Then, according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times, the target baud rate is determined. Finally, the current baud rate is determined and adjusted to the target baud rate. Therefore, when the current temperature environment changes, the target baud rate can be determined in time through the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times, and the current baud rate can be adjusted, thereby avoiding the phenomenon that the communication reception or transmission fails due to the error between the current baud rate and the actual requirement exceeding a certain range. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1is a flow chart of steps of a baud rate adjustment method provided by an embodiment of the present invention;
[0069] Figure 2 is a flowchart of another baud rate adjustment method provided by an embodiment of the present invention;
[0070] Figure 3 It is a structural block diagram of a baud rate adjustment device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0071] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0072] In the related art, since the ambient temperature has a great influence on the oscillator, the error between the baud rate of the UART and the actual requirement may exceed a certain range when working at high or low temperatures, thereby causing the phenomenon of failure in communication reception or transmission. In order to solve the above technical problems, the present invention provides a baud rate adjustment method, firstly obtains the current ambient temperature of the device and the ambient temperature of the previous moment, when the difference between the current ambient temperature and the ambient temperature of the previous moment is greater than the preset temperature, it is necessary to adjust the current baud rate, at this time, the current baud rate coarse adjustment value, the current clock frequency and the number of samplings for the communication rate of the device can be determined, and then the target baud rate is determined according to the current baud rate coarse adjustment value, the current clock frequency and the number of samplings, and finally the current baud rate is determined, and the current baud rate is adjusted to the target baud rate, so that when the current temperature environment changes, the target baud rate can be determined in time by the current baud rate coarse adjustment value, the current clock frequency and the number of samplings, and the current baud rate is adjusted, so as to avoid the phenomenon of failure in communication reception or transmission caused by the error between the current baud rate and the actual requirement exceeding a certain range.
[0073] The effect of ambient temperature on the baud rate is mainly reflected in the frequency stability of the oscillator. The frequency of the oscillator may change with changes in temperature, which may affect the system's clock frequency and, in turn, the baud rate. Effect of Temperature on Baud Rate Clock Frequency Change: Temperature changes can cause the oscillator frequency to change, which in turn affects the system's clock frequency. Since the baud rate is calculated based on the clock frequency, changes in the clock frequency will cause changes in the baud rate. Communication Error: Changes in the baud rate can lead to increased communication errors, especially in asynchronous communications, where the sending and receiving devices must use the same baud rate to communicate correctly. System Stability: Temperature changes can affect the stability of the system, especially in applications with large temperature changes such as industrial environments or automotive electronics.
[0074] Reference Figure 1, shows a flow chart of a baud rate adjustment method provided by an embodiment of the present invention, the method may specifically include the following steps:
[0075] Step 101, obtaining the current ambient temperature of the device and the ambient temperature at the previous moment.
[0076] In an embodiment of the present invention, the device may be a device that uses a UART interface for communication, and the clock corresponding to the UART interface uses an oscillator, such as an air conditioner. When the device is operating, the current ambient temperature of the device and the ambient temperature at the last moment may be obtained in real time. In the present invention, the ambient temperature at the last moment may be the ambient temperature corresponding to the last baud rate adjustment.
[0077] In the present invention, a temperature sensor and an analog-to-digital converter can be installed on the device. When the device is running, the chip in the device can read the temperature on the temperature sensor in real time through the analog-to-digital converter, and then obtain the current ambient temperature of the device and the ambient temperature at the previous moment according to the corresponding conversion.
[0078] In the present invention, UART is a widely used serial communication interface. It is used for full-duplex communication between two devices, and is usually used for short-distance communication, such as communication between a computer and peripheral devices (such as modems, printers, microcontrollers, etc.). UART has the following main features: Asynchronous communication: UART communication does not require a clock signal to synchronize data transmission. Instead, it relies on the start bit and stop bit contained in the data frame to synchronize the receiving device. Full-duplex: UART can send and receive data at the same time. Point-to-point communication: Usually used for direct communication between two devices, rather than a multi-device network. Simple hardware interface: Usually only two wires (transmit line and receive line) are required, as well as an optional ground line. The data transmission rate in UART communication is called the baud rate. The sending and receiving devices must use the same baud rate to communicate correctly.
[0079] In the present invention, baud rate refers to the number of symbols transmitted per second, which is usually used in serial communication. Baud rate is an important parameter for measuring data transmission rate, which determines how many symbols can be transmitted per second. In UART communication, baud rate is particularly important because it determines the speed and accuracy of data transmission. Baud rate has the following characteristics: Data transmission rate: The baud rate determines how many symbols can be transmitted per second. Symbols can be bits, characters, or other data units. Synchronicity: In asynchronous communication, the sending and receiving devices must use the same baud rate to communicate correctly. Error rate: The choice of baud rate will affect the error rate of communication. Higher baud rates may increase the error rate, especially in noisy environments. The following factors need to be considered when selecting a suitable baud rate: Communication distance: Longer communication distances may require lower baud rates to reduce the impact of signal attenuation and noise. Data volume: Larger data volumes may require higher baud rates to increase transmission speed. Noise environment: In noisy environments, lower baud rates can reduce bit error rates. Device compatibility: Ensure that the sending and receiving devices support the same baud rate.
[0080] Step 102: When the temperature difference between the current ambient temperature and the ambient temperature at the previous moment is greater than a preset temperature, determine the current baud rate coarse adjustment value, the current clock frequency, and the number of sampling times for the communication rate of the device.
[0081] In an embodiment of the present invention, after obtaining the current ambient temperature of the device and the ambient temperature of the previous moment, it can be determined whether the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is greater than the preset temperature. For example, the preset temperature is 10°C. When the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is greater than 10°C, it proves that the baud rate needs to be adjusted. At this time, the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times for the communication rate of the device can be determined.
[0082] In the present invention, the baud rate coarse adjustment value refers to a parameter value for roughly adjusting the baud rate in serial communication in order to adapt to different communication requirements or compensate for changes in the system clock frequency.
[0083] In the present invention, clock frequency refers to the frequency of a periodic signal generated by an oscillator, usually in Hertz (Hz). An oscillator is an electronic device used to generate a stable periodic signal as a clock source for an electronic system. The clock frequency determines the operating speed, data transmission rate, and timing accuracy of the system. The clock frequency of the oscillator needs to have high stability to ensure that the system can work properly under different environmental conditions (such as temperature changes, power supply fluctuations, etc.). The accuracy of the clock frequency determines the timing accuracy of the system and the accuracy of data transmission. High-precision clock frequency is particularly important for applications that require precise timing (such as communication systems and data acquisition systems). The clock frequency of the oscillator ranges widely, ranging from a few hertz to hundreds of megahertz, depending on the application requirements. The power consumption of the oscillator directly affects the overall power consumption of the system. Low-power oscillators are suitable for battery-powered devices.
[0084] In the present invention, UART is a serial communication protocol, and the conventional data format is 1-bit start bit + 8-bit data bit + 1-bit check bit (or no check bit) + 1-bit stop bit. The communicating parties can communicate at the agreed baud rate (without external clock signal), and the chip samples at 16 times the communication rate during receiving and processing, that is, each bit of data is sampled 16 times.
[0085] In one embodiment, the current baud rate coarse adjustment value, the current clock frequency, and the number of samplings for the communication rate of the device are determined, including: obtaining the current clock frequency, the number of samplings for the communication rate of the device, the clock frequency at the last moment, and the baud rate at the last moment; determining the baud rate coarse adjustment value at the last moment based on the number of samplings, the clock frequency at the last moment, and the baud rate at the last moment; determining the current baud rate coarse adjustment value based on the baud rate coarse adjustment value at the last moment.
[0086] Specifically, the current clock frequency and the number of samplings for the communication rate of the device in the present invention can be directly obtained. The baud rate coarse adjustment value at the previous moment needs to first obtain the sampling number, the clock frequency at the previous moment and the baud rate at the previous moment, and then determine the baud rate coarse adjustment value at the previous moment based on the sampling number, the clock frequency at the previous moment and the baud rate at the previous moment, and finally determine the current baud rate coarse adjustment value based on the coarse adjustment value at the previous moment.
[0087] In one embodiment, determining the baud rate coarse adjustment value at the last moment according to the number of sampling times, the clock frequency at the last moment, and the baud rate at the last moment includes:
[0088] The baud rate coarse adjustment value at the previous moment is calculated according to the following formula (1):
[0089] Br1=UC1 / (STV*BC1) Formula (1)
[0090] Among them, Br1 is the baud rate at the previous moment; UC1 is the clock frequency at the previous moment; STV is the number of sampling times; BC1 is the coarse adjustment value of the baud rate at the previous moment.
[0091] In one embodiment, determining the current baud rate coarse adjustment value according to the baud rate coarse adjustment value at the last moment may include: determining the current baud rate coarse adjustment value according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times and the baud rate at the last moment.
[0092] In the present invention, after the baud rate coarse adjustment value at the last moment is determined, the current baud rate coarse adjustment value can be determined according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times and the baud rate at the last moment.
[0093] In one embodiment, the current baud rate coarse adjustment value is determined according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times, and the baud rate at the last moment, including:
[0094] The current baud rate coarse adjustment value is calculated according to the following formula (2):
[0095] BC2=UC1(1+N*Temp-M) / (STV*Br1) Formula (2)
[0096] Among them, BC2 is the current baud rate coarse adjustment value; UC1 is the clock frequency at the previous moment; Temp is the current ambient temperature; STV is the number of sampling times; Br1 is the baud rate at the previous moment; N is the first preset parameter; and M is the second preset parameter.
[0097] In the present invention, the first preset parameter N and the second preset parameter M can be determined by checking the frequency of the oscillator of the sample chip under a certain temperature range, and statistically obtaining the trend line and the linear equation, and then determining the error value between the ambient temperature and the actual temperature, thereby determining the specific values of the first preset parameter N and the second preset parameter M. In the present invention, the specific value of the first preset parameter N can be 0.0002, and the specific value of the second preset parameter M can be 0.0055.
[0098] Step 103, determining a target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times.
[0099] In the embodiment of the present invention, after the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times are determined, the target baud rate can be determined according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times.
[0100] In one embodiment, determining the target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times includes:
[0101] The target baud rate is calculated according to the following formula (3):
[0102] Br2=UC2 / (STV*BC2) Formula (3)
[0103] Among them, Br2 is the target baud rate; UC2 is the current clock frequency; STV is the number of sampling times; BC2 is the current baud rate coarse adjustment value.
[0104] Step 104, determining the current baud rate, and adjusting the current baud rate to the target baud rate.
[0105] In the embodiment of the present invention, after the target baud rate is determined, the current baud rate may be determined, and the current baud rate may be adjusted to the target baud rate.
[0106] In one embodiment, determining the current baud rate and adjusting the current baud rate to the target baud rate may include: determining the current baud rate according to the baud rate coarse adjustment value at the last moment, the current clock frequency and the number of sampling times; and adjusting the current baud rate to the target baud rate.
[0107] In the present invention, the current baud rate can be calculated based on the baud rate coarse adjustment value at the last moment, the current clock frequency and the number of sampling times. After the current baud rate is calculated, the current baud rate can be adjusted according to the target baud rate.
[0108] In one embodiment, the current baud rate is determined according to the baud rate coarse adjustment value at the last moment, the current clock frequency, and the number of sampling times, including:
[0109] The current baud rate is calculated according to the following formula (4):
[0110] Br2=UC2 / (STV*BC1) Formula (4)
[0111] Among them, Br2 is the current baud rate; UC2 is the current clock frequency; STV is the number of sampling times; BC1 is the coarse adjustment value of the baud rate at the previous moment.
[0112] In order to better understand the embodiments of the present invention, a specific example is first used for illustration. For example: the ambient temperature at the last moment is 25°C, the clock frequency at the last moment is 8MHz, the baud rate at the last moment is 1200bps, and the number of sampling times is 16 times. Then, according to the above formula (1), the baud rate coarse adjustment value BC1 at the last moment can be calculated to be 416.66, which is approximately equal to 416. When the ambient temperature rises to 85°C, the current clock frequency increases by 0.8% compared with the clock frequency at the last moment, that is, the current ambient temperature is 85°C and the current clock frequency is 8.064MHz. At this time, according to formula (4), the current baud rate Br2=8064000 / (16*416)≈1211 can be calculated. When adjusting the current baud rate, the current baud rate coarse adjustment value can be calculated according to formula (2), wherein the first preset parameter N is 0.0002, and the second preset parameter M is 0.0055, that is, BC2=8000000(1+0.0002*85-0.0055)(16*1200)≈421, and then according to formula (3), the target baud rate can be calculated, that is, Br2=8064000 / (16*421)≈1197. Finally, the current baud rate is adjusted to the target baud rate 1197, thereby completing the adjustment of the baud rate.
[0113] Reference Figure 2 , showing a flow chart of steps of another baud rate adjustment method provided by an embodiment of the present invention. The current ambient temperature of the device and the ambient temperature of the previous moment are obtained, and it is determined whether the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is greater than the preset temperature. When the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is not greater than the preset temperature, the current ambient temperature and the ambient temperature of the previous moment of the device are continued to be obtained. When the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is greater than the preset temperature, the current baud rate coarse adjustment value is determined according to a preset formula, and the preset formula is formula (2) in the above embodiment. Then, according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times, the target baud rate is determined, and finally, corresponding adjustments are made according to the target baud rate.
[0114] In an embodiment of the present invention, the current ambient temperature of the device and the ambient temperature of the previous moment are obtained; when the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is greater than the preset temperature, the current baud rate coarse adjustment value, the current clock frequency and the number of samplings for the communication rate of the device are determined; according to the current baud rate coarse adjustment value, the current clock frequency and the number of samplings, the target baud rate is determined; the current baud rate is determined and adjusted to the target baud rate. Thus, when the current temperature environment changes, the target baud rate can be determined in time through the current baud rate coarse adjustment value, the current clock frequency and the number of samplings, and the current baud rate can be adjusted, thereby avoiding the phenomenon that the communication reception or transmission fails due to the error between the current baud rate and the actual requirement exceeding a certain range.
[0115] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0116] Reference Figure 3 , shows a structural block diagram of a baud rate adjustment device provided by an embodiment of the present invention, which may specifically include the following modules:
[0117] The acquisition module 301 is used to acquire the current ambient temperature and the ambient temperature of the device at the previous moment;
[0118] A first determination module 302 is used to determine a current baud rate coarse adjustment value, a current clock frequency, and a sampling number of a communication rate of the device when the temperature difference between the current ambient temperature and the ambient temperature at the previous moment is greater than a preset temperature;
[0119] A second determination module 303 is used to determine a target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times;
[0120] The adjustment module 304 is used to determine the current baud rate and adjust the current baud rate to the target baud rate.
[0121] In one embodiment, the first determining module 302 includes:
[0122] An acquisition submodule, used to acquire the current clock frequency, the number of sampling times for the communication rate of the device, the clock frequency at the last moment, and the baud rate at the last moment;
[0123] A first determination submodule, used to determine a baud rate coarse adjustment value at a previous moment according to the number of sampling times, the clock frequency at a previous moment, and the baud rate at a previous moment;
[0124] The second determination submodule is used to determine the current baud rate coarse adjustment value according to the baud rate coarse adjustment value at the previous moment.
[0125] In one embodiment, the second determining submodule includes:
[0126] The determination unit is used to determine the current baud rate coarse adjustment value according to the clock frequency at the previous moment, the current ambient temperature, the number of sampling times and the baud rate at the previous moment.
[0127] In one embodiment, the adjustment module 304 includes:
[0128] A third determination submodule, configured to determine a current baud rate according to the baud rate coarse adjustment value at the previous moment, the current clock frequency and the number of sampling times;
[0129] The adjustment submodule is used to adjust the current baud rate to the target baud rate.
[0130] In one embodiment, the first determining submodule includes:
[0131] The first calculation unit is used to calculate the baud rate coarse adjustment value at the previous moment according to the following formula:
[0132] Br1=UC1 / (STV*BC1)
[0133] Among them, the Br1 is the baud rate at the previous moment; the UC1 is the clock frequency at the previous moment; the STV is the sampling number; and the BC1 is the coarse adjustment value of the baud rate at the previous moment.
[0134] In one embodiment, the third determining submodule includes:
[0135] The second calculation unit is used to calculate the current baud rate according to the following formula:
[0136] Br2=UC2 / (STV*BC1)
[0137] Among them, Br2 is the current baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC1 is the baud rate coarse adjustment value at the previous moment.
[0138] In one embodiment, the determining unit includes:
[0139] The calculation subunit is used to calculate the current baud rate coarse adjustment value according to the following formula:
[0140] BC2=UC1(1+N*Temp-M) / (STV*Br1)
[0141] Among them, BC2 is the current baud rate coarse adjustment value; UC1 is the clock frequency at the previous moment; Temp is the current ambient temperature; STV is the number of sampling times; Br1 is the baud rate at the previous moment; N is the first preset parameter; and M is the second preset parameter.
[0142] In one embodiment, the second determining module 303 includes:
[0143] The third calculation unit is used to calculate the target baud rate according to the following formula:
[0144] Br2=UC2 / (STV*BC2)
[0145] Among them, Br2 is the target baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC2 is the current baud rate coarse adjustment value.
[0146] In an embodiment of the present invention, an acquisition module is used to acquire the current ambient temperature of the device and the ambient temperature of the previous moment; a first determination module is used to determine the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times for the communication rate of the device when the temperature difference between the current ambient temperature and the ambient temperature of the previous moment is greater than a preset temperature; a second determination module is used to determine the target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times; an adjustment module is used to determine the current baud rate and adjust the current baud rate to the target baud rate. Thus, when the current temperature environment changes, the target baud rate can be determined in time through the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times, and the current baud rate can be adjusted, thereby avoiding the phenomenon that the communication reception or transmission fails due to the error between the current baud rate and the actual requirement exceeding a certain range.
[0147] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0148] An embodiment of the present invention further provides an electronic device, including:
[0149] It includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned baud rate adjustment method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0150] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned baud rate adjustment method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0151] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0152] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0153] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0154] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0155] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0156] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0157] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0158] The baud rate adjustment method, the baud rate adjustment device, the electronic device and the computer-readable storage medium provided by the present invention are introduced in detail above. The principle and implementation mode of the present invention are explained by using specific examples in this article. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation mode and the scope of application. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A baud rate adjustment method, characterized in that: The method comprises: Get the current ambient temperature and the ambient temperature of the device at the last moment; When the temperature difference between the current ambient temperature and the ambient temperature at the previous moment is greater than a preset temperature, determining a current baud rate coarse adjustment value, a current clock frequency, and a sampling number for a communication rate of the device; Determining a target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times; A current baud rate is determined, and the current baud rate is adjusted to a target baud rate.
2. The baud rate adjustment method according to claim 1, characterized in that: The determining of the current baud rate coarse adjustment value, the current clock frequency, and the number of sampling times for the communication rate of the device includes: Obtaining the current clock frequency, the number of samples of the communication rate of the device, the clock frequency at the last moment, and the baud rate at the last moment; Determining a baud rate coarse adjustment value at a previous moment according to the number of sampling times, the clock frequency at a previous moment, and the baud rate at a previous moment; The current baud rate coarse adjustment value is determined according to the baud rate coarse adjustment value at the previous moment.
3. The baud rate adjustment method according to claim 2, characterized in that: Determining the current baud rate coarse adjustment value according to the baud rate coarse adjustment value at the previous moment includes: A current baud rate coarse adjustment value is determined according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times and the baud rate at the last moment.
4. The baud rate adjustment method according to claim 1, characterized in that: The determining of the current baud rate and adjusting the current baud rate to the target baud rate includes: Determine the current baud rate according to the baud rate coarse adjustment value at the previous moment, the current clock frequency and the number of sampling times; The current baud rate is adjusted to a target baud rate.
5. The baud rate adjustment method according to claim 2, characterized in that: Determining the baud rate coarse adjustment value at the last moment according to the number of sampling times, the clock frequency at the last moment, and the baud rate at the last moment includes: The baud rate coarse adjustment value at the previous moment is calculated according to the following formula: Br1=UC1 / (STV*BC1) Among them, the Br1 is the baud rate at the previous moment; the UC1 is the clock frequency at the previous moment; the STV is the sampling number; and the BC1 is the coarse adjustment value of the baud rate at the previous moment.
6. The baud rate adjustment method according to claim 4, characterized in that: The determining the current baud rate according to the baud rate coarse adjustment value at the previous moment, the current clock frequency and the number of sampling times includes: The current baud rate is calculated according to the following formula: Br2=UC2 / (STV*BC1) Among them, Br2 is the current baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC1 is the baud rate coarse adjustment value at the previous moment.
7. The baud rate adjustment method according to claim 3, characterized in that: Determining the current baud rate coarse adjustment value according to the clock frequency at the last moment, the current ambient temperature, the number of sampling times and the baud rate at the last moment includes: The current baud rate coarse adjustment value is calculated according to the following formula: BC2=UC1(1+N*Temp-M) / (STV*Br1) Among them, BC2 is the current baud rate coarse adjustment value; UC1 is the clock frequency at the previous moment; Temp is the current ambient temperature; STV is the number of sampling times; Br1 is the baud rate at the previous moment; N is the first preset parameter; and M is the second preset parameter.
8. The baud rate adjustment method according to claim 4, characterized in that: The step of determining the target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times includes: The target baud rate is calculated according to the following formula: Br2=UC2 / (STV*BC2) Among them, Br2 is the target baud rate; UC2 is the current clock frequency; STV is the sampling number; and BC2 is the current baud rate coarse adjustment value.
9. A baud rate adjustment device, characterized in that: The device comprises: The acquisition module is used to obtain the current ambient temperature of the device and the ambient temperature of the previous moment; A first determination module, configured to determine a current baud rate coarse adjustment value, a current clock frequency, and a number of sampling times for a communication rate of the device when a temperature difference between the current ambient temperature and the ambient temperature at the previous moment is greater than a preset temperature; A second determination module is used to determine a target baud rate according to the current baud rate coarse adjustment value, the current clock frequency and the number of sampling times; The adjustment module is used to determine the current baud rate and adjust the current baud rate to the target baud rate.
10. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the baud rate adjustment method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the baud rate adjustment method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Synchronous data transmission method and device on basis of Baud rate of communication connectors
CN103970697A
Method and device for adjusting baud rate of serial port communication and electronic equipment
CN116541323A
Self-adapting baud rate
US20170288899A1
Cited By
Baud rate calibration method and circuit, storage medium and electronic equipment
CN120090765A