CN111782572A - Baud rate self-adaptive USB serial port device and method - Google Patents

Baud rate self-adaptive USB serial port device and method Download PDF

Info

Publication number
CN111782572A
CN111782572A CN202010541049.3A CN202010541049A CN111782572A CN 111782572 A CN111782572 A CN 111782572A CN 202010541049 A CN202010541049 A CN 202010541049A CN 111782572 A CN111782572 A CN 111782572A
Authority
CN
China
Prior art keywords
usb
serial port
baud rate
line
serial
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.)
Pending
Application number
CN202010541049.3A
Other languages
Chinese (zh)
Inventor
丁峰平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Innovation Research Institute of Beihang University
Original Assignee
Hangzhou Innovation Research Institute of Beihang University
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Hangzhou Innovation Research Institute of Beihang University filed Critical Hangzhou Innovation Research Institute of Beihang University
Priority to CN202010541049.3A priority Critical patent/CN111782572A/en
Publication of CN111782572A publication Critical patent/CN111782572A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/14Handling requests for interconnection or transfer
    • G06F13/20Handling requests for interconnection or transfer for access to input/output bus
    • G06F13/28Handling requests for interconnection or transfer for access to input/output bus using burst mode transfer, e.g. direct memory access DMA, cycle steal
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/0042Universal serial bus [USB]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)
  • Communication Control (AREA)

Abstract

The invention discloses a USB serial port device and method for self-adapting baud rate, the device comprises: a USB interface, a USB firmware, a receiving and transmitting buffer/receiving sampling interface, a transmitting line TX and a receiving line RX; the method comprises the following steps: the serial port equipment realizes a USB virtual serial port by using a USB CDC protocol processing unit, and the personal computer automatically identifies and loads a CDC virtual serial port driver; the serial port equipment performs special processing on the SET _ LINE _ CODING request in the CDC protocol; the serial port equipment reports the baud rate which is adapted to the matching in the GET _ LINE _ CODING request; the serial port equipment sends the data of the USB CDC OUT Endpoint unit to the embedded system; and the serial port equipment sends the received data of the embedded system to the personal computer. The invention does not need additional installation of a drive for a personal computer, and the calculation method is simple and easy to realize.

Description

