CN113032320A - Asynchronous serial port communication baud rate self-adaption method - Google Patents
Asynchronous serial port communication baud rate self-adaption method Download PDFInfo
- Publication number
- CN113032320A CN113032320A CN202110383333.7A CN202110383333A CN113032320A CN 113032320 A CN113032320 A CN 113032320A CN 202110383333 A CN202110383333 A CN 202110383333A CN 113032320 A CN113032320 A CN 113032320A
- Authority
- CN
- China
- Prior art keywords
- sampling
- baud rate
- serial port
- byte
- sensitive
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000004891 communication Methods 0.000 title claims abstract description 50
- 238000000034 method Methods 0.000 title claims abstract description 30
- 238000005070 sampling Methods 0.000 claims abstract description 87
- 238000004458 analytical method Methods 0.000 claims abstract description 7
- 230000006978 adaptation Effects 0.000 claims description 5
- 238000012545 processing Methods 0.000 claims description 5
- 230000003044 adaptive effect Effects 0.000 abstract description 5
- 238000010586 diagram Methods 0.000 description 6
- 230000005540 biological transmission Effects 0.000 description 5
- 238000004364 calculation method Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012544 monitoring process Methods 0.000 description 2
- 230000007547 defect Effects 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4282—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
Abstract
The invention provides an asynchronous serial port communication baud rate self-adaption method which supports various serial port communication protocols with the same protocol message header. According to a communication protocol of the serial port equipment, selecting a first byte of a protocol format message as a sensitive byte. By carrying out variable-speed sampling analysis on the sensitive bytes, the adaptive process of the serial port communication baud rate is completed within one byte sampling time.
Description
Technical Field
The invention relates to the technical field of communication, in particular to a baud rate self-adaption method for asynchronous serial port communication.
Background
In the industrial fields of industrial control, intelligent instruments, power communication and the like, a serial communication mode is often used as a data exchange means. Generally, both communication parties of the asynchronous serial communication mode need to agree on a transmission rate and a data format in advance, the positions of both communication parties are equal, and one-to-one data transmission and reception can be normally carried out. In the instrument information acquisition, one-to-many communication conditions are often encountered, and a plurality of devices with different baud rates and different communication protocols are connected to the same RS485 or RS232 circuit.
The common baud rate self-adapting method at present is a baud rate exhaustion method and a minimum level width calculation method. The baud rate exhaustion method repeatedly tries to communicate the baud rate by sending specific bytes at different rates, and redundant synchronous bytes are required to be sent in the process, so that the effective data transmission efficiency is reduced, and the practical applicability is not strong. The minimum level width calculation method estimates the communication baud rate by accurately detecting the minimum level width, requires a larger buffer space to capture the minimum level, and has high requirements on hardware resources.
Disclosure of Invention
Aiming at the practical application requirements and the defects in the prior art, the invention aims to provide the asynchronous serial port communication baud rate self-adaption method which is strong in practicability, simple and effective in implementation method.
In order to achieve the purpose, the technical scheme adopted by the asynchronous serial port communication baud rate self-adaption method is as follows:
presetting sensitive bytes and setting a serial port baud rate self-adaptive range;
initializing sampling module parameters, and starting to sample data signals on an interface after detecting that communication data signals appear on an asynchronous serial port;
analyzing a sampling result after completing one byte sampling;
judging the sampling progress of the sensitive bytes according to the sampling result, adjusting parameters of a sampling module and processing sampling data;
the sampling result is consistent with the sensitive byte, the sampling is finished, and the baud rate is determined;
the preset sensitive byte is the first byte of data to be transmitted on the serial port as the judgment basis, the sensitive byte number is more than or equal to 1, and the baud rate self-adaptive range of the serial port is a limited integer set { B) conforming to the asynchronous serial communication protocol specification1,B2,…,Bn-1,Bn}, the collection element satisfiesThe baud rate of asynchronous serial port communication is an integer, the baud rate of asynchronous serial port communication is one of elements in the finite integer set, and the set element is selected as the current tested baud rate B.
The parameter of the initialization sampling module is that the maximum value B is selected from the serial port baud rate self-adaptive rangemaxThe value of the configured sampling frequency f is more than two times BmaxInteger multiple of value; to avoid falling edge glitch signals, the first sampling is waitingAfter which time it is carried out.
The analysis of the sampling result after completing the sampling of one byte means that the sampling is completed within the time required by transmitting one byte at the current tested baud rate B, the sampling frequency configured under the current tested baud rate B is f, andand performing sampling analysis on one group, and judging the sampling level according to the sampling law.
Judging the sampling progress of the sensitive bytes according to the sampling result refers to adjusting the sampling progress by judging the consistency of the sampling result and the preset sensitive bytes; if not, selecting the baud rate B to be tested from the serial port baud rate self-adaptive range in sequencenSmall value of Bn-1As the current baud rate B to be tested, the sampling frequency is adjusted toThe sensitive byte length is L, and the timing time T of the timer is adjusted toThe sampling module is arranged inContinuing the sampling process after the time; processing the sampled data means that the baud rate B to be tested last timenAccording to the sampling dataCarrying out data sampling at intervals; if the current baud rate B is consistent with the serial port baud rate, the baud rate B to be tested is accurately matched with the serial port baud rate, and the asynchronous serial port communication baud rate self-adaption process is finished.
Compared with the existing baud rate self-adaptive technical scheme, the method can accurately capture serial port data in real time and analyze and determine the communication baud rate, does not need to repeatedly send specific bytes for repeated attempts, reduces the hardware complexity and the cache resource requirement of baud rate self-adaptation through strict sequential logic control and sampling detection, and realizes that the communication baud rate is directly analyzed in the real-time communication of the serial port data and the communication rate is accurately matched in the process of receiving the first byte of the serial port data.
Drawings
Fig. 1 is a flowchart of an asynchronous serial port communication baud rate adaptation method according to an embodiment of the present invention.
Fig. 2 is a diagram of a sampling scenario in which the first sample lacks latency in accordance with an embodiment of the present invention.
Fig. 3 is a sample case diagram of first sample setup latency for an embodiment of the present invention.
Fig. 4 is a schematic diagram of asynchronous serial port multi-machine communication according to an embodiment of the present invention.
Detailed Description
The invention will be described in detail and clearly in connection with the embodiments of the present application and the accompanying drawings. As shown in fig. 1, a flowchart of an asynchronous serial port communication baud rate adaptive method disclosed in the embodiment of the present invention includes the steps of (1): and setting a preset sensitive byte and setting a serial port baud rate self-adaption range.
In an embodiment, the preset sensitive byte is a first byte of data to be transmitted on the serial port as a determination basis, generally, header bytes of packets of the table communication protocol are the same, communication protocols such as national standard DL/T645 and CJ/T188-2004 specify that a start byte of the packet is 0x68, and a start byte of the packet in an asynchronous serial transmission ASCII mode of the Modbus protocol is 0x 3A. According to the protocol requirements of different communication protocols, the invention can set a plurality of sensitive bytes as the baud rate self-adaptive judgment basis. The adaptive range of the serial port baud rate is a finite integer set B conforming to the asynchronous serial communication protocol specification1,B2,…,Bn-1,Bn}, the collection element satisfiesAnd selecting a set element as the current tested baud rate B as an integer.
Step (2): and initializing parameters of the sampling module and monitoring serial port data.
In a particular embodiment, the initialized sampling module parameter isSelecting maximum value B from serial port baud rate self-adaptive rangemaxConfiguring the sampling frequency f, and taking the value of the sampling frequency f to be more than two times B according to the sampling law fmaxWhole-fold number of values. And after the falling edge of the asynchronous serial port communication start bit is detected, starting to sample the data signal on the interface.
To avoid falling edge glitch signals, the first sampling is waitingAfter which time it is carried out. Fig. 2 is a diagram of a sampling scenario in which the first sample lacks latency in accordance with an embodiment of the present invention. Taking the baud rate of 19200bps as an example, a waveform when the test is carried out and the 19200bps rate is captured is shown in fig. 2, wherein the time of three sampling intervals is 50.76 mus, the actual 1-bit time is 52.08 mus, the 10-bit accumulated error is 13 mus, the final accumulated error exceeds 25%, and the margin is very small compared with the range of 33% theoretically allowed by three-time sampling, so that the communication is unstable at the 19200bps baud rate; fig. 3 is a diagram of a first sampling setup latency sampling situation according to an embodiment of the present invention, with uniform sampling distribution to avoid sampling errors.
And (3): judging whether the serial port starts to receive the transmitted data or not, if so, entering the step (4); if not, the step (2) is entered.
And (4): a timer is started. The sampling time is controlled by a timer, and the time of the serial port timer needs to be initialized before the serial port timer is started for the first time. To avoid falling edge glitch signals, the first sampling is waitingAfter which time it is carried out.
In a specific embodiment, a timer is set for sampling timing control, the timer dynamically adjusts the timing time T according to the sampling progress, and the preset value is determined by the sensitive byte length L and the current tested baud rate B. The first time of starting the timer is based on monitoring the initial bit of the serial port data, and then the dynamic control is carried out according to the sampling result.
And (5): sampling serial port data signals, and controlling to finish sampling the serial port data signals within preset time through a sampling timer.
In a specific embodiment, after completing a byte sample at the current tested baud rate B, the method followsAnd judging the level of the sampling signal for one group, analyzing the sampling data according to the group and caching the analysis result.
And (6): and if the timer is overtime, judging whether the sampling is finished.
In a specific embodiment, when the timer is overtime, whether the serial data signal sampling progress is finished or not is judged by comparing the serial data sampling analysis result in the step (5) with the sensitive bytes in the step (1) one by one; if yes, entering the step (7); if not, selecting the baud rate B to be tested from the baud rate adaptive range of the serial port in sequencenSmall value of Bn-1The current tested baud rate B is adjusted to Bn-1The sampling frequency f is adjusted accordinglyThe sensitive byte length is L, and the timing time T of the timer is adjusted toAnd processing the sampled data; at the same time, go to step (4) andand (5) continuing sampling after the moment, otherwise, executing the step (7).
And (7): and judging whether the serial port baud rate self-adaption process is finished or not. And (4) if the current tested baud rate B is the minimum value in the serial port baud rate self-adaption range and the sensitive byte is not received, returning to the step (2). If the sensitive byte is received through the step (6), the current tested baud rate B is the serial port data transmission rate, and the serial port communication baud rate self-adaption process is finished.
Fig. 4 is a schematic diagram of asynchronous serial port multi-machine communication disclosed in the embodiment of the present invention. When a plurality of devices are interconnected through a serial port, all the devices are not divided into master devices and slave devices and can communicate at different serial port communication baud rates. The relay device transmits the serial port signal to the upper end device and the lower end device.
The foregoing is a specific embodiment of the baud rate adaptive method for asynchronous serial port communication provided in the present invention, but the scope of the present invention is not limited thereto, and the scope of the present invention is defined by the claims, and any modification or modification that may be made by those skilled in the art based on the technology described in the present invention belongs to the scope of the present invention.
Claims (5)
1. A baud rate self-adapting method for asynchronous serial port communication is characterized in that the method comprises the following contents:
presetting sensitive bytes and setting a serial port baud rate self-adaptive range;
initializing sampling module parameters, and starting to sample data signals on an interface after detecting that communication data signals appear on an asynchronous serial port;
analyzing a sampling result after completing one byte sampling;
judging the sampling progress of the sensitive bytes according to the sampling result, adjusting parameters of a sampling module and processing sampling data;
and (5) finishing sampling and determining the baud rate when the sampling result is consistent with the sensitive byte.
2. The asynchronous serial port communication baud rate adaptation method of claim 1, wherein: the preset sensitive byte is the first byte of data to be transmitted on the serial port as the judgment basis, the sensitive byte number is more than or equal to 1, and the baud rate self-adaptive range of the serial port is a limited integer set { B) conforming to the asynchronous serial communication protocol specification1,B2,…,Bn-1,Bn}, the collection element satisfiesThe baud rate of asynchronous serial port communication is an integer, the baud rate of asynchronous serial port communication is one of elements in the finite integer set, and the set element is selected as the current tested baud rate B.
3. The asynchronous serial port communication baud rate adaptation method of claim 1, wherein: the parameter of the initialization sampling module is that the maximum value B is selected from the serial port baud rate self-adaptive rangemaxThe value of the configured sampling frequency f is more than two times BmaxInteger multiple of value; to avoid falling edge glitch signals, the first sampling is waitingAfter which time it is carried out.
4. The asynchronous serial port communication baud rate adaptation method of claim 1, wherein: the analysis of the sampling result after completing the sampling of one byte means that the sampling is completed within the time required by transmitting one byte at the current tested baud rate B, the sampling frequency configured under the current tested baud rate B is f, andand carrying out sampling analysis on one group, and judging the level of the sampling level.
5. The asynchronous serial port communication baud rate adaptation method of claim 1, wherein: judging the sampling progress of the sensitive bytes according to the sampling result refers to adjusting the sampling progress by judging the consistency of the sampling result and the preset sensitive bytes; if not, selecting the baud rate B to be tested from the serial port baud rate self-adaptive range in sequencenSmall value of Bn-1As the current baud rate B to be tested, the sampling frequency is adjusted toThe sensitive byte length is L, and the timing time T of the timer is adjusted toThe sampling module is arranged inContinuing the sampling process after the time; processing the sampled data means that the baud rate B to be tested last timenAccording to the sampling dataCarrying out data sampling at intervals; if the current tested baud rate B is consistent with the serial port baud rate, the current tested baud rate B is accurately matched with the serial port baud rate, and the asynchronous serial port communication baud rate self-adaption process is finished.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110383333.7A CN113032320B (en) | 2021-04-09 | 2021-04-09 | Asynchronous serial port communication baud rate self-adaption method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110383333.7A CN113032320B (en) | 2021-04-09 | 2021-04-09 | Asynchronous serial port communication baud rate self-adaption method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113032320A true CN113032320A (en) | 2021-06-25 |
CN113032320B CN113032320B (en) | 2022-10-18 |
Family
ID=76456173
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110383333.7A Expired - Fee Related CN113032320B (en) | 2021-04-09 | 2021-04-09 | Asynchronous serial port communication baud rate self-adaption method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113032320B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114039807A (en) * | 2021-11-05 | 2022-02-11 | 深圳数马电子技术有限公司 | Baud rate self-adaption method and device, computer equipment and storage medium |
CN114490487A (en) * | 2022-02-16 | 2022-05-13 | 瀚云科技有限公司 | Serial port information acquisition method, device, equipment and storage medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20030048862A1 (en) * | 2001-09-10 | 2003-03-13 | Hsin-Hsien Lee | Automatic calibration & synchronization for digital asynchronous communication |
CN103001734A (en) * | 2012-10-17 | 2013-03-27 | 海军工程大学 | Method for automatically detecting asynchronous serial port communication protocol on basis of level sampling |
CN103618588A (en) * | 2013-11-26 | 2014-03-05 | 中国科学院嘉兴微电子与系统工程中心 | Automatic Baud rate detection method and detection module |
CN105049151A (en) * | 2015-07-03 | 2015-11-11 | 福州瑞芯微电子股份有限公司 | Method for controlling serial port communication and communication serial port |
CN111737182A (en) * | 2020-06-29 | 2020-10-02 | 山东管理学院 | Automatic configuration method and system for serial communication parameters |
CN112039635A (en) * | 2020-08-28 | 2020-12-04 | 杭州万高科技股份有限公司 | UART baud rate self-adaption method and device based on RC oscillator |
-
2021
- 2021-04-09 CN CN202110383333.7A patent/CN113032320B/en not_active Expired - Fee Related
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20030048862A1 (en) * | 2001-09-10 | 2003-03-13 | Hsin-Hsien Lee | Automatic calibration & synchronization for digital asynchronous communication |
CN103001734A (en) * | 2012-10-17 | 2013-03-27 | 海军工程大学 | Method for automatically detecting asynchronous serial port communication protocol on basis of level sampling |
CN103618588A (en) * | 2013-11-26 | 2014-03-05 | 中国科学院嘉兴微电子与系统工程中心 | Automatic Baud rate detection method and detection module |
CN105049151A (en) * | 2015-07-03 | 2015-11-11 | 福州瑞芯微电子股份有限公司 | Method for controlling serial port communication and communication serial port |
CN111737182A (en) * | 2020-06-29 | 2020-10-02 | 山东管理学院 | Automatic configuration method and system for serial communication parameters |
CN112039635A (en) * | 2020-08-28 | 2020-12-04 | 杭州万高科技股份有限公司 | UART baud rate self-adaption method and device based on RC oscillator |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114039807A (en) * | 2021-11-05 | 2022-02-11 | 深圳数马电子技术有限公司 | Baud rate self-adaption method and device, computer equipment and storage medium |
CN114490487A (en) * | 2022-02-16 | 2022-05-13 | 瀚云科技有限公司 | Serial port information acquisition method, device, equipment and storage medium |
CN114490487B (en) * | 2022-02-16 | 2023-12-19 | 瀚云科技有限公司 | Method, device, equipment and storage medium for acquiring serial port information |
Also Published As
Publication number | Publication date |
---|---|
CN113032320B (en) | 2022-10-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113032320B (en) | Asynchronous serial port communication baud rate self-adaption method | |
US9026832B2 (en) | Method, system and device for removing media access control addresses | |
CN104750588A (en) | Serial port communication based pressure testing method | |
US11343067B2 (en) | Sampling point identification for low frequency asynchronous data capture | |
US11606185B2 (en) | Detection of physical layer parameter of a master device in an ethernet network | |
CN112752285B (en) | Sniffing copy control equipment and method for Wi-SUN network test | |
WO2012151827A1 (en) | Method and device for testing uplink delay of radio remote unit (rru) | |
CN110798386B (en) | Configurable CAN bus protocol transceiving test method and system | |
CN203574663U (en) | Automatic baud rate detection module | |
CN108667706B (en) | Ethernet serial server with dynamically adjustable serial number and data transmission method thereof | |
US20070258478A1 (en) | Methods and/or apparatus for link optimization | |
CN114243954B (en) | Wireless equipment matching communication system and method based on waveform characteristics and electronic equipment | |
CN101150339A (en) | A TD-SCDMA trunk amplifier using network modulation synchronization mode | |
CN106487421A (en) | Power line carrier communication test system and its method of testing | |
CN109283457B (en) | Method for detecting electrical performance of M-BUS communication interface | |
CN109639457B (en) | System and method for testing single event error rate of JESD204B protocol high-speed transmitter | |
CN103152134A (en) | Real time protocol (RTP)-based method and system for rearranging voice packets at receiving end | |
CN112597081A (en) | UART software implementation method based on low-voltage Internet of things sensing terminal | |
CN109981394B (en) | Communication method and device based on enhanced CAN bus protocol analyzer | |
US20130266044A1 (en) | Communication system and test apparatus | |
CN111339005A (en) | Data acquisition method and device and computer readable storage medium | |
CN117785747A (en) | Method, device and chip for configuring communication interface | |
CN101582727B (en) | Method and device for time template measurement | |
CN117076372B (en) | Communication signal receiving interface circuit and communication method | |
CN109254942B (en) | Method and device for adjusting bus signals |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20221018 |