CN111400229A - Baud rate self-adaptive serial communication system and serial communication method - Google Patents

Baud rate self-adaptive serial communication system and serial communication method Download PDF

Info

Publication number
CN111400229A
CN111400229A CN202010160457.4A CN202010160457A CN111400229A CN 111400229 A CN111400229 A CN 111400229A CN 202010160457 A CN202010160457 A CN 202010160457A CN 111400229 A CN111400229 A CN 111400229A
Authority
CN
China
Prior art keywords
serial port
usb
data
serial
baud rate
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
CN202010160457.4A
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.)
Nanjing Qinheng Microelectronics Co ltd
Original Assignee
Nanjing Qinheng Microelectronics Co ltd
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 Nanjing Qinheng Microelectronics Co ltd filed Critical Nanjing Qinheng Microelectronics Co ltd
Priority to CN202010160457.4A priority Critical patent/CN111400229A/en
Publication of CN111400229A publication Critical patent/CN111400229A/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
    • 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 baud rate self-adaptive serial communication system and a serial communication method. The USB-to-serial port device continuously samples the TXD pin of the serial port communication device, continuously uploads continuous sampling data to a USB upper computer, the USB upper computer analyzes the baud rate and even the frame format of serial port communication according to the continuous sampling data, and extracts effective serial port communication data according to the baud rate and the frame format; converting data to be transmitted into an encoded data stream which accords with the baud rate and the frame format and transmitting the encoded data stream to USB serial-to-serial equipment; the USB serial port conversion equipment converts the coded data stream into a level information stream and sends the level information stream to the serial port communication equipment. The invention fully utilizes the resource advantages of high operation speed and large cache of the upper computer in the system, has low requirement on the USB-to-serial port chip, can realize the self-adaptation of the serial port frame format and the baud rate, and can not increase the hardware cost.

Description