Baud rate self-adaptive USB serial port device and method
Technical Field
The invention relates to the field of data communication, in particular to a USB serial port device capable of self-adapting to a baud rate.
Background
In modern embedded systems, asynchronous serial communication interfaces are often found in single-chip computers and embedded systems as standard peripherals. When the personal computer communicates with the embedded system, the baud rate of the serial interface of the embedded system must be known in advance and the same baud rate of the PC serial equipment must be set, so that normal communication can be performed.
Under the limit of cost and volume, the serial port (RS232) interface of the novel personal computer is less and less or is directly eliminated. Instead, more USB interfaces are used. It is a trend to use USB to serial to communicate with embedded systems.
Disclosure of Invention
The invention provides a USB serial port device and a method capable of adapting to a baud rate, which aim to solve the problems that the conventional serial port device needs to manually specify the baud rate of a serial port, and a novel personal computer has few or even no serial port.
The invention specifically adopts the following technical scheme:
the invention relates to a USB serial port device capable of self-adapting to baud rate, which comprises: a USB interface, a USB firmware, a receiving and transmitting buffer/receiving sampling interface, a transmitting line TX and a receiving line RX; wherein the USB firmware comprises: a Control Endpoint unit, an OUT Endpoint unit, an IN Endpoint unit and a CDC protocol processing unit; the USB interface is connected with the USB interface of the personal computer, the USB firmware of the equipment forwards the USB data to the receiving and transmitting buffer/receiving sampling interface after the USB data is analyzed by the CDC protocol processing unit, and the USB data is connected with the embedded system through the transmitting line TX and the receiving line RX, so that the function of converting the USB data into the serial port is realized.
The invention provides a method for adapting the baud rate of an embedded system by using USB serial equipment, which is used for realizing the function of adapting the baud rate of the embedded system equipment by serial software of a personal computer and comprises the following steps:
and step 11, the serial Device realizes a USB virtual serial port by using a USB CDC (Communication Device Class) protocol processing unit, and the personal computer can automatically identify and load a CDC virtual serial port driver.
Step 12, the serial device performs special processing on the SET _ LINE _ CODING (setting CODING format) request in the CDC protocol: defining a specific baud rate (e.g., 100bps) as a flag to turn on the adaptive baud rate function or ignoring the SET _ LINE _ CODING request always enables the adaptive baud rate function. And the serial port equipment reports the adaptively matched baud rate in a GET _ LINE _ CODING (acquiring CODING format) request.
And step 13, the serial port equipment sends the data of the USB CDC OUT Endpoint unit to the embedded system through a sending line TX of the serial port equipment.
And step 14, the serial port equipment sends the data of the embedded system received on a receiving line RX of the serial port equipment to a personal computer through a USB CDC IN Endpoint unit.
Further, the adaptive baud rate characteristic of the serial device is mainly based on oversampling of a transmission line (TX) of a serial interface of an embedded system, and the adaptive baud rate function of the serial device is realized:
and step 21, because the start bit of a transmission frame of the serial port is a low level, the serial port device starts sampling by taking the TX falling edge of the embedded system as an interrupt signal.
And step 22, the serial port device samples high and low level pulses on a transmission line TX of the embedded system by using a self timer clock and records the numerical value of each pulse width meter.
Step 23, the serial port device calculates the pulse widths of the high and low levels in a unified manner to obtain a minimum pulse width meter
Numerical values.
And 24, the serial port equipment repeats the steps 21 to 23, continues to calculate the pulse width of the next frame of data to obtain the minimum pulse width value, and then compares the minimum pulse width value with the minimum pulse width value of the previous frame to obtain a minimum value.
And step 25, the serial port device matches the closest baud rate with the minimum pulse width of the two data frames, calculates all data of the two data frames according to the baud rate with the minimum pulse width closest to the baud rate, and stores all data frames in a receiving cache for sending to a personal computer.
The invention relates to a USB serial port device and method capable of self-adapting to baud rate, which has the advantages and effects that: the USB virtual serial port is realized by using a CDC protocol, and a personal computer is not required to be additionally provided with a driver; the method for self-adapting the baud rate, namely the minimum pulse width calculation method, is simple and easy to realize, and can obtain the pulse width of a single-bit pulse at a rate of about 99.963% by only using two frames: taking a high-level stop bit, no parity bit, as an example, only the following 24 data frames will not have a single-bit pulse: 01100111/01100011/01100001/01110001/01110011/01111001/01111000/01111100/01111111/00110011/00110001/00110000/00111001/00111100/00111111/00011001/00011100/00011111/00001100/00001111/00000111/00000011/00000001/00000000, respectively; then the probability that no single-bit pulse appears in two consecutive frames is (24/256) x (1/256) ═ 0.037%, i.e. about 99.963% can obtain the pulse width of a single-bit pulse.
Drawings
Fig. 1 is a schematic block diagram of a personal computer communicating with an embedded system via a USB serial device according to the present invention.
Fig. 2 is a schematic diagram of a module for adapting the baud rate of the USB serial device according to the present invention.
Detailed Description
The present invention will be described in detail with reference to the accompanying drawings.
The invention relates to a USB serial device with a self-adaptive baud rate, as shown in figure 1, comprising: a USB interface, a USB firmware, a receiving and transmitting buffer/receiving sampling interface, a transmitting line TX and a receiving line RX; wherein the USB firmware comprises: a control Endpoint unit, an OUT Endpoint unit, an IN Endpoint unit and a CDC protocol processing unit; the USB interface is connected with the USB interface of the personal computer, the USB firmware of the equipment forwards the USB data to the receiving and transmitting buffer/receiving sampling interface after the USB data is analyzed by the CDC protocol processing unit, and the USB data is connected with the embedded system through the transmitting line TX/receiving line RX, so that the function of converting the USB to the serial port is realized.
As shown in fig. 1, when the serial software reads the baud rate of the USB serial device, the GET _ LINE _ CODING command in the CDC protocol is used to obtain the baud rate information, the command reads the Control port corresponding to the USB serial device through the Control port (Control Endpoint), and the firmware of the USB serial device implements the corresponding GET _ LINE _ CODING command to report the adaptive baud rate information.
The firmware of the USB serial port device performs special processing on a SET _ LINE _ CODING (setting code format) request in a CDC protocol, defines a specific baud rate (such as 100bps) as a mark to start a self-adaptive baud rate function, or ignores the SET _ LINE _ CODING (setting code format) request and always enables the self-adaptive baud rate function.
And the USB serial port equipment sends the data of the USB CDC OUT Endpoint to the embedded system through the TX of the equipment according to the obtained baud rate matched with the minimum pulse width.
And the equipment sends the received data of the embedded system to the personal computer through the USB CDC IN Endpoint.
As shown in fig. 2, the USB serial device starts sampling with the TX falling edge of the embedded system as an interrupt signal. The USB serial port equipment samples high and low level pulses on a transmitting TX of the embedded system by using a self timer clock and records the numerical value of each pulse width meter.
The USB serial port device calculates the pulse widths of high and low levels in a unified manner to obtain a minimum pulse width count value, wherein the minimum pulse width count value is about 104 by taking 9600 baud rate and 1MHz of a timer clock as an example.
The USB serial device continues to perform pulse width calculation on the next frame of data to obtain a minimum pulse width value, and then compares the minimum pulse width value with the minimum pulse width value of the previous frame to obtain a minimum value, for example, 103.
The device matches the nearest common baud rate of 9600 with the minimum pulse width 103 of two data frames, calculates all data of the two data frames with the baud rate of 9600, and stores all the data frames in a receiving buffer for sending to a personal computer.

