A universal serial port communication baud rate adaptive method
By using the universal serial communication baud rate adaptive method in inter-chip serial communication, the baud rate is automatically judged and adjusted, and the data transmission error caused by baud rate deviation between different chips is solved, and the accuracy and stability of inter-chip serial communication is achieved.
Patent Information
- Application Number
- CN202510208630.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-25
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2045-02-25
AI Technical Summary
When serial port communication between different chips, frequency deviation caused by different working environments leads to deviations between the actual baud rate and the expected baud rate, resulting in sampling errors and data transmission errors. The existing baud rate adaptive technology cannot be effectively adjusted in some scenarios, resulting in failure of serial communication.
The universal serial communication baud rate adaptive method is used to determine the center point and boundary point corresponding to the length of each sequence through the serial communication initialization parameters, as well as the overlapping interval, and set the number of times threshold. According to the acquisition of real-time communication data, the baud rate difference between the two ends of the communication is automatically judged, and the baud rate configuration is dynamically adaptively adjusted to ensure that the baud rate magnitudes of both ends are consistent.
It realizes that the baud rate can be automatically judged and adjusted without sending synchronous characters from the main control chip, ensuring the correctness and stability of serial communication between chips, and is suitable for situations where there are baud rate deviations on both ends of chips.
Smart Images

