FPGA-based UART interface module and design method
By designing the UART interface module on the FPGA and using the baud rate generator and receiving unit to realize automatic adjustment of the baud rate and data format, the problems of baud rate matching error and insufficient non-standard rate adaptability in the existing technology are solved. It improves the accuracy and automation of data transmission and is suitable for a variety of complex scenarios.
Patent Information
- Application Number
- CN202410834689.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-09-13
AI Technical Summary
A few existing UART interface chips and IP cores support dynamic adjustment of baud rate, and errors are prone to occur during the matching adjustment process, making it difficult to adapt to non-standard rate interfaces and interference scenarios, affecting the accuracy of data transmission.
Design an FPGA-based UART interface module that uses edge detection and low-level time calculation through the baud rate generator to automatically configure and calibrate the baud rate of the serial port, and ensure the correctness of the data format and rate through the receiving unit and sending unit. , using a combination of table lookup method and calculation method to adapt to standard and non-standard baud rates and realize automatic adjustment of data format.
It realizes automatic configuration calibration of baud rate and automatic adjustment of data format. It does not need to establish the baud rate in advance, adapts to baud rate changes caused by various factors, covers non-standard rate interfaces, improves the degree of automation and practicality, and is suitable for Scenarios such as automotive electronics, industrial sites, and medical equipment.
Smart Images