Claims (4)

1. A USB serial port device with adaptive baud rate comprises: a USB interface, a USB firmware, a receiving and transmitting buffer/receiving sampling interface, a transmitting line TX and a receiving line RX; wherein the USB firmware comprises: a Control Endpoint unit, an OUTENPoint unit, an IN Endpoint unit and a CDC protocol processing unit; the USB interface is connected with the USB interface of the personal computer, the USB firmware of the equipment forwards the USB data to the receiving and transmitting buffer/receiving sampling interface after the USB data is analyzed by the CDC protocol processing unit, and the USB data is connected with the embedded system through the transmitting line TX and the receiving line RX, so that the function of converting the USB data into the serial port is realized.
2. A method for using USB serial port apparatus to adapt the baud rate of the embedded system, realize the baud rate of the serial software self-adaptation embedded system apparatus of the personal computer, including the following step:
step 11, the serial port device utilizes the USB CDC protocol processing unit to realize a USB virtual serial port, and the personal computer automatically identifies and loads a CDC virtual serial port driver;
step 12, the serial device performs special processing on the SET _ LINE _ CODING request in the CDC protocol: defining a specific baud rate as a mark to start the self-adaptive baud rate function, or ignoring the SET _ LINE _ CODING request, and always enabling the self-adaptive baud rate function; the serial port equipment reports the baud rate which is adapted to the matching in the GET _ LINE _ CODING request;
step 13, the serial port equipment sends the data of the USB CDC OUT Endpoint unit to an embedded system through a sending line TX of the serial port equipment;
and step 14, the serial port equipment sends the data of the embedded system received on a receiving line RX of the serial port equipment to a personal computer through a USB CDCIN Endpoint unit.
3. The method for adapting the baud rate of the embedded system by using the USB serial device according to claim 2, wherein the method comprises the following steps: the self-adaptive baud rate characteristic of the serial device is based on oversampling of a transmission line of a serial interface of an embedded system, and the self-adaptive baud rate function of the serial device is realized.
4. The method for adapting the baud rate of the embedded system by the USB serial device according to claim 3, wherein: the oversampling realizes the function of self-adapting baud rate of the serial device, and the specific process is as follows:
step 21, because the start bit of a transmission frame of the serial port is a low level, the serial port device starts sampling by taking a TX falling edge of the embedded system as an interrupt signal;
step 22, the serial port device samples high and low level pulses on a transmission line TX of the embedded system by using a self timer clock and records the numerical value of each pulse width meter;
step 23, the serial port device calculates the pulse widths of high and low levels in a unified manner to obtain a minimum pulse width count value;
step 24, the serial port device repeats the steps 21 to 23, continues to perform pulse width calculation on the next frame of data to obtain a minimum pulse width meter value, and then compares the minimum pulse width meter value with the minimum pulse width meter value of the previous frame to obtain a minimum value;
and step 25, the serial port device matches the closest baud rate with the minimum pulse width of the two data frames, calculates all data of the two data frames according to the baud rate with the minimum pulse width closest to the baud rate, and stores all data frames in a receiving cache for sending to a personal computer.
CN202010541049.3A 2020-06-15 2020-06-15 Baud rate self-adaptive USB serial port device and method Pending CN111782572A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010541049.3A CN111782572A (en) 2020-06-15 2020-06-15 Baud rate self-adaptive USB serial port device and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010541049.3A CN111782572A (en) 2020-06-15 2020-06-15 Baud rate self-adaptive USB serial port device and method

