A automatic detection method of serial communication baud rate

xiaoxiao2021-03-06  46

Automatic detection method of serial communication baud (Department of Control Engineering, Harbin Institute of Technology), 150001, China) Ren Gui Yong Qi Yan Cheng Wang Changhong Abstract: Give a use of receiving site ⒓ ⒓    ㄐ ㄌ芈? Methods. This method is simple, reliable, easy, and gives pseudo code for implementing this detection method. Key words: automatic detection; baud rate serial communication is the main communication mode between terminals and hosts, and communication baud rates are generally selected from 1800, 4800, 9600, and 19200. There are many types of terminals, and there are many options in communication rates. How does the host determine the communication rate of the terminal? This article gives a simple and easy way: set the host's receiving baud rate (9600 baud as an example), the terminal sends a specific character (as an example of the carriage, the host is received according to the received) Character information can determine the communication baud rate of the terminal. This method is detailed in this way. 1 Basic method The ASCII value of the carriage return is 0x0d. Attaching a starting bit and terminating bit when serial communication, the transmission order of the bit is generally the first pass low. At this time, the binary representation of the carriage return is: the transmission time (remember to t) of a binary bit in serial communication in the serial communication of the carriage return depends on the baud rate of the communication, a binary position at 9600 baud. The transmission time is twice the transmission time of 19200 baud, namely: 2 * T19200 = T 9600. Therefore, two bits can be transmitted at a position of 9600 baud, 19200 baud can transmit two bits. Similarly, 9600 baud transmits two bits of time at 4800 baud can only transfer one bit. The host sets the receiving baud rate of 9600, and the terminal only transmits with 9600 baud, the host can receive correctly. The send baud rate is higher than or less than 9600, it will cause the host to receive the character to be errors. When the receiving baud rate is 9600, when the terminal transmits the back-end with a different baud rate, the binary sequence received by the main machine is shown in Table 1. As can be seen from Table 1, in addition to the two special cases of 19200 and 1800 baud, the binary sequences of other situations are transformations of the binary sequence of 9600 baud. Take the first ten binary positions corresponding to the binary position at 9600 baud. Ignore the data frame error caused by the lack of stop bit '1', indicate the received character into byte mode (as shown in Table 1). For example: When the transmission rate is 1200 baud, the received rate is 9600 baud, the host obtained by the host is 0x80, not the correct carriage return 0x0d. Since the bytes obtained at different transmission rates (9600, 4800, 2400, 1200) are different, the transmission baud rate can be determined by the determination of the character. When the transmission baud rate is 19,200, the transmission speed is exactly twice the receiving speed (9600 baud), so the two binary bits of the transmitting end are viewed as one. Depending on the different serial interface hardware, '01 'and' 10 'These two binary combinations may be considered' 1 'or' 0 '. Fortunately, only 0 to 4 bits have such ambiguity, the back bit is because it is stopped, so it is '1'. Therefore, the high half byte of the character received when the transmission rate is 19,200 Baud is 0xF. Low half bytes may be one of multiple values, but will not be 0x0 because there are two adjacent '1' in 0x0D, which will generate a '1' at least in low half bytes. Therefore, the entire byte is 0xF ?, and low half bytes are not 0. Table 1 Binary sequence at different baud rates

Bud rate received two-way sequence byte 19200 0 1 0 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0xF? 9600 0 1 0 1 0 0 0 0 1 0x0D 4800 0 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 xE6 2400 0 0 0 0 1 1 1 0 0 0 0 1 1 1 1 1 1 1 0 x 78 1800 0 0 0 0 0 x 1 1 1 1 x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x00 150 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0X00 Transmit Rate is 1800 waves Base, because T1800 = T9600 * 16/3, while 16/3 is not an integer, the state conversion time of the receiving end binary bit and the 9600 baud are not correspondingly, causing state changes in a bit reception cycle in the receiving end. may. The sixth bit (represented as X) given in Table 1 is this situation. Because x is likely to be seen as '1', it is possible to be considered to '0', so the transmitted byte that is received when the transmission rate is 1800 baud may be 0xe0 or 0xF0. The baud rate also has the same problem when there are 3600 and 7200, or the same method can also be used, but uncertain numbers will increase, and the type of byte is required will also be more. The transmission rate of 3600 baud and 7200 baud is hardly used, so this problem is not serious. As long as the transmission baud rate is between 1200 and 19200, we can perform a unique judgment of this baud by the received character. 2 Low-baud rate detection When the transmission rate is less than 1200 baud, the byte received by the receiving end is 0x00, so it can only determine if its rate is less than 1200 baud, and more information is not possible. . In order to solve this problem, you can continue to receive one byte information at a rate of 9600 baud. When the transmission rate is 600 baud or less, the transmission time of one bit is greater than the reception time of the entire byte when 9600 baud. Therefore, each of the transitions from '1' (terminating bits) to '0' (start bit) will begin to start with a new byte. Table 2 shows the binary sequence of the receiving end returns when the 600 baud or lower transmission rate (only some of the starting bits) is given. Table 2 Receive method of low-baud rate enrollment

Porter rate 9600 baud binary sequence time difference (cycle) time difference (real time) 600 16 0's 16 1's 16 0's 32 3.33ms 300 32 0's 32 1's 32 0'S 64 6.66MS 150 64 0'S 64 1's 64 0's 128 13.33ms 110 87 0's 87 1 $ 87 0's 174 18.13MS 75 128 0'S 128 1'S 128 0'S 256 26.66MS 50 192 0'S 192 1's 192 0'S 384 4 0.00ms

转载请注明原文地址:https://www.9cbs.com/read-80094.html

New Post(0)