Figure CN119690898B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of integrated circuits, relates to inter-chip communication technology, and specifically relates to a universal serial port communication baud rate adaptive method. Background Art
[0002] When serial communication is performed between different chips, the difference in the working environment of the chips may cause frequency deviation in the system, resulting in a deviation between the actual baud rate and the expected baud rate. In this way, when serial communication is performed between different chips, sampling errors may occur due to the baud rate deviation, resulting in data transmission errors.
[0003] Baud rate indicates the number of code symbols transmitted per unit time, that is, the number of times the carrier modulation state changes per unit time. Baud rate measures the transmission rate of symbols, not the actual number of data bits transmitted. For example, a baud rate of 9600 means that 9600 code symbols can be transmitted per second.
[0004] The existing baud rate adaptive technical solution is that before serial communication, the receiving end adjusts the baud rate by comparing the received characters with the preset synchronization characters. However, in actual chip docking communication, in many scenarios, the docking chip cannot control the main control chip to set the preset synchronization characters to send synchronization characters or command leading characters, and the baud rate adjustment cannot be achieved. This scenario will cause serial communication data transmission errors. In addition, the chips at both ends of the communication will cause frequency deviation due to the working environment, which will cause a certain offset in the baud rate of the chips at both ends. In this scenario, the benchmark of the method of presetting synchronization characters itself is inaccurate, which will cause inaccurate baud rate adjustment or failure of adjustment. Summary of the invention
[0005] In view of the defects of the above-mentioned prior art, the present invention discloses a universal serial port communication baud rate adaptive method.
[0006] The universal serial port communication baud rate self-adaptation method of the present invention comprises the following steps:
[0007] Step 1. Determine the initialization parameters of the serial port communication, determine the center point and boundary point corresponding to each sequence length, as well as the overlapping interval, and set the number threshold;
[0008] The overlapping interval is an interval where the boundary points of adjacent sequence lengths overlap;
[0009] Step 2. Transmit data and perform sampling counting;
[0010] Step 3. Determine whether the sampling count result falls within the bit sequence interval, if not, return to step 2, if yes, proceed to step 4;
[0011] Step 4. Determine the baud rate offset based on the sampling count result, specifically:
[0012] Step 41. If the sampling count result does not fall into the overlapping interval, the corresponding sequence length can be inferred according to the sampling count result;
[0013] Step 42. According to the sequence length and the sampling count result, determine whether there is a baud rate deviation. If there is, proceed to step 5; if not, proceed to step 6;
[0014] If the counting result falls at the center point, it means that there is no baud rate deviation in this monitoring;
[0015] If the sampling result falls to the left of the center point, that is, it is smaller than the center point, it means that the baud rate is negatively biased. If the counting result falls to the right of the center point, that is, it is larger than the center point, it means that the baud rate is positively biased.
[0016] Step 5. Determine whether the baud rate deviation is continuous and has the same trend; if so, correct the baud rate, otherwise return to step 2;
[0017] Step 6. End the baud rate detection.
[0018] Preferably, in step 1:
[0019] The center point C=N*L, the boundary point SIDE=INT [C*(1± W / 2)], where N is the oversampling rate, L is the sequence length, W is the deviation range, and INT means rounding.
[0020] Preferably, the step 5 is specifically:
[0021] Step 51. Determine whether the baud rate deviation trend is the same as the previous one, if yes, go to step 52, otherwise return to step 2;
[0022] Step 52: Determine whether the number of baud rate deviations reaches the number threshold set in step 1. If yes, make a judgment and correct the baud rate. Otherwise, return to step 2 to continue detection.
[0023] The universal serial port communication baud rate adaptive method of the present invention has the following technical advantages over the prior art:
[0024] 1. The present invention no longer uses the main control chip to send synchronization characters and preset characters, but automatically determines the baud rate difference between the two ends of the communication based on the collection of real-time communication data, identifies whether the baud rate of the chip end is too large or too small, and dynamically and adaptively adjusts the baud rate configuration to achieve the same baud rate at both ends, ensuring the correctness of serial communication data transmission between chips.
[0025] 2. The present invention can perform baud rate tracking in real time when there is a baud rate deviation between the chips at both ends, so as to achieve the effect of consistent communication baud rate.
[0026] 3. The present invention does not depend on whether the chip is the main control chip in the application, and can directly judge the deviation of the baud rate configuration of the local end in real time according to the received sampling data, and perform baud rate correction in real time to ensure the correctness of data communication transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 A schematic diagram of a specific embodiment of the sequence of the present invention;
[0028] Figure 2 A schematic diagram of a specific implementation of the central points and boundary points corresponding to sequences of different lengths and overlapping intervals in the present invention;
[0029] Figure 3 A schematic flow chart of a specific implementation of the method of the present invention;
[0030] Figure 4 The figure is a schematic diagram of an actual baud rate change when the baud rate is adjusted by the method of the present invention. DETAILED DESCRIPTION
[0031] In order to more intuitively and clearly describe the specific details of the technical solution of the present invention, a detailed description will be given below in conjunction with specific embodiments and example drawings.
[0032] In the universal serial communication baud rate adaptation method described in the present invention, the described serial communication baud rate adaptation is based on sampling a section of received signal with jumps, and the actual baud rate deviation can be obtained by comparing the sampling result with the baud rate configuration. According to the detected deviation size, the baud rate configuration is updated and adjusted in real time until the baud rates at both ends of the communication are close to the same.
[0033] The baud rate deviation is calculated by oversampling, such as Figure 2 The diagram shows the principle of calculating the baud rate deviation by oversampling. Figure 2 As shown, assuming that the oversampling rate is set to N, when there is no deviation in the baud rate, the number of sampling points for 1-bit data is N, the number of sampling points for 2-bit data is 2N, and so on.
[0034] When the baud rate is biased, the number of sampling points corresponding to the sequence length will deviate from the number of center points. Figure 3As shown in the triangular area of each sequence length, the left side of the triangular area indicates that the distance from the center point is small, and the number of sampling points is less than the number of center points, which is a negative deviation. The right side of the triangular area indicates that the number of sampling points is greater than the number of center points, which is a positive deviation. When the sequence length is short, the number of sampling points and the sequence length are unique, and there will be no overlapping intervals in short sequences. The more sequence bits there are, the larger the cumulative floating range of the number of sampling points will be, and an intersection area will appear.
[0035] A sequence refers to one or more consecutive data bits that remain in the same level during data transmission; for example Figure 1 In the sequence, the start bit, the first bit, and the second bit are all zero, which is a three-bit sequence. The third bit and the fourth bit are all 1, which is a two-bit sequence. The seventh bit is 1, which is a one-bit sequence.
[0036] Obviously, the levels of different continuously distributed sequences are distributed at intervals, namely 0 and 1. A sequence with a level of 1 is preceded and followed by a sequence with a level of 0, and vice versa. Therefore, when sampling, the adjacent rising and falling edges can be counted.
[0037] For short sequences, the sampling error caused by the baud rate error cannot cause overlap in the sampling process. However, when the sequence length is long, overlapping sampling may occur. For example, assuming that the oversampling rate N is set to 32 and the baud rate has a 15% deviation, for a short sequence of 1 bit length, the number of sampling points may be distributed between 29-35, and for a short sequence of two bits length, the number of sampling points may be distributed between 58-70. Obviously, there is no intersection between these two number distributions.
[0038] For a 6-bit long sequence, the number of sampling points may be distributed between 174 and 210, and for a 7-bit short sequence, the number of sampling points may be distributed between 203 and 245. Obviously, these two number distributions already have an intersection of 203 and 210. As the sequence length increases and the baud rate error increases, the area of intersection will continue to increase. The larger the baud rate error, the shorter the sequence length required for the intersection to occur.
[0039] When the sequence length is long, the number of sampling points and the sequence length are not unique. When the number of sampling points falls into the overlapping interval, a short sequence is needed to assist in determining the positive and negative bias directions to determine the center point position that needs to be aligned. When estimating the deviation based on the oversampling method, because the points sampled on the transition edge may be judged in the front or in the back, considering the uncertainty introduced by the two sampling points at the boundary transition of the metastable state, which leads to the basic estimation error, on the one hand, the influence ratio can be reduced by increasing the oversampling rate, and on the other hand, it can be estimated by splicing longer continuous sequences to offset the influence of the uncertainty of the edge judgment, so as to increase the accuracy of the detection baud rate.
[0040] like Figure 1 As shown, the baud rate detection can be obtained from Figure 1 Starting from the transition edge of the waveform, a sequence is formed between two adjacent transition edges. Multiple sequences can be detected to determine the baud rate fluctuation to increase the accuracy and robustness of the baud rate adaptive adjustment.
[0041] The method of the present invention is implemented according to the following steps:
[0042] Step 1. Determine the initialization parameters of the serial communication, specifically determine the serial communication baud rate, oversampling rate parameters and the initialization configuration of the serial communication; determine the center point and boundary point corresponding to each sequence length, as well as the overlapping interval, and set the number threshold;
[0043] According to the oversampling rate and deviation range, the center point and boundary points corresponding to the sampling of different sequence lengths are set, where the center point C=N*L, the boundary point SIDE=INT [C*(1± W / 2)], where N is the oversampling rate, L is the sequence length, W is the deviation range, and INT means rounding; the area between the two boundary points constitutes the sequence interval of the sequence.
[0044] For example, if the oversampling rate is 32 and the deviation range is 15%, the center points of the sequences with lengths of 1, 2, and 3 are 32, 64, and 96 respectively; the boundary points are (29, 35), (58, 70), and (87, 105) respectively.
[0045] The overlapping interval is when the sequence length increases, the adjacent sequence length boundaries overlap. For example, for a 6-bit long sequence, the number of sampling points may be distributed between 174 and 210, and for a 7-bit short sequence, the number of sampling points may be distributed between 203 and 245. Obviously, these two number distributions have an overlapping interval [203, 210].
[0046] like Figure 2 As shown, the horizontal axis is the number of sampling points. Figure 2 For the convenience of display, an isosceles triangle is used to show the center point and boundary points corresponding to different sequence lengths, where the central vertex of the isosceles triangle is the center point, which is N, 2N, 3N... respectively; N represents the oversampling rate, and the other two vertices of the isosceles triangle represent the boundary points of the sequence length. When the sequence length is short, the bottoms of adjacent isosceles triangles will not overlap. As the sequence length increases, the bottoms of adjacent isosceles triangles begin to overlap, and the horizontal axis coverage area corresponding to the overlapping area is the overlapping interval.
[0047] At the same time, determine the oversampling rate division coefficient osbd = (F uart_clk / {osr*bdr}),
[0048] Baud rate division factor bdd = (F uart_clk / {bdsr*bdr}),
[0049] Configure the oversampling rate and baud rate division coefficients, where osbd is the oversampling rate division coefficient, F uart_clk It is the working clock of the serial communication module, bdr is the baud rate, osr is the oversampling rate, bdsr is the baud rate sampling rate, and bdd is the baud rate division coefficient; the baud rate can be adjusted later by adjusting the oversampling rate division coefficient and the baud rate division coefficient.
[0050] Step 2. Transmit data and perform sampling counting;
[0051] After completing the initialization parameters of the serial communication in step 1, enable the baud rate adaptive function. After the baud rate adaptive function is turned on, the serial communication starts to monitor the receiving sequence data on the receiving end RX side in real time. When the data jumps, the receiving sequence is sampled and counted according to the set sampling rate. When the data jumps again, it means that one sequence has been sampled and the next sequence has started.
[0052] like Figure 1 As shown, when the start bit is not considered, the first sequence is two consecutive 0s. Since the level is the same as the start bit 0, the data does not jump and the first sequence does not need to be sampled. The second sequence is two consecutive 1s. The level between the first and second sequences changes from 0 to 1, and a jump occurs. Sampling and counting start when the jump occurs. The third sequence is two consecutive 0s. The sampling of the second sequence ends when it changes from 1 to 0, and the sampling and counting of the third sequence starts at the same time.
[0053] Step 3. Determine whether the sampling count result falls within the bit sequence interval, if not, return to step 2, if yes, proceed to step 4;
[0054] If the sampling count result falls within the overlapping interval, that is, the corresponding sequence length cannot be determined based on the number of sampling points in the sampling sequence, then return to step 2.
[0055] For example, for a long sequence of 6 bits, the number of sampling points may be distributed between 174 and 210, and for a short sequence of 7 bits, the number of sampling points may be distributed between 203 and 245. Obviously, these two number distributions have an overlapping interval [203, 210]
[0056] If the number of sampling points of the current sampling sequence is 208, it is difficult to determine whether the corresponding sequence length is 6 or 7. If the corresponding sequence length cannot be determined, it is impossible to determine whether the baud rate is positively biased or negatively biased.
[0057] Step 4. Determine the baud rate offset.
[0058] Based on the comparison results, it can be determined whether there is a baud rate deviation:
[0059] Step 41. If the sampling count result does not fall into the overlapping interval, the corresponding sequence length can be determined according to the sampling count result;
[0060] Specifically, if the sampling count result falls into the sampling interval formed between two boundary points corresponding to a certain sequence length, then the sequence length corresponding to this sampling is the sequence length.
[0061] During data transmission, the sequence length can be read in real time at the receiving end RX, and the theoretical number of sampling points can be calculated based on the set oversampling rate;
[0062] By comparing the sampling count result with the number of sampling points, the sequence length corresponding to the current sampling sequence can be determined.
[0063] For example, the oversampling rate is 32. When the sampling technology result in the sampling sequence is 28, the corresponding sequence length is obviously 1. When the sampling technology result in the sampling sequence is 35, the corresponding sequence length is also 1. When the sampling technology result in the sampling sequence is 60, the corresponding sequence length is obviously 2. When the sampling technology result in the sampling sequence is 64, the corresponding sequence length is also 2. When the sampling technology result in the sampling sequence is 95, the corresponding sequence length is obviously 3.
[0064] Step 42. According to the sequence length and the sampling count result, determine whether there is a baud rate deviation. If there is, proceed to step 5; if not, proceed to step 6;
[0065] If the counting result falls at the center point, it means that there is no baud rate deviation in this monitoring and the baud rate does not need to be adjusted, then go to step 6 to end this round of baud rate detection;
[0066] If the sampling result falls into the overlapping interval, it is impossible to determine the positive or negative offset of the baud rate, record the sampling result, return to step 2, and continue to monitor the baud rate;
[0067] If the sampling result falls to the left of the center point, it means that the baud rate is negatively biased. If the counting result falls to the right of the center point, it means that the baud rate is positively biased.
[0068] For example, if the sequence length is 3 and the oversampling rate is 32, the theoretical number of sampling points is 96;
[0069] If the sample count result is also 96, it means there is no baud rate deviation.
[0070] If the sampling count result does not fall within the overlapping interval, and the sampling count result is less than 96, such as 95, that is, it falls to the left of the center point, indicating that the baud rate is negatively biased. If the sampling count result is greater than 96, such as 100, that is, it falls to the right of the center point, indicating that the baud rate is positively biased.
[0071] If the baud rate deviation is detected and the baud rate deviation is in the same direction for three consecutive times, it means that the baud rate has a stable deviation. Go to step 5 to adjust the baud rate.
[0072] Step 5. Determine whether the baud rate deviation is continuous and has the same trend; if so, correct the baud rate, otherwise return to step 2; a specific implementation of step 5 can be:
[0073] Step 51. Determine whether the baud rate deviation trend is the same as the previous one, if yes, go to step 51, otherwise return to step 2;
[0074] Step 52: Determine whether the number of baud rate deviations reaches the number threshold set in step 1. If yes, make a judgment and correct the baud rate. Otherwise, return to step 2 to continue detection.
[0075] If there is a baud rate offset and the three baud rate offsets are in the same direction, the sampling progress needs to be adaptively adjusted according to the baud rate offset. If the baud rate is a negative offset, the baud rate needs to be increased. If the baud rate is a positive offset, the baud rate configuration needs to be reduced to adaptively follow the baud rate of the transmitting device. After calculating the baud rate-related configuration and frequency division parameters, return to step 1 to configure the baud rate parameters. The baud rate is usually adjusted by adjusting the baud rate division coefficient and the oversampling rate division coefficient in step 1.
[0076] Step 6. The baud rate has not shifted, and this round of baud rate detection ends.
[0077] like Figure 4 As shown, a schematic diagram of the baud rate adjustment of the present invention is given. When the actual baud rate begins to be significantly lower than the initial baud rate set as a theoretical value over time, correction is performed to increase the actual baud rate. The increase amplitude is based on a preset program. The actual baud rate and the initial baud rate may not be completely equal in the first adjustment. The actual baud rate may be equal to or approximately equal to the initial baud rate after multiple adjustments.
[0078] The baud rate adaptive detection described in the present invention does not rely on accurate start bit position judgment, does not require the host computer to change the MCU firmware, can achieve senseless docking after power-on, does not require the host MCU to send special characters, only needs to sample the receiving end data according to the set sampling rate, record the number of oversampling points, and compare with the number of center point bits of the standard bit sequence to obtain the baud rate deviation of both parties. The longer the data length, the smaller the error introduced by the boundary jump point, and the more accurate the estimation. As the length becomes longer, overlapping may occur. If it does not fall in the overlapping interval, the center point can be directly judged. If it falls in the overlapping interval, when the center point cannot be directly judged from the number of points, the baud rate can be judged to be too large or too small by recording the change in the number of points of multiple jump edges. The center point can be found by judging whether it is too large or too small, thereby calculating the baud rate deviation.
[0079] The present invention does not force the baud rate detection to start after finding the real start bit. Figure 1 The figure shows a schematic diagram of a specific embodiment of a frame of serial communication data. During serial communication, when the level jumps from the idle state 1 to 0, data transmission begins after the start bit is detected. After the data bit transmission is completed, the stop bit is sent, the level jumps to 1, and returns to the idle state.
[0080] The present invention also adopts a statistical method to increase the robustness of baud rate detection. By counting the baud rate frequency deviations of multiple effective detection sequences, when the ratio values of the baud rate deviations of multiple detection sequences differ greatly, or the positive and negative deviation directions are inconsistent, it is indicated that this is an unstable fluctuation state, and this state is not suitable for adaptively adjusting the baud rate; when the ratio values of the baud rate deviations of multiple detection sequences are equivalent, and the positive and negative deviation directions are consistent, it is indicated that the deviation is in a stable state, and the baud rate adaptive adjustment is started to increase the accuracy and robustness of the baud rate adaptive adjustment.
[0081] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, 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 code.
[0082] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising 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.
[0083] The foregoing describes various preferred embodiments of the present invention. Unless the preferred implementation modes in various preferred embodiments are obviously self-contradictory or based on a certain preferred implementation mode, various preferred implementation modes can be arbitrarily superimposed and used in combination. The embodiments and specific parameters in the embodiments are only for clearly describing the invention verification process of the inventor, and are not used to limit the patent protection scope of the present invention. The patent protection scope of the present invention shall still be based on its claims. All equivalent structural changes made using the contents of the description and drawings of the present invention should be included in the protection scope of the present invention.
Claims
1. A universal serial port communication baud rate adaptive method, characterized in that , including the following steps: Step 1. Determine the initialization parameters of the serial port communication, determine the center point and boundary point corresponding to each sequence length, as well as the overlapping interval, and set the number threshold; The sequence length refers to the number of data between two transition edges, that is, the number of consecutive identical data (0 or 1). For example, if two consecutive numbers are 1, the sequence length is 2, and if three consecutive numbers are 0, the sequence length is 3. The overlapping interval is an interval where the boundary points of adjacent sequence lengths overlap; Step 2. Transmit data and perform sampling and counting; Step 3. Determine the bit sequence interval that the sampling count result falls into, otherwise return to step 2, if yes, go to step 4; The bit sequence interval is a bit sequence interval of the sequence length formed by calculating two boundary points of positive bias and negative bias according to the oversampling rate, the deviation range and the sequence length; Step 4. Determine the baud rate offset based on the sampling count result, specifically: Step 41. If the sampling count result does not fall into the overlapping interval, the corresponding sequence length can be inferred according to the sampling count result; Step 42. According to the sequence length and the sampling count result, determine whether there is a baud rate deviation. If there is, proceed to step 5; if not, proceed to step 6; If the counting result falls at the center point, it means that there is no baud rate deviation in this monitoring; If the sampling result falls to the left of the center point, that is, it is smaller than the center point, it means that the baud rate is negatively biased. If the counting result falls to the right of the center point, that is, it is larger than the center point, it means that the baud rate is positively biased. Step 5. Determine whether the baud rate deviation is continuous and has the same trend; if so, correct the baud rate, otherwise return to step 2; Step 6. End the baud rate detection.
2. The universal serial port communication baud rate self-adaptation method as claimed in claim 1, characterized in that: In step 1: The center point C=N*L, the boundary point SIDE=INT [C*(1± W / 2)], where N is the oversampling rate, L is the sequence length, W is the deviation range, and INT means rounding.
3. The universal serial port communication baud rate self-adaptation method as claimed in claim 1, characterized in that: The step 5 is specifically as follows: Step 51. Determine whether the baud rate deviation trend is the same as the previous one, if yes, go to step 52, otherwise return to step 2; Step 52: Determine whether the number of baud rate deviations reaches the number threshold set in step 1. If yes, make a judgment and correct the baud rate. Otherwise, return to step 2 to continue detection.
Citation Information
Patent Citations
Serial communication baud rate error tolerance range improving method and system
CN111800249A
Method and system for detecting abnormal waveform of serial port equipment
CN117871998A