Baud rate self-adaptive serial communication system and serial communication method
Technical Field
The invention belongs to the serial communication technology, and particularly relates to a baud rate self-adaptive serial communication system and a serial communication method.
Background
Before two serial devices carry out serial communication, the two serial devices must be set to the same frame format and the same baud rate in advance to ensure the correctness of communication data. The frame format is level flow information of serial port communication, including 1 start bit, 6/7/8 data bits, 0/1 check bits and 1/1.5/2 stop bits, and the most common frame format is: 1 start bit, 8 data bits, 0 check bit, 1 stop bit. The baud rate is a transmission rate parameter of serial communication. With the popularization of the USB interface, the USB to serial port chip is more and more widely used. However, the structure of the existing USB serial-to-serial port chip is as shown in fig. 1, and is the same as that of a general serial port communication device, and before serial port data is received and sent, the frame format and baud rate of the serial port communication must be set to be the same as those of the other party to realize correct serial port communication, and thus, the serial port communication cannot be self-adaptive. Although some documents also propose a method capable of realizing baud rate self-adaptation, the USB to serial port chip needs to have very high requirements, for example, a very high clock master frequency and a very large storage RAM are needed, and extra hardware cost is inevitably increased. Especially for eight-bit MCU chips with low cost and limited resources, it is impossible to realize baud rate adaptation without increasing cost.
Disclosure of Invention
The purpose of the invention is as follows: the invention provides a baud rate self-adaptive serial communication system and a serial communication method, aiming at solving the problem that the baud rate self-adaptation of a serial port is difficult to realize on a low-cost USB-to-serial port chip with limited resources.
The technical scheme is as follows: a Baud rate self-adaptive serial port communication system is characterized by comprising serial port communication equipment, USB-to-serial port equipment and a USB upper computer, wherein the USB-to-serial port equipment comprises a USB-to-serial port chip, the USB-to-serial port chip comprises a core control module, a serial port RXD pin level sampling module, a USB data uploading module, a USB data downloading module and a serial port TXD pin level sending module, and the serial port RXD pin level sampling module, the USB data uploading module, the USB data downloading module and the serial port TXD pin level sending module are all connected with the core control module; the level sampling module of the RXD pin of the serial port is connected with the TXD pin of the serial port communication equipment; the level transmitting module of the serial TXD pin is connected with the RXD pin of the serial communication equipment; the USB data uploading module and the USB data downloading module are connected with a USB upper computer through USB interfaces; the serial port RXD pin level sampling module is used for continuously sampling a serial port RXD pin of the USB-to-serial port chip; the USB data uploading module is used for continuously uploading continuous sampling data; the USB data downloading module is used for acquiring an encoded data stream downloaded by a USB upper computer; the serial port TXD pin level transmitting module is used for converting the coded data stream into a level information stream and transmitting the level information stream to the serial port communication equipment; the USB upper computer comprises a memory, a processor and a USB driver which is stored on the memory and can run on the processor, and the processor executes the USB driver to realize that: receiving continuous sampling data uploaded by a USB interface continuously; analyzing the baud rate of serial port communication; extracting effective serial port communication data; and converting the sending data into an encoded data stream which accords with the baud rate and downloading the encoded data stream to the USB interface.
A USB-to-serial port chip in a Baud rate self-adaptive serial port communication system comprises a core control module, a serial port RXD pin level sampling module, a USB data uploading module, a USB data downloading module and a serial port TXD pin level sending module, wherein the serial port RXD pin level sampling module, the USB data uploading module, the USB data downloading module and the serial port TXD pin level sending module are all connected with the core control module; the serial port RXD pin level sampling module is used for continuously sampling a serial port RXD pin; the USB data uploading module is used for continuously uploading continuous sampling data; the USB data downloading module is used for acquiring an encoded data stream downloaded by a USB upper computer; and the serial port TXD pin level transmitting module is used for converting the coded data stream into a level information stream and transmitting the level information stream.
The system further comprises a sampled data coding module and a sent data decoding module, wherein the sampled data coding module is connected with the core control module and the level sampling module of the RXD pin of the serial port, and is used for coding continuous sampled data; the transmitting data decoding module is connected with the core control module and the serial port TXD pin level transmitting module, and is used for decoding the coded data stream transmitted by the USB data downloading module.
A USB upper computer in a baud rate self-adaptive serial port communication system comprises a memory, a processor and a USB driver which is stored on the memory and can run on the processor, wherein the processor executes the USB driver to realize the following steps: receiving USB data continuously; analyzing the baud rate of serial communication according to the USB data, and extracting effective serial communication data; and converting the sending data into an encoded data stream according with the baud rate, and downloading the encoded data stream to the USB interface.
A serial port communication method of USB-to-serial port equipment comprises the following steps:
continuously sampling level information of a serial port RXD pin of the USB-to-serial port chip, wherein the sampling frequency is at least 4 times of the maximum baud rate supported by the USB-to-serial port chip;
continuously uploading continuous sampling data to a USB upper computer;
receiving a coded data stream of sending data sent by a USB upper computer;
and converting the coded data stream into a level information stream and sending the level information stream to the serial port communication equipment.
A serial port communication method of a USB upper computer comprises the following steps:
continuously receiving continuous sampling data through a USB interface, acquiring the baud rate of serial port communication according to the continuous sampling data, and extracting effective serial port communication data according to the baud rate of the serial port communication and the frame format of the serial port communication;
and acquiring data to be transmitted, converting the data to be transmitted into an encoded data stream according to the baud rate of serial communication, the frame format of the serial communication and the sampling frequency, and downloading the encoded data stream through a USB interface.
Further, the method for acquiring the baud rate of serial port communication comprises the following steps:
calculating the time occupied by the minimum pulse of the level information corresponding to the continuous sampling data;
setting the time occupied by the minimum pulse as T, and then the calculated value of the baud rate is 1/T;
setting the fault tolerance error as X;
enumerating common values of serial port communication baud rates;
comparing the 1/T value with a common value, and if the common value exists, enabling the common value to be between (1-X)/T and (1+ X)/T, determining the actual baud rate of serial port communication to be the common value; if all common values are not between (1-X)/T and (1+ X)/T, the actual baud rate of serial port communication is 1/T, which is a non-standard baud rate.
Further, the frame format of the serial communication is a fixed format or obtained by analyzing the baud rate and continuous sampling data of the serial communication, and the analyzing method comprises the following steps:
the default frame format is 1 start bit, 8 data bits, 0 check bit and 1 stop bit;
matching with a default frame format according to the characteristics of a serial port frame through continuous sampling data and the baud rate of serial port communication, wherein if the matching is successful, the default frame format is the frame format of the serial port communication; if the matching is unsuccessful, the default frame format is changed into other common frame formats for re-matching until a matched frame format is found, namely the frame format of the serial port communication.
A baud rate self-adaptive serial port communication method comprises the following steps:
the USB serial-to-serial port device continuously samples the level information of a TXD pin of the serial port communication device, and the sampling frequency is at least 4 times of the maximum baud rate supported by the USB serial-to-serial port chip;
the USB-to-serial port device continuously uploads continuous sampling data to a USB upper computer;
the USB upper computer receives continuous sampling data continuously, calculates the time occupied by the corresponding minimum pulse of the level information according to the continuous sampling data, obtains the baud rate of serial communication according to the time occupied by the minimum pulse, and extracts effective serial communication data according to the baud rate of the serial communication and the frame format of the serial communication;
the USB upper computer acquires data to be transmitted, performs bit encoding on the data to be transmitted according to the baud rate of serial port communication, the frame format of the serial port communication and the sampling frequency, and transmits encoded data stream after the bit encoding to USB serial-to-serial equipment;
the USB serial-to-serial port device receives the coded data stream downloaded by the USB upper computer, converts the coded data stream into a level information stream and sends the level information stream to the serial port communication device, and sends a high level when the coded data stream is not received by default.
Further, the frame format of the serial communication is a fixed format or is obtained by analyzing the baud rate and continuous sampling data of the serial communication.
Has the advantages that: compared with the prior art, the Baud rate of serial communication equipment does not need to be set in advance, the Baud rate currently used by a sender can be automatically analyzed in real time according to a data stream sent by the sender, effective serial communication data can be analyzed, and data to be sent are converted into the same Baud rate to be sent, so that the Baud rate self-adaption of serial communication is realized, double self-adaption of data receiving and data sending is realized, and correct serial communication is realized. Because the USB-to-serial port chip only performs level sampling and data coding uploading on the RXD pin of the serial port, the USB upper computer with larger storage and higher speed in the system performs analysis of the frame format and the baud rate and analysis processing of the serial port data, so that the USB-to-serial port chip does not need high clock master frequency and a large storage RAM, and extra hardware cost is not increased by the method. The invention fully utilizes the resource advantages of high operation speed and large cache of the upper computer in the system, and can realize the function of USB-to-serial port on an 8-bit MCU chip with common resources, thereby achieving the effects of convenient use, simple operation, low cost, good serial port signal compatibility and the like.
Drawings
FIG. 1 is a block diagram of a conventional USB-to-serial chip;
FIG. 2 is a system block diagram of a baud rate adaptive serial communication system of the present invention;
FIG. 3 is a schematic structural diagram of a USB-to-serial port chip according to the present invention;
FIG. 4 is a schematic diagram showing sampling of a serial RXD pin of a USB-to-serial chip;
FIG. 5 is a schematic diagram of the principle of calculating a serial port communication baud rate;
FIG. 6 is a flow chart of the USB to serial port chip according to the present invention;
FIG. 7 is a flowchart illustrating the operation of the USB driver software according to the present invention.
Detailed Description
The invention is further explained below with reference to the figures and the specific embodiments.
As shown in fig. 2, the baud rate adaptive serial communication system includes a serial communication device, a USB host computer, and USB driver software installed on the USB host computer.
As shown in fig. 2 and 3, the USB to serial device includes a USB to serial chip, the USB to serial chip includes a core control module, a serial RXD pin level sampling module, a USB data uploading module, a USB data downloading module, a serial TXD pin level transmitting module, a sampled data encoding module, and a transmitted data decoding module, and the serial RXD pin level sampling module, the USB data uploading module, the USB data downloading module, and the serial TXD pin level transmitting module are all connected to the core control module; the level sampling module of the RXD pin of the serial port is connected with the TXD pin of the serial port communication equipment; the level transmitting module of the serial TXD pin is connected with the RXD pin of the serial communication equipment; the USB data uploading module and the USB data downloading module are connected with the USB upper computer through USB interfaces. The serial port RXD pin level sampling module is used for continuously sampling a serial port RXD pin; the USB data uploading module is used for continuously uploading continuous sampling data; the USB data downloading module is used for acquiring an encoded data stream downloaded by a USB upper computer; the serial port TXD pin level transmitting module is used for converting the coded data stream into a level information stream and transmitting the level information stream; the sampling data coding module is connected with the core control module and the level sampling module of the RXD pin of the serial port, and is used for coding the sampling data into bytes; the transmitting data decoding module is connected with the core control module and the serial port TXD pin level transmitting module, and is used for decoding the coded data stream transmitted by the USB upper computer.
The USB host computer is provided with USB driving software and upper-layer serial port software, the USB driving software analyzes the frame format and the baud rate of serial port communication by using continuous sampling data continuously uploaded by a USB-to-serial port device, and the frame format can be fixed without analysis or can be obtained by analysis in practice, and the method obtained by analysis is described in the embodiment; acquiring effective serial port communication data and sending the effective serial port communication data to upper-layer serial port software; and acquiring data to be sent from upper-layer serial port software, converting the data to be sent into an encoded data stream conforming to the frame format and the baud rate, and downloading the encoded data stream to the USB-to-serial port device.
The baud rate self-adaptive serial port communication system comprises two working modes, and the working mode can be used for designating the baud rate besides the baud rate self-adaptive working mode. The present embodiment only details the details of the baud rate adaptive operation mode.
Fig. 6 and 7 are main work flows of the USB to serial device and the USB driver software, respectively, where events such as level information sampling, USB data uploading, USB data downloading, level information sending, and the like are all processed in an interrupt manner, so that parallelism and real-time performance of the events are guaranteed. The receiving, storing and sending of the related data are processed in a DMA mode, so that the occupation of system resources is reduced, and the processing speed is improved. I.e. the control packet needs to be interrupted and the pure data packet does not need to be interrupted. The USB is automatically downloaded to the buffer area by hardware and then is continuously sent to TXD for output by direct memory access DMA, the received sampling data is also processed by the hardware until the DMA is stored in the buffer area after the DMA is full of 64 bytes, the interruption is only carried out once, DMA and automatic functions are not needed, and the high-speed sampling is difficult to realize. Namely: the hardware has RXD continuous sampling, sequential 8-bit combination coding, DMA automatic storage to the buffer, uploading and downloading to the buffer, DMA automatically taking out data from the buffer, sequentially transmitting 8 bits to TXD, and defaulting TXD to output high level when there is no data.
The specific method of the Baud rate self-adaptive serial port communication comprises the following contents:
1. the USB-to-serial port device continuously samples level information of an RXD pin of a serial port, and the sampling frequency is at least 4 times of the maximum baud rate supported by a USB-to-serial port chip;
in order to facilitate subsequent USB transmission, consecutive sample data is encoded into a byte form, eight sample data are encoded into one byte, and then each 64 bytes are combined into one data packet for storage, but the encoding method and the data packet combination method are not limited.
The level information of the serial port RXD pin takes a frame as a unit, and each frame comprises 1 start bit, 6 or 7 or 8 data bits, 0 or 1 check bit and 1 or 1.5 or 2 stop bits. The time occupied by each bit is determined by the baud rate, and if the maximum baud rate supported by the USB-to-serial port chip is Bmax, the time occupied by each bit in serial communication at the maximum baud rate is 1/Bmax. The USB serial-to-serial port chip at least needs to perform continuous sampling at a time interval of 1/(4 × Bmax), where the high-level sampling data is "1" and the low-level sampling data is "0". The smaller the time interval between successive samples, the more accurate, e.g., 1/(8 × Bmax) or 1/(16 × Bmax). The following is an example in which the sampling frequency F is 3 MHz.
The USB-to-serial port chip continuously samples level information of an RXD pin of the serial port according to the sampling frequency of 3MHz, and continuously encodes the sampled level information, and encodes the level information into 1 byte after sampling for 8 times.
Fig. 4 is a schematic diagram showing that the level information is randomly sampled 24 times. A0-a7, B0-B7, C0-C7 are 24 sampling points, and a0 (high level 1), a1 (low level 0), a2 (low level 0), A3 (low level 0), a4 (low level 0), a5 (high level 1), A6 (high level 1), and a7 (high level 1)8 sampling points are encoded into binary data 10000111, corresponding to 0x87, which is hexadecimal data. B0 (high 1), B1 (high 1), B2 (high 1), B3 (high 1), B4 (high 1), B5 (low 0), B6 (low 0), and B7 (low 0)8 samples are encoded into binary data 11111000, corresponding to hexadecimal data 0xF 8. C0 (low 0), C1 (high 1), C2 (high 1), C3 (high 1), C4 (high 1), C5 (low 0), C6 (low 0), and C7 (low 0)8 samples are encoded into binary data 01111000, corresponding to hexadecimal data 0x 78.
2. The USB-to-serial port device is connected with a USB upper computer through a USB interface and is identified as a self-defined USB device on the USB upper computer. And the USB host computer runs USB driving software, and the USB driving software can continuously send the IN token to acquire the uploading data of the IN endpoint of the USB-to-serial device. The USB-to-serial device circularly packages the encoded data, for example, 1 package is formed by every 64 bytes, and then the data is uninterruptedly uploaded to the USB drive software through the USB interface. And the USB drive software stores the acquired coded data in sequence, and then starts the following decoding analysis. Sampling, encoding and uploading are continuous processes, and the existing USB-to-serial port chip needs to identify the idle state and the non-idle state of serial port communication and then carries out data transmission.
Because the USB-to-serial port chip only carries out continuous and uninterrupted level sampling and data coding uploading on the RXD pin of the serial port, whether serial port data transmission exists or not does not need to be identified, and the Baud rate does not need to be analyzed, the USB drive software of the USB upper computer with larger storage and higher speed per se carries out analysis of the frame format and the Baud rate and analysis processing of the serial port data, so that the USB-to-serial port chip does not need high clock master frequency and large storage RAM, and extra hardware cost is not increased.
3. The USB upper computer receives data packets of continuous sampling data uploaded by the USB-to-serial port device continuously, decodes the data packets into continuous sampling data, and analyzes the baud rate and the frame format according to the continuous sampling data; and obtaining effective serial communication data from the continuous sampling data according to the baud rate and the frame format, and submitting the effective serial communication data to upper-layer serial software.
(1) The baud rate was analyzed:
the 1 byte hexadecimal coded data contains 8 data bits, each bit of 0 represents the low level of 1/F time, and each bit of 1 represents the high level of 1/F time. As shown in fig. 5, the level information corresponding to a segment of continuous sampled data includes 5 bytes of encoded data 0XF0, 0XF0, 0x00, 0XF0, and 0XF0, and the corresponding binary data are, in order: 11110000, 00000000, 11110000, and decoded to restore to continuous binary sample data "1111000011110000000000001111000011110000", the level information corresponding to the continuous sample data is shown in fig. 5. From the concatenated continuous stream of level information, the low-level pulse or the high-level pulse with the smallest time is found. I.e. the minimum number of consecutive 0's or consecutive 1's from among consecutive binary sample data. The number of the minimum consecutive 0 s or consecutive 1 s found from the above-mentioned consecutive binary sample data is 4, i.e. the minimum pulse time of the current segment of the level stream information contains 4 sample periods. The same method continuously analyzes the continuously received continuous sampling data, and if there are pulses smaller than 4 sampling periods, the data are updated. Assuming that 4 is the minimum continuous number of 0 or 1 finally determined, the baud rate of serial communication is calculated as:
and if the time occupied by the minimum pulse is T and the calculated value of the serial port communication baud rate is B, the value of T is 4 (1/F), and B is 1/T750000 bps.
Considering sampling errors and serial port communication errors, calculating a calculated value of the baud rate by certain fault-tolerant error (for example, 5% and setting as other numerical values according to requirements), comparing the value B with a common value, and if the common value exists, enabling the common value to be between 0.95B and 1.05B, determining the actual baud rate of the serial port communication to be the common value; if all the common values are not between 0.95B and 1.05B, which indicates that the difference between all the common baud values and the calculated values is relatively large, the baud rate may be a non-standard baud rate, and the actual baud rate of serial communication is 1/T. Common baud values are 1200bps, 2400bps, 4800bps, 9600bps, 19200bps, 115200bps, 230400bps, 460800bps, 921600bps, and so on. Because the B obtained by the calculation is 750000bps, and no relatively close common baud value exists, the baud rate of the serial port communication is the non-standard baud rate of 750000 bps. Assuming that the calculated baud rate B is 2345, which is relatively close to 2400, it may be determined that the current actual baud rate is 2400 bps; assuming that the currently calculated baud rate B is 9357, which is relatively close to 9600, the current actual baud rate can be determined to be 9600 bps.
(2) Analyzing the frame format:
each frame of serial port communication comprises 1 start bit, 6 or 7 or 8 data bits, 0 or 1 check bit and 1 or 1.5 or 2 stop bits, and the time width occupied by each bit is 1/B, so that the time width occupied by each frame is as follows: 8. 8.5, 9, 9.5, 10, 10.5, 11, 11.5 or 12 1/B. Because the start bit is fixed to be low level and the stop bit is fixed to be high level, the minimum pulse width can be obtained according to continuous sampling data and the obtained baud rate, 1 and 0 sequences corresponding to the real waveform of the serial port frame are restored, and then the start and the end of each frame are analyzed from the sequences according to the characteristics of the frames, so that the digit of the current frame is determined. After the time width of each bit and the number of the frame bits are determined, the number of data bits (6 or 7 or 8), the number of check bits (0 or 1) and the number of stop bits (1 or 1.5 or 2) of the current frame are analyzed.
The most common serial communication frame format is: 1 start bit, 8 data bits, 0 check bit and 1 stop bit, so that the default frame format is analyzed for the current communication frame format, and the matching probability is higher. Because all received successive sample data has been stored in advance, different analyses can be repeated. If the current default frame format does not match, another new frame format is assumed to be re-matched until a matching frame format is found. If the frame format of the serial port communication is a known fixed format, the frame format does not need to be analyzed.
In the traditional scheme, the MCU analyzes the baud rate or the frame format to realize self-adaptation, the MCU main frequency of the USB-to-serial port chip is usually from several MHz to dozens of MHz, the RAM storage space is usually hundreds of bytes or Kbytes, the analysis capability is severely limited, or the hardware cost needs to be greatly improved, thereby limiting the commercial application. In the scheme of the invention, the CPU main frequency of the computer at the USB upper computer end is usually several GHz and multi-core, the storage space is measured by Mbytes and even Gbytes, and is several orders of magnitude higher than that at the USB-to-serial port chip end, so that the characteristics can be searched in a wider sampling data range at high speed and in parallel for intelligent analysis, and the accuracy and the response speed of baud rate self-adaptation are improved.
4. When the upper layer serial port software needs to send serial port data, the data to be sent is submitted to the USB driving software, the USB driving software converts the data to be sent into a hexadecimal coding data stream which is provided with a start bit, a data bit, a check bit and a stop bit and is expanded according to a multiple of a sampling frequency and the baud rate according to a frame format and the baud rate separated in the previous receiving time, and then the hexadecimal coding data stream is downloaded to the USB serial port conversion device through the USB interface. After receiving the coded data stream, the USB serial-to-serial device decodes the coded data stream into a level information stream, and sends the level information stream to the serial communication device through the TXD pin. And according to the sampling frequency of the USB-to-serial port chip, sending a low level of 1/F time when receiving one bit 0 downloaded by the USB, sending a high level of 1/F time when receiving one bit 1 downloaded by the USB, and sending a continuous high level when not receiving the coded data stream downloaded by the USB upper computer by default. Therefore, the frame format and the baud rate during data transmission can be automatically adjusted according to the frame format and the baud rate analyzed during receiving, so that double self-adaptation of receiving and transmitting is realized, and the USB-to-serial port device can directly convert the frame format and the baud rate into a level information stream.