Figure CN118642998A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of UART communication, in particular to a UART interface module based on FPGA and a design method thereof. Background Art
[0002] UART is a serial communication protocol, commonly used to transmit data between computers or microcontrollers and peripherals, and is widely used in various fields and applications. It has the advantages of strong versatility, flexible implementation, reliability and low cost. It uses asynchronous transmission, and the receiving and sending do not share the clock signal. The two communicating parties transmit data synchronously at a pre-agreed baud rate.
[0003] FPGA is a reconfigurable programmable logic device, which is widely used in scenarios including but not limited to digital signal processing, communication protocols, communication systems, embedded systems and high-performance computing. It has the advantages of short development cycle, programmability, low latency and strong adaptability.
[0004] In order to ensure the accuracy of data transmission, the baud rate and data format of the receiving and sending must be consistent. Currently, few UART interface chips and IP cores on the market can support dynamic baud rate adjustment, but some devices currently have some non-standard rate interfaces, and errors are prone to occur during the matching adjustment process. Summary of the invention
[0005] In view of the needs and shortcomings of current technological development, the present invention provides a UART interface module based on FPGA and a design method, which realizes automatic configuration and calibration of baud rate and improves the versatility and practicality of UART.
[0006] In the first aspect, a UART interface module based on FPGA of the present invention adopts the following technical solutions to solve the above technical problems:
[0007] A UART interface module based on FPGA, comprising:
[0008] The baud rate generator is used to determine the baud rate value through edge detection and low-level time calculation, and compare it with the preset baud rate table to automatically configure the baud rate of the calibrated serial port; it is also used to generate a sampled signal by dividing the system clock after the baud rate generator calculates the baud rate, so as to receive the configuration code and store it in the shift register;
[0009] A receiving unit, used for accessing the shift register to convert serial data into parallel data;
[0010] The sending unit is used to control the data sending status timing according to the parameter information in the shift register after the parameter configuration is completed, to ensure that the data is sent in the correct format and rate, so as to convert the parallel data into serial form and send it out.
[0011] Optionally, the baud rate generator involved determines the baud rate value through edge detection and low level time calculation, and compares it with a preset baud rate table to automatically configure the baud rate of the calibration serial port. The specific operations are as follows:
[0012] First, the baud rate generator uses a two-stage D flip-flop to perform edge detection and confirm the characteristic value;
[0013] Subsequently, the baud rate generator uses the clock counter to calculate the low level time cnt, and calculates the corresponding baud rate value according to the given formula Baud_rate=1 / (10^-8*cnt / 9);
[0014] Then, the calculated baud rate value is compared with the preset baud rate table by combining the characteristic value method and the table lookup method, the closest baud rate value is found, and it is set as the baud rate of the serial port, completing the automatic configuration and calibration of the baud rate;
[0015] Finally, according to the received data format configuration code, it is written into the shift register to realize automatic adjustment of the data format.
[0016] Further optionally, in the case of a standard baud rate, the baud rate generator uses a table lookup method to quickly determine the baud rate value;
[0017] If the table lookup method fails to find a corresponding standard baud rate, the baud rate generator initiates a calculation process to determine the required nonstandard baud rate;
[0018] The baud rate generator temporarily stores the determined baud rate value or the calculated baud rate value in the shift register so as to be accessed and used by the parameter receiving unit and the data receiving unit.
[0019] Optionally, the receiving units involved include a parameter receiving unit and a data receiving unit, the parameter receiving unit has write permission to the shift register, and the data receiving unit has read permission to the shift register.
[0020] Further optionally, the parameter receiving unit and the data receiving unit involved are implemented by a finite state machine, the receiving controller uniformly controls the parameter receiving unit and the data receiving unit, and the priority of the parameter receiving unit is higher than that of the data receiving unit;
[0021] The parameter receiving unit needs to confirm that the communication baud rate is correct before it can work. When the parameter receiving unit receives the correct baud rate, it will perform continuous edge detection and use the falling edge to determine the position of the start bit;
[0022] When the falling edge appears and the configuration parameters are completed, the data receiving unit is entered; under the action of the receiving controller, the data receiving unit uses a counter to calculate the data bit length and the data bits that have been received to determine whether to enter the next state; during the data receiving process, if the state needs to be verified, it is verified through the error detection mechanism. If an error is detected, appropriate error correction measures are taken, or data retransmission is requested; after the data reception is completed, the data is stored and an identification of the receiving state is given.
[0023] In the second aspect, a UART interface design method based on FPGA of the present invention solves the above technical problems by adopting the following technical solutions:
[0024] A UART interface design method based on FPGA comprises the following steps:
[0025] The baud rate generator determines the baud rate value through edge detection and low-level time calculation, and compares it with the preset baud rate table to automatically configure and calibrate the baud rate of the serial port;
[0026] After the baud rate generator calculates the baud rate, it generates a sampled signal by dividing the system clock to receive the configuration code and store it in the shift register, which can be accessed by the receiving unit, which converts the serial data into parallel data;
[0027] After the parameter configuration is completed, the sending unit controls the data sending state timing according to the parameter information in the shift register to ensure that the data is sent in the correct format and rate, so as to convert the parallel data into serial form and send it out.
[0028] Optionally, the baud rate generator involved determines the baud rate value through edge detection and low level time calculation, and compares it with a preset baud rate table to automatically configure the baud rate of the calibration serial port. The specific operations are as follows:
[0029] First, the baud rate generator uses a two-stage D flip-flop to perform edge detection and confirm the characteristic value;
[0030] Subsequently, the baud rate generator uses the clock counter to calculate the low level time cnt, and calculates the corresponding baud rate value according to the given formula Baud_rate=1 / (10^-8*cnt / 9);
[0031] Then, the calculated baud rate value is compared with the preset baud rate table by combining the characteristic value method and the table lookup method, the closest baud rate value is found, and it is set as the baud rate of the serial port, completing the automatic configuration and calibration of the baud rate;
[0032] Finally, according to the received data format configuration code, it is written into the shift register to realize automatic adjustment of the data format.
[0033] Further optionally, in the case of a standard baud rate, a table lookup method is used to quickly determine the baud rate value;
[0034] If the table lookup method fails to find a corresponding standard baud rate, a calculation process is initiated to determine the required non-standard baud rate;
[0035] The determined baud rate value or the calculated baud rate value is temporarily stored in the shift register so as to be accessed and used by the parameter receiving unit and the data receiving unit.
[0036] Optionally, the receiving units involved include a parameter receiving unit and a data receiving unit, the parameter receiving unit has write permission to the shift register, and the data receiving unit has read permission to the shift register.
[0037] Further optionally, the parameter receiving unit and the data receiving unit involved are implemented by a finite state machine, the receiving controller uniformly controls the parameter receiving unit and the data receiving unit, and the priority of the parameter receiving unit is higher than that of the data receiving unit;
[0038] The parameter receiving unit needs to confirm that the communication baud rate is correct before it can work. When the parameter receiving unit receives the correct baud rate, it will perform continuous edge detection and use the falling edge to determine the position of the start bit;
[0039] When the falling edge appears and the configuration parameters are completed, the data receiving unit is entered; under the action of the receiving controller, the data receiving unit uses a counter to calculate the data bit length and the data bits that have been received to determine whether to enter the next state; during the data receiving process, if the state needs to be verified, it is verified through the error detection mechanism. If an error is detected, appropriate error correction measures are taken, or data retransmission is requested; after the data reception is completed, the data is stored and an identification of the receiving state is given.
[0040] The UART interface module and design method based on FPGA of the present invention have the following beneficial effects compared with the prior art:
[0041] The present invention can realize automatic configuration calibration of baud rate and automatic adjustment of data format without setting baud rate in advance, and can adapt to various scenarios where baud rate is different or interfered due to different factors;
[0042] In addition to standard baud rates, the present invention can also cover interfaces with other non-standard rates, and can cope with the increasingly new non-standard external devices; in addition to adaptive baud rates, it can also automatically match data formats, establish communication links, improve the degree of automation, and be more practical; it can be applied to various scenarios such as vehicle-mounted electronic equipment communications, industrial sites, and medical equipment and external interactions. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] AttachedFigure 1 It is a structural diagram of a UART interface module according to a first embodiment of the present invention;
[0044] Attached Figure 2 It is the UART byte format and receiving process in the embodiment of the present invention;
[0045] Attached Figure 3 It is a flow chart of the parameter receiving unit and the data receiving unit in the embodiment of the present invention implemented by a finite state machine. DETAILED DESCRIPTION
[0046] In order to make the technical solution, the technical problem solved and the technical effect of the present invention more clearly understood, the technical solution of the present invention is clearly and completely described below in conjunction with specific embodiments.
[0047] Embodiment 1:
[0048] Combined with Figure 1 , 2 3. This embodiment proposes a UART interface module based on FPGA, which includes:
[0049] The baud rate generator is used to determine the baud rate value through edge detection and low-level time calculation, and compare it with the preset baud rate table to automatically configure the baud rate of the calibrated serial port; it is also used to generate a sampled signal by dividing the system clock after the baud rate generator calculates the baud rate, so as to receive the configuration code and store it in the shift register;
[0050] A receiving unit, used for accessing the shift register to convert serial data into parallel data;
[0051] The sending unit is used to control the data sending status timing according to the parameter information in the shift register after the parameter configuration is completed, to ensure that the data is sent in the correct format and rate, so as to convert the parallel data into serial form and send it out.
[0052] In this embodiment, the baud rate generator involved determines the baud rate value through edge detection and low level time calculation, and compares it with the preset baud rate table to automatically configure the baud rate of the calibration serial port. The specific operations are as follows:
[0053] First, the baud rate generator uses a two-stage D flip-flop to perform edge detection and confirm the characteristic value;
[0054] Subsequently, the baud rate generator uses the clock counter to calculate the low level time cnt, and calculates the corresponding baud rate value according to the given formula Baud_rate=1 / (10^-8*cnt / 9);
[0055] Then, the calculated baud rate value is compared with the preset baud rate table by combining the characteristic value method and the table lookup method, the closest baud rate value is found, and it is set as the baud rate of the serial port, completing the automatic configuration and calibration of the baud rate;
[0056] Finally, according to the received data format configuration code, it is written into the shift register to realize automatic adjustment of the data format.
[0057] It should be added that: in the case of standard baud rates, the baud rate generator uses a table lookup method to quickly determine the baud rate value;
[0058] If the table lookup method fails to find a corresponding standard baud rate, the baud rate generator initiates a calculation process to determine the required nonstandard baud rate;
[0059] The baud rate generator temporarily stores the determined baud rate value or the calculated baud rate value in the shift register so that it can be accessed and used by the receiving unit.
[0060] In this embodiment, the receiving unit involved includes a parameter receiving unit and a data receiving unit. The parameter receiving unit has write permission to the shift register, and the data receiving unit has read permission to the shift register.
[0061] In this embodiment, combined with the attached Figure 3 , the parameter receiving unit and the data receiving unit involved are implemented by a finite state machine, the receiving controller uniformly controls the parameter receiving unit and the data receiving unit, and the priority of the parameter receiving unit is higher than that of the data receiving unit;
[0062] The parameter receiving unit needs to confirm that the communication baud rate is correct before it can work. When the parameter receiving unit receives the correct baud rate, it will perform continuous edge detection and use the falling edge to determine the position of the start bit;
[0063] When the falling edge appears and the configuration parameters are completed, the data receiving unit is entered; under the action of the receiving controller, the data receiving unit uses a counter to calculate the data bit length and the data bits that have been received to determine whether to enter the next state; during the data receiving process, if the state needs to be verified, it is verified through the error detection mechanism. If an error is detected, appropriate error correction measures are taken, or data retransmission is requested; after the data reception is completed, the data is stored and an identification of the receiving state is given.
[0064] Embodiment 2:
[0065] Reference Figure 1 , 2 3. This embodiment proposes a UART interface design method based on FPGA, which includes the following steps:
[0066] (I) The baud rate generator determines the baud rate value through edge detection and low-level time calculation, and compares it with the preset baud rate table to automatically configure the baud rate of the calibration serial port. The specific operations are as follows:
[0067] First, the baud rate generator uses a two-stage D flip-flop to perform edge detection and confirm the characteristic value;
[0068] Subsequently, the baud rate generator uses the clock counter to calculate the low level time cnt. Since this time includes a start bit and eight data bits, a low level needs to be obtained by dividing the low level time by nine. Therefore, according to the given formula Baud_rate=1 / (10^-8*cnt / 9), the corresponding baud rate value is calculated;
[0069] Then, the calculated baud rate value is compared with the preset baud rate table by combining the characteristic value method and the table lookup method, the closest baud rate value is found, and it is set as the baud rate of the serial port, completing the automatic configuration and calibration of the baud rate;
[0070] Finally, according to the received data format configuration code, it is written into the shift register to realize automatic adjustment of the data format.
[0071] It should be added that: in the case of standard baud rate, use the table lookup method to quickly determine the baud rate value;
[0072] If the table lookup method fails to find a corresponding standard baud rate, a calculation process is initiated to determine the required non-standard baud rate;
[0073] The determined baud rate value or the calculated baud rate value is temporarily stored in the shift register so as to be accessed and used by the receiving unit.
[0074] (II) After the baud rate generator calculates the baud rate, it generates a sampled signal by dividing the system clock to receive the configuration code (the first start bit serves as a clock buffer for one bit, and the configuration code is in the second to seventh bits) and stores it in the shift register, which can be accessed by the receiving unit, and the receiving unit converts the serial data into parallel data. It should be noted that receiving sampling at half the frequency division factor (in the middle of the baud rate signal cycle) makes the data more stable, reduces sampling errors, and improves sampling accuracy.
[0075] The receiving unit includes a parameter receiving unit and a data receiving unit. The parameter receiving unit has a write permission to the shift register, and the data receiving unit has a read permission to the shift register.
[0076] The parameter receiving unit and the data receiving unit are implemented by a finite state machine. The receiving controller uniformly controls the parameter receiving unit and the data receiving unit, and the priority of the parameter receiving unit is higher than that of the data receiving unit.
[0077] Combined with Figure 3 ,The parameter receiving unit needs to confirm that the communication baud rate is correct before it can work. When the parameter receiving unit receives the correct baud rate, it will perform continuous edge detection to determine the position of the start bit by the falling edge;
[0078] When the falling edge appears and the configuration parameters are completed, the data receiving unit is entered; under the action of the receiving controller, the data receiving unit uses a counter to calculate the data bit length and the data bits that have been received to determine whether to enter the next state; during the data receiving process, if the state needs to be verified, it is verified through the error detection mechanism. If an error is detected, appropriate error correction measures are taken, or data retransmission is requested; after the data reception is completed, the data is stored and an identification of the receiving state is given.
[0079] (iii) After the parameter configuration is completed, the sending unit controls the data sending status timing according to the parameter information in the shift register to ensure that the data is sent in the correct format and rate, so as to convert the parallel data into serial form and send it out.
[0080] During this process, the sending unit converts the baud rate into the sending state timing, controls the sending content according to the data length, stop bit, check bit, etc., and realizes the serial-to-parallel conversion of the data by controlling the shift.
[0081] Functional simulation of the implementation process of the interface module described in Example 1 and the design method described in Example 2 is performed through the Vivado simulation platform, including baud rate adaptation, parameter reception and system data transmission and reception, changing different baud rates and performing parameter reception and data transmission and reception, and verifying that the data is successfully received and the verification is correct.
[0082] We further used FPGA to conduct communication tests with the computer. We used the serial port debugging assistant to configure and send and receive data on the computer. We used different baud rates to conduct multiple tests. The results showed that FPGA could accurately obtain parameters and conduct stable communication at different baud rates.
[0083] Therefore, by adopting an FPGA-based UART interface module and design method of the present invention, there is no need to establish the baud rate in advance, the baud rate can be automatically detected and actively configured, and it can adapt to a variety of scenarios where the baud rate is different or interfered due to different factors; in addition to the standard baud rate, it can also cover other non-standard rate interfaces, and can cope with the increasingly new non-standard external devices; at the same time, in addition to the adaptive baud rate, it can also automatically match the data format, establish a communication link, improve the degree of automation, and be more practical; it can be applied to a variety of scenarios such as vehicle-mounted electronic equipment communication, industrial sites, and medical equipment and external interaction.
[0084] The above specific examples are used to explain the principles and implementation methods of the present invention in detail. These examples are only used to help understand the core technical content of the present invention. Based on the above specific embodiments of the present invention, any improvements and modifications made by technicians in this technical field without departing from the principles of the present invention should fall within the scope of patent protection of the present invention.
Claims
1. A UART interface module based on FPGA, It is characterized in that It includes: The baud rate generator is used to determine the baud rate value through edge detection and low-level time calculation, and compare it with the preset baud rate table to automatically configure the baud rate of the calibrated serial port; it is also used to generate a sampled signal by dividing the system clock after the baud rate generator calculates the baud rate, so as to receive the configuration code and store it in the shift register; A receiving unit, used for accessing the shift register to convert serial data into parallel data; The sending unit is used to control the data sending status timing according to the parameter information in the shift register after the parameter configuration is completed, to ensure that the data is sent in the correct format and rate, so as to convert the parallel data into serial form and send it out.
2. A UART interface module based on FPGA according to claim 1, It is characterized in that The baud rate generator determines the baud rate value through edge detection and low level time calculation, and compares it with the preset baud rate table to automatically configure the baud rate of the calibration serial port. The specific operation is as follows: First, the baud rate generator uses a two-stage D flip-flop to perform edge detection and confirm the characteristic value; Subsequently, the baud rate generator uses the clock counter to calculate the low level time cnt, and calculates the corresponding baud rate value according to the given formula Baud_rate=1 / (10^-8*cnt / 9); Then, the calculated baud rate value is compared with the preset baud rate table by combining the characteristic value method and the table lookup method, the closest baud rate value is found, and it is set as the baud rate of the serial port, completing the automatic configuration and calibration of the baud rate; Finally, according to the received data format configuration code, it is written into the shift register to realize automatic adjustment of the data format.
3. A UART interface module based on FPGA according to claim 2, It is characterized in that In the case of standard baud rates, the baud rate generator uses a table lookup to quickly determine the baud rate value; If the table lookup method fails to find a corresponding standard baud rate, the baud rate generator initiates a calculation process to determine the required nonstandard baud rate; The baud rate generator temporarily stores the determined baud rate value or the calculated baud rate value in the shift register so as to be accessed and used by the parameter receiving unit and the data receiving unit.
4. The FPGA-based UART interface module according to claim 1, It is characterized in that The receiving unit includes a parameter receiving unit and a data receiving unit. The parameter receiving unit has a write permission to the shift register, and the data receiving unit has a read permission to the shift register.
5. A UART interface module based on FPGA according to claim 4, It is characterized in that The parameter receiving unit and the data receiving unit are implemented by a finite state machine. The receiving controller uniformly controls the parameter receiving unit and the data receiving unit, and the priority of the parameter receiving unit is higher than that of the data receiving unit. The parameter receiving unit needs to confirm that the communication baud rate is correct before it can work. When the parameter receiving unit receives the correct baud rate, it will perform continuous edge detection and use the falling edge to determine the position of the start bit; When the falling edge appears and the configuration parameters are completed, the data receiving unit is entered; under the action of the receiving controller, the data receiving unit uses a counter to calculate the data bit length and the data bits that have been received to determine whether to enter the next state; During data reception, if verification status is required, verification is performed through the error detection mechanism. If an error is detected, appropriate error correction measures are taken or data retransmission is requested; After the data is received, the data is stored and an indication of the receiving status is given.
6. A UART interface design method based on FPGA, It is characterized in that The steps include: The baud rate generator determines the baud rate value through edge detection and low-level time calculation, and compares it with the preset baud rate table to automatically configure and calibrate the baud rate of the serial port; After the baud rate generator calculates the baud rate, it generates a sampled signal by dividing the system clock to receive the configuration code and store it in the shift register, which can be accessed by the receiving unit, which converts the serial data into parallel data; After the parameter configuration is completed, the sending unit controls the data sending state timing according to the parameter information in the shift register to ensure that the data is sent in the correct format and rate, so as to convert the parallel data into serial form and send it out.
7. A UART interface design method based on FPGA according to claim 6, It is characterized in that The baud rate generator determines the baud rate value through edge detection and low-level time calculation, and compares it with the preset baud rate table to automatically configure and calibrate the baud rate of the serial port. The specific operations are as follows: First, the baud rate generator uses a two-stage D flip-flop to perform edge detection and confirm the characteristic value; Subsequently, the baud rate generator uses the clock counter to calculate the low level time cnt, and calculates the corresponding baud rate value according to the given formula Baud_rate=1 / (10^-8*cnt / 9); Then, the calculated baud rate value is compared with the preset baud rate table by combining the characteristic value method and the table lookup method, the closest baud rate value is found, and it is set as the baud rate of the serial port, completing the automatic configuration and calibration of the baud rate; Finally, according to the received data format configuration code, it is written into the shift register to realize automatic adjustment of the data format.
8. A UART interface design method based on FPGA according to claim 7, It is characterized in that In the case of standard baud rates, a table lookup method is used to quickly determine the baud rate value; If the table lookup method fails to find a corresponding standard baud rate, a calculation process is initiated to determine the required non-standard baud rate; The determined baud rate value or the calculated baud rate value is temporarily stored in the shift register so as to be accessed and used by the parameter receiving unit and the data receiving unit.
9. A UART interface design method based on FPGA according to claim 6, It is characterized in that The receiving unit includes a parameter receiving unit and a data receiving unit. The parameter receiving unit has a write permission to the shift register, and the data receiving unit has a read permission to the shift register.
10. A UART interface design method based on FPGA according to claim 9, It is characterized in that The parameter receiving unit and the data receiving unit are implemented by a finite state machine. The receiving controller uniformly controls the parameter receiving unit and the data receiving unit, and the priority of the parameter receiving unit is higher than that of the data receiving unit. The parameter receiving unit needs to confirm that the communication baud rate is correct before it can work. When the parameter receiving unit receives the correct baud rate, it will perform continuous edge detection and use the falling edge to determine the position of the start bit; When the falling edge appears and the configuration parameters are completed, the data receiving unit is entered; under the action of the receiving controller, the data receiving unit uses a counter to calculate the data bit length and the data bits that have been received to determine whether to enter the next state; During data reception, if verification status is required, verification is performed through the error detection mechanism. If an error is detected, appropriate error correction measures are taken or data retransmission is requested; After the data is received, the data is stored and an indication of the receiving status is given.
Citation Information
Cited By
UART Baud rate adaptive circuit
CN121000342A
Implementation method and device for calibrating UART baud rate
CN121333515A
A method and apparatus for calibrating UART baud rate
CN121333515B