Publications (1)

Publication Number Publication Date
CN111782572A true CN111782572A (en) 2020-10-16

Family

ID=72756475

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010541049.3A Pending CN111782572A (en) 2020-06-15 2020-06-15 Baud rate self-adaptive USB serial port device and method

Country Status (1)

Country Link
CN (1) CN111782572A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112422363A (en) * 2020-10-27 2021-02-26 成都航空职业技术学院 Automatic detection device and method for asynchronous serial port communication baud rate
CN114661646A (en) * 2022-03-31 2022-06-24 深圳市凯迪仕智能科技有限公司 Serial port switching control circuit

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6263033B1 (en) * 1998-03-09 2001-07-17 Advanced Micro Devices, Inc. Baud rate granularity in single clock microcontrollers for serial port transmissions
CN104168080A (en) * 2013-05-15 2014-11-26 上海贝尔股份有限公司 Method and apparatus for baud rate self adaption, and equipment
CN107403573A (en) * 2017-07-20 2017-11-28 湖北工业大学 A kind of USB experimental systems and method based on STM32F7

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6263033B1 (en) * 1998-03-09 2001-07-17 Advanced Micro Devices, Inc. Baud rate granularity in single clock microcontrollers for serial port transmissions
CN104168080A (en) * 2013-05-15 2014-11-26 上海贝尔股份有限公司 Method and apparatus for baud rate self adaption, and equipment
CN107403573A (en) * 2017-07-20 2017-11-28 湖北工业大学 A kind of USB experimental systems and method based on STM32F7

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
叶存奎: ""USB设备协议栈的设计与实现"", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *
陈旭辉: ""USB接口的虚拟多串口通信设备设计"", 《单片机与嵌入式系统应用》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112422363A (en) * 2020-10-27 2021-02-26 成都航空职业技术学院 Automatic detection device and method for asynchronous serial port communication baud rate
CN114661646A (en) * 2022-03-31 2022-06-24 深圳市凯迪仕智能科技有限公司 Serial port switching control circuit

Similar Documents

Publication Publication Date Title
US4761800A (en) Method and apparatus for detecting a rate of data transmission
CN111782572A (en) Baud rate self-adaptive USB serial port device and method
US7565583B2 (en) Multilink receiver for multiple cordless applications
WO2004059497A3 (en) Wireless cable replacement for computer peripherals using a master adapter
CN112565036B (en) Data transmission method, device, storage medium and communication system
EP1199641A3 (en) Data processing device used in serial communication system
WO2024032441A1 (en) Device wake-up method, apparatus and system, and electronic device and storage medium
CN111400229A (en) Baud rate self-adaptive serial communication system and serial communication method
CN111352887B (en) PCI bus-to-configurable frame length serial bus adaptation and transmission method
US20070061491A1 (en) Communication method and apparatus
CN101697249A (en) Method and device for decoding infrared remote control signals
CN108614795B (en) Digital implementation method for USB data transmission
US8452883B2 (en) Method for data transmission
CN110058706B (en) PS2 controller suitable for long-distance transmission and implementation method
CN111026691B (en) OWI communication equipment based on APB bus
CN109144937B (en) High-reliability transmission method for multi-path serial port
CN114863666B (en) Infrared remote control carrier-free coding method
CN216286203U (en) Stage control system's DMX512 conversion access device and stage control system
JP3735099B2 (en) Peripheral device status check method and apparatus
WO2022082950A1 (en) Method for improving device serial communication efficiency and terminal
US6944560B2 (en) Method for eliminating noise signals in radio signal receiving devices
CN213934827U (en) One-way KVM controller
CN102117254A (en) Embedded-system-based asynchronous data receiving method
KR200191626Y1 (en) Usb port interpreter
CN206672083U (en) A kind of computer interface diagnostic device

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
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20201016

WD01 Invention patent application deemed withdrawn after publication