Claims (10)

1. A Baud rate self-adaptive serial port communication system is characterized by comprising serial port communication equipment, USB-to-serial port equipment and a USB upper computer, wherein the USB-to-serial port equipment comprises a USB-to-serial port chip, the USB-to-serial port chip comprises a core control module, a serial port RXD pin level sampling module, a USB data uploading module, a USB data downloading module and a serial port TXD pin level sending module, and the serial port RXD pin level sampling module, the USB data uploading module, the USB data downloading module and the serial port TXD pin level sending module are all connected with the core control module; the level sampling module of the RXD pin of the serial port is connected with the TXD pin of the serial port communication equipment; the level transmitting module of the serial TXD pin is connected with the RXD pin of the serial communication equipment; the USB data uploading module and the USB data downloading module are connected with a USB upper computer through USB interfaces; the serial port RXD pin level sampling module is used for continuously sampling a serial port RXD pin of the USB-to-serial port chip; the USB data uploading module is used for continuously uploading continuous sampling data; the USB data downloading module is used for acquiring an encoded data stream downloaded by a USB upper computer; the serial port TXD pin level transmitting module is used for converting the coded data stream into a level information stream and transmitting the level information stream to the serial port communication equipment; the USB upper computer comprises a memory, a processor and a USB driver which is stored on the memory and can run on the processor, and the processor executes the USB driver to realize that: receiving continuous sampling data uploaded by a USB interface continuously; analyzing the baud rate of serial port communication; extracting effective serial port communication data; and converting the sending data into an encoded data stream which accords with the baud rate and downloading the encoded data stream to the USB interface.
2. A USB-to-serial port chip in a Baud rate self-adaptive serial port communication system is characterized by comprising a core control module, a serial port RXD pin level sampling module, a USB data uploading module, a USB data downloading module and a serial port TXD pin level sending module, wherein the serial port RXD pin level sampling module, the USB data uploading module, the USB data downloading module and the serial port TXD pin level sending module are all connected with the core control module; the serial port RXD pin level sampling module is used for continuously sampling a serial port RXD pin; the USB data uploading module is used for continuously uploading continuous sampling data; the USB data downloading module is used for acquiring an encoded data stream downloaded by a USB upper computer; and the serial port TXD pin level transmitting module is used for converting the coded data stream into a level information stream and transmitting the level information stream.
3. The USB-to-serial port chip in the Baud rate adaptive serial port communication system according to claim 2, further comprising a sampled data encoding module and a transmitted data decoding module, wherein the sampled data encoding module is connected with the core control module and the serial port RXD pin level sampling module, and the sampled data encoding module is used for encoding continuous sampled data; the transmitting data decoding module is connected with the core control module and the serial port TXD pin level transmitting module, and is used for decoding the coded data stream transmitted by the USB data downloading module.
4. The USB upper computer in the baud rate self-adaptive serial port communication system is characterized by comprising a memory, a processor and a USB driver which is stored on the memory and can run on the processor, wherein the USB driver is implemented when the processor executes the USB driver: receiving USB data continuously; analyzing the baud rate of serial communication according to the USB data, and extracting effective serial communication data; and converting the sending data into an encoded data stream according with the baud rate, and downloading the encoded data stream to the USB interface.
5. A serial port communication method of USB-to-serial port equipment is characterized by comprising the following steps:
continuously sampling level information of a serial port RXD pin of the USB-to-serial port chip, wherein the sampling frequency is at least 4 times of the maximum baud rate supported by the USB-to-serial port chip;
continuously uploading continuous sampling data to a USB upper computer;
receiving a coded data stream of sending data sent by a USB upper computer;
and converting the coded data stream into a level information stream and sending the level information stream to the serial port communication equipment.
6. A serial port communication method of a USB upper computer is characterized by comprising the following steps:
continuously receiving continuous sampling data through a USB interface, acquiring the baud rate of serial port communication according to the continuous sampling data, and extracting effective serial port communication data according to the baud rate of the serial port communication and the frame format of the serial port communication;
and acquiring data to be transmitted, converting the data to be transmitted into an encoded data stream according to the baud rate of serial communication, the frame format of the serial communication and the sampling frequency, and downloading the encoded data stream through a USB interface.
7. The serial port communication method of the USB host computer according to claim 6, wherein the baud rate of the serial port communication is obtained by:
calculating the time occupied by the minimum pulse of the level information corresponding to the continuous sampling data;
setting the time occupied by the minimum pulse as T, and then the calculated value of the baud rate is 1/T;
setting the fault tolerance error as X;
enumerating common values of serial port communication baud rates;
comparing the 1/T value with a common value, and if the common value exists, enabling the common value to be between (1-X)/T and (1+ X)/T, determining the actual baud rate of serial port communication to be the common value; if all common values are not between (1-X)/T and (1+ X)/T, the actual baud rate of serial port communication is 1/T, which is a non-standard baud rate.
8. The serial port communication method of the USB host computer according to claim 6 or 7, wherein the frame format of the serial port communication is a fixed format or obtained by analyzing baud rate and continuous sampling data of the serial port communication, and the analyzing method includes:
the default frame format is 1 start bit, 8 data bits, 0 check bit and 1 stop bit;
matching with a default frame format according to the characteristics of a serial port frame through continuous sampling data and the baud rate of serial port communication, wherein if the matching is successful, the default frame format is the frame format of the serial port communication; if the matching is unsuccessful, the default frame format is changed into other common frame formats for re-matching until a matched frame format is found, namely the frame format of the serial port communication.
9. A baud rate self-adaptive serial port communication method is characterized by comprising the following steps:
the USB serial-to-serial port device continuously samples the level information of a TXD pin of the serial port communication device, and the sampling frequency is at least 4 times of the maximum baud rate supported by the USB serial-to-serial port chip;
the USB-to-serial port device continuously uploads continuous sampling data to a USB upper computer;
the USB upper computer receives continuous sampling data continuously, calculates the time occupied by the corresponding minimum pulse of the level information according to the continuous sampling data, obtains the baud rate of serial communication according to the time occupied by the minimum pulse, and extracts effective serial communication data according to the baud rate of the serial communication and the frame format of the serial communication;
the USB upper computer acquires data to be transmitted, performs bit encoding on the data to be transmitted according to the baud rate of serial port communication, the frame format of the serial port communication and the sampling frequency, and transmits encoded data stream after the bit encoding to USB serial-to-serial equipment;
the USB serial-to-serial port device receives the coded data stream downloaded by the USB upper computer, converts the coded data stream into a level information stream and sends the level information stream to the serial port communication device, and sends a high level when the coded data stream is not received by default.
10. The baud rate adaptive serial communication method of claim 9, wherein the frame format of the serial communication is a fixed format or is obtained by analyzing baud rate and continuous sampling data of the serial communication.
CN202010160457.4A 2020-03-10 2020-03-10 Baud rate self-adaptive serial communication system and serial communication method Pending CN111400229A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010160457.4A CN111400229A (en) 2020-03-10 2020-03-10 Baud rate self-adaptive serial communication system and serial communication method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010160457.4A CN111400229A (en) 2020-03-10 2020-03-10 Baud rate self-adaptive serial communication system and serial communication method

