Electronic Knowledge Encyclopedia: Automatic Identification of Serial Communication Baud Rate

Publisher:SereneWandererLatest update time:2012-01-14 Source: 单片机及嵌入式系统应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
For asynchronous serial communication, correct data transmission and reception can only be achieved when the baud rates of both parties are the same; and some systems always hope to achieve compatibility with various baud rates. The usual implementation method is to require the other party to send a specified character or data first. After the system receives the character or data, it calculates the baud rate of the other party. To adapt to the baud rate of the other party to work, such as some wireless transceiver modules, GSM communication modules, etc. However, for the fields of detection and testing, it is not possible to require the system under test to send a fixed character or data. So for such communication systems, how to achieve reliable baud rate identification? This paper innovatively proposes a method of finding the greatest common divisor based on the capture of code element width. This method can achieve baud rate identification without making special requirements on the data sent by the system under test, and ensures the effectiveness and reliability of baud rate identification. The following is a detailed description of this method.

1 Traditional methods and basic principles of automatic baud rate identification

Serial communication data is transmitted in bit order, while asynchronous serial communication does not have a bit timing clock, so strict timing is required between each data bit to ensure correct communication. In other words, only when the baud rates of both communicating parties are the same can the correct transmission and reception of data be achieved. There are two main traditional methods for automatic baud rate identification:
① Standard baud rate exhaustive method. The standard baud rate exhaustive method is applicable to the situation where the baud rate on the host side must vary between a limited number of fixed values, such as the standard value between 300 and 19200; and the working oscillation frequency on the slave side is known and stable. After the slave starts the communication program, it tries to receive specific characters sent by the host at different baud rates one by one until it can be received correctly. Therefore, the application of this method has certain limitations.
② Real-time detection method of code element width. This method requires the host to send a certain data according to the agreement, and the slave measures the code element width of the input data on the RXD pin through the timer of the microcontroller, and then calculates the baud rate of the communication of the system to be tested. This method is currently widely used. For example, in order to adapt to various communication baud rates, a certain GSM module is designed to require the communicating system to send 08H first and then send instructions. It calculates the baud rate of the other party based on the code element width of the data 08H.

2 Principle and implementation of the greatest common divisor method
The traditional method has certain restrictions or requirements on the data sent by the system under test to achieve baud rate recognition, but sometimes it is impossible to constrain the system under test to send specific characters first. Here, according to different application requirements, a more general baud rate recognition method-the greatest common divisor method is proposed.
For the convenience of explanation, let the baud rate of the host be BPS, the bit transmission time be t1bit, the baud rate measured by the test system be BAUD, and the bit transmission time be txbit. Taking l start bit, 8 data bits, 1 stop bit, and no parity bit as an example, the communication data format is shown in Figure 1. In addition to the start bit always being 0 and the stop bit always being 1, the level of the 8-bit data bit is determined by the transmitted data. To measure the baud rate of the system under test, according to the actual meaning of the baud rate BPS=l/t1bit, it is sufficient to detect the bit transmission time t1bit of the communication data of the system under test.

The bit transmission time t1bit corresponds to the unit code width time. As long as the unit code width time is known, the system baud rate can be easily calculated. Since the system under test cannot be required to send specific data or characters according to regulations, the code width capture method is used here to find the code width time. The single-chip microcomputer should be hung in the communication line of the system under test, and the high and low level pulse duration of the TXD (or RXD) pin of the system under test should be continuously collected to capture the unit code width time t1bit. Obviously, the duration of a single high and low level pulse directly collected by the single-chip microcomputer may be nt1bit, where 1≤n≤9. How to find t1bit from the collected nt1bit becomes the key to baud rate identification.
After analyzing the characteristics of the serial communication data format, this paper proposes the code width greatest common divisor method to calculate the unit code width time from the captured code width time, that is, the bit transmission time t1bit. The specific implementation method is as follows: After the system under test works normally, the test microcontroller is connected to its communication line; first, the positive and negative pulse widths are timed, collected n times respectively, and after eliminating the overflow of the positive pulse, all unequal effective pulse width times are sorted from small to large (if △t<5μs, the two times are considered equal, which will be explained later), assuming that they are t1, t2, t3, ..., tm (1≤m≤9) in sequence; since the collected time must be an integer multiple of t1bit, the greatest common divisor of t1, t2, t3, ..., tm is calculated to be txbit, then txbit can be used as the minimum pulse width of the system to calculate the baud rate. The txbit calculated here may be equal to t1bit, or it may not be equal to t1bit. The following classifies and discusses the reliability and basis of using t1bit as the bit transmission time to calculate the baud rate.
In the first case, txbit=t1bit: the narrowest positive pulse or the narrowest negative pulse appears in the communication process of the system under test, and the obtained txbit is equal to t1bit, then it is reliable to use txbit to calculate the baud rate; the narrowest positive pulse or the narrowest negative pulse does not appear in the communication process of the system under test, but the greatest common divisor of the pulse width that appears in the system communication process is the narrowest pulse width, such as 2t1bit, 3t1bit pulse time appears in the system under test, or 4t1bit, 7t1bit, 8t1bit pulse time appears in the system under test, at this time the greatest common divisor txbit is still equal to t1bit, in this case the baud rate can be reliably identified.
The second case, txbit≠t1bit, that is, txbit=N't1bit (2≤N'≤9): If the pulse width time that appears during the system communication process is an integer multiple of N't1bit, taking N'=2 as an example, only data similar to that shown in Figure 2(a) may appear during the communication process of the system under test, and the greatest common divisor txbit=2t1bit, BAUD=BPS/2, and the actual measured baud rate is 1/2 of the baud rate of the system under test. However, we note that the measured data is shown in Figure 2(b), which is FFH, FEH, FDH, FCH, FBH, FAH, F9H, and F8H in sequence. Although the measured baud rate is not the baud rate of the system under test, it does not cause information loss, and all data can be correctly restored. Therefore, in this case, it is completely reliable to use the greatest common divisor method to calculate the baud rate.