Publications (1)

Publication Number Publication Date
CN111400229A true CN111400229A (en) 2020-07-10

Family

ID=71434106

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010160457.4A Pending CN111400229A (en) 2020-03-10 2020-03-10 Baud rate self-adaptive serial communication system and serial communication method

Country Status (1)

Country Link
CN (1) CN111400229A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112821985A (en) * 2020-12-31 2021-05-18 珠海格力电器股份有限公司 Control method and control device of encoder, servo motor and encoder
CN112988650A (en) * 2021-05-12 2021-06-18 网络通信与安全紫金山实验室 Communication method, device, system and storage medium
CN114510446A (en) * 2022-01-05 2022-05-17 浙江科睿微电子技术有限公司 Serial port baud rate self-adaption method, device, equipment and medium
CN115718715A (en) * 2022-11-18 2023-02-28 深圳市精泰达科技有限公司 USB interface changes serial port card

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103001734A (en) * 2012-10-17 2013-03-27 海军工程大学 Method for automatically detecting asynchronous serial port communication protocol on basis of level sampling
CN107038135A (en) * 2017-03-24 2017-08-11 深圳市顺讯电子有限公司 A kind of serial port baud rate Adaptable System and method
CN109344022A (en) * 2018-07-22 2019-02-15 广州市星翼电子科技有限公司 The multi-functional downloading debugging apparatus of one kind and adjustment method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103001734A (en) * 2012-10-17 2013-03-27 海军工程大学 Method for automatically detecting asynchronous serial port communication protocol on basis of level sampling
CN107038135A (en) * 2017-03-24 2017-08-11 深圳市顺讯电子有限公司 A kind of serial port baud rate Adaptable System and method
CN109344022A (en) * 2018-07-22 2019-02-15 广州市星翼电子科技有限公司 The multi-functional downloading debugging apparatus of one kind and adjustment method

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112821985A (en) * 2020-12-31 2021-05-18 珠海格力电器股份有限公司 Control method and control device of encoder, servo motor and encoder
CN112988650A (en) * 2021-05-12 2021-06-18 网络通信与安全紫金山实验室 Communication method, device, system and storage medium
CN112988650B (en) * 2021-05-12 2021-08-03 网络通信与安全紫金山实验室 Communication method, device, system and storage medium
CN114510446A (en) * 2022-01-05 2022-05-17 浙江科睿微电子技术有限公司 Serial port baud rate self-adaption method, device, equipment and medium
CN115718715A (en) * 2022-11-18 2023-02-28 深圳市精泰达科技有限公司 USB interface changes serial port card

Similar Documents

Publication Publication Date Title
CN111400229A (en) Baud rate self-adaptive serial communication system and serial communication method
CN112330456A (en) Ultra-low-delay hardware accelerated market data stream analysis system
US10579581B2 (en) Multilane heterogeneous serial bus
US8583269B2 (en) Isochronous audio network software interface
JPH05122282A (en) Data transmission system
CN115866081A (en) Industrial Ethernet protocol conversion method based on SOC
CN110474692B (en) Optical communication device, optical communication system, data transmission method and storage medium
CN116708579A (en) Data access method, device, electronic equipment and computer readable storage medium
CN113676386B (en) FC-AE-1553 bus protocol message communication system
CN111367850B (en) Rapid communication method between FPGA and MCU
CN112131170A (en) Tightening machine visualization method and system based on RS485 serial port communication
CN114338270B (en) Data communication method, device, electronic equipment and storage medium
KR20240046830A (en) On-demand packetization for chip-to-chip interfaces
CN112147918B (en) Asynchronous data interaction method and system based on ARM + FPGA + DSP architecture
CN110120987B (en) WiFi connection method and device
CN112017049A (en) Security quotation forwarding system and method
CN109032664B (en) Method and system for tracking queue full state of micro-architecture level queue in real time
CN115150436B (en) System and method for realizing serial communication between Internet of things sensing module and MCU
CN114726893B (en) Internet of things application layer access method and system capable of supporting multiple underlying bearer protocols
CN114050890B (en) Multi-type information transmission device suitable for optical fiber network
CN109474707B (en) Two-layer protocol design and data transmission method and system based on serial port protocol
CN115695176A (en) Method for configuring physical interface chip and related device
CN115017066A (en) Multi-channel data recording system and method
CN1170231C (en) Gigabit firewall device
CN116668339A (en) Deep packet inspection system and application method thereof

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