Issues to note when finding the greatest common divisor:
① Approximate equality. As mentioned earlier, if the time difference between two pulse widths of the detected serial communication is △t<5μs, the two times are considered to be approximately equal. This is determined by the characteristics of serial communication. Assuming that the acquisition system design indicator requires the system to be able to identify the baud rate between 300 and 38,400 bps, then the calculated bit transmission time t1bit is 26μs≤t1bit≤3400μs; and the detected pulse time can be expressed as nt1bit, where n is a natural number 1≤n≤9, then the time difference between any two pulse widths △t=(n-1)t1bit. Obviously, the time difference △t between two pulses is either an integer multiple of t1bit or 0, and 26μs≤t1bit≤3400μs. Therefore, if the time difference △t between two pulse widths of the system to be tested is detected to be less than 5μs, then the two times can be considered to be approximately equal (experimental results show that the time difference between any two pulse widths is less than or equal to 2μs. The reason why it is sometimes not equal to 0 is the error caused by the rising and falling edge time of the pulse during serial communication and the start and end timing of the microcontroller).
② Approximately equal to 0. The bit transmission time t1bit is 26μs≤t1bit≤3400μs, so the detected pulse width must be ≥26μs. If the pulse width of the system to be tested is detected to be less than 5μs, it can be considered to be approximately equal to 0. In fact, after a large number of experiments, the result of directly detecting that a pulse width time is less than 5μs will not appear. Its significance is that when calculating the greatest common divisor, the effective pulse times t1, t2, t3, ..., tm collected should be divided by the minimum time t1 respectively, and the remainders are A2, A3, ..., Am from small to large. At this time, in addition to the remainders that are approximately equal to t1, there are also some remainders that are less than 5μs, so at this time, the remainders are considered to be approximately equal to 0, and the remaining remainders are neither approximately equal to t1 nor approximately equal to 0. Only one of the approximately equal remainders is retained, and these remainders are Ax, Ay, Az (up to 3) from small to large, then Ax, Ay, Az are considered to be the smaller pulse width times calculated. Then the previously collected times t1, t2, t3, ..., tm and Ay, Az are divided by Ax respectively. Assume that the remainders are B1, B2, B3, ..., Bk. If there is no remainder in the interval (5, Ax-5), then Ax can be used as t1bit to calculate the baud rate; if there is Bx that meets the conditions, then Bx can be used as t1bit to calculate the baud rate of the system under test (there is no need to continue to calculate the remainder, and the basis will not be repeated).


3 Experimental results and conclusions
Since the baud rate can still be correctly identified and communicated within the deviation range of ±3%, the author judged that the reference range of the bit transmission time at different baud rates is listed in Table 1. After a large number of experiments and tests, the corresponding relationship between the typical value of the bit transmission time collected at different baud rates and the baud rate is also given here. The maximum deviation of other sample values ​​collected from the typical value is less than 1%, so this method is feasible and reliable for baud rate recognition.

The greatest common divisor method of code element width proposed in this paper realizes baud rate recognition, which can be realized using C5l series single-chip microcomputer and assembly language; its algorithm is simple, program space requirements are small, speed is fast, and efficiency is high. In the application design that requires real-time detection and data processing, the baud rate recognition program can be started by key interruption. After the recognition is completed, the detection system sets its own baud rate to be consistent with the system to be tested, and then returns after interruption, and enters the main program for communication and data processing. After a large number of tests and experiments, it is proved that this method is feasible and reliable to realize baud rate recognition, and can be promoted in different application fields, especially in the field of detection and testing, which has great potential.

Reference address:Electronic Knowledge Encyclopedia: Automatic Identification of Serial Communication Baud Rate

Previous article:The principle and application of picosecond laser
Next article:An anti-electromagnetic interference packaging technology for electronic fuze

Latest Power Management Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号