Implementing serial communication between FPGA and PC

Publisher:WiseThinkerLatest update time:2012-03-31 Keywords:FPGA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Abstract: This paper mainly introduces the process of realizing serial communication with PC based on FPGA technology, gives the specific implementation method of each module, analyzes the implementation results, and verifies the correctness of serial communication.

Introduction
Serial communication is serial data transmission. Realizing serial communication between FPGA and PC is very important in practice, especially in debugging FPGA. The debugging process generally involves software programming simulation first, and then downloading the program to the chip to verify the correctness of the design. Currently, there is no better tool that can analyze the working status and data of FPGA in real time after downloading. Through serial communication, control commands can be sent to FPGA to let it perform corresponding operations, and the required data can be sent to PC through the serial port for corresponding data processing and analysis to determine whether FPGA works according to the design requirements. This greatly facilitates the debugging of FPGA. Without the need for other additional hardware such as DSP, the debugging of FPGA can be completed only through the serial port. This paper adopts QuartusⅡ3.0 development platform and Altera's FPGA to design and implement serial communication with PC.

Figure 1 Overall block diagram

Figure 2 Send and receive flow chart

Figure 3 State machine transformation

Overall design
The main design idea is: PC sends commands to the serial port, and FPGA performs corresponding operations by judging the received control word. The overall block diagram is shown in Figure 1.
The design includes three parts: 1. Send high and low levels to the I/O port to achieve the requirements of controlling external hardware. 2. Complete the changes in the internal logic of the chip. 3. Store the required data first (generally using internal or external FIFO), and then send the data to the PC through the serial port. The PC processes and analyzes the received data. The serial port uses the standard RS-232 protocol, and the main parameters are: baud rate 28800bit/s, 8 valid bits, no parity bit, and 1 stop bit.

Implementation of each module in FPGA
Frequency division module
In the design, the 3.6864MHz clock needs to be divided by 64 to 57600 baud as the clock reference for other modules. In the specific implementation, a 6-bit counter is used, and the overflow of the counter is used as the output of the clock to achieve integer division.
Transmitting and receiving module
This module is the core part of the entire design. The design process is shown in Figure 2.
In serial communication, whether sending or receiving, there must be a clock pulse signal to locate and synchronize the transmitted data. The clock frequency used in the design is twice the baud rate (57600 bit/s). Receiving process: The initial state is the waiting state. When 0 is detected, it enters the test state. If 0 is detected again in the test state, it enters the receiving data state. After receiving 8 bits, it determines whether there is a stop bit. If there is, the receiving process ends and re-enters the waiting state. Transmitting process: The initial state is the waiting state. When the signal to start sending is received, the sending process is entered. The start bit is sent first, and then the 8-bit bit number is sent. The width of each bit is 2 cycles. When a byte is sent, a stop bit is sent. The sending ends and returns to the waiting state.
Control module
The main functions are: judging the data received from the PC and performing corresponding state transitions according to the pre-designed logic. For example: presetting a state for the port; sending the flag to start sending and the data to be sent; sending the configuration signal to the DDS to control the reading and writing of the FIFO. The state machine design in the program is shown in Figure 3.
Issues to be noted in the design
The choice of baud rate is very important for serial communication. The baud rate should not be too large so that the data will be more stable. The determination and sending of the start bit in the entire sending and receiving process is the premise of data transmission. In order to avoid the generation of bit errors, a data latch should be added to the serial input and output ports in the FPGA design.

Figure 4 Sending and receiving process

Figure 5: Control word sending process

Figure 6 The process of reading data from FIFO


Simulation results
Basic sending and receiving
As shown in Figure 4, clk is the clock signal (57600 bit/s); start_xmit is the start sending flag; sin is the serial input; datain is the parallel output; read_bit is the receiving end flag; xmit_bit is the sending end flag; sout is the serial output; dataout is the parallel output; rcv_bit is the receiving bit register. The sending and receiving module mainly completes the conversion of the serial data received from the sin port into parallel data and sends it to dataout; the conversion of the parallel data datain into serial data and serially sends it through the sout port.
Receiving: Determine whether the received serial data sin is two consecutive 0s. If so, enter the receiving process; receive 1 bit of data every two clock cycles, and receive 01101010 in sequence. If the stop bit is received, it indicates that the receiving process is over, read_bit=1. According to the serial communication protocol, data is sent in the order of low bits first and high bits later, so the actual received data is 01010110. Send: The parallel data to be sent is 01010110. When start_xmit=1, the sending is valid and the sending process begins. First, two start bits 0 are sent to ensure that the length is two clock cycles. Then 01101010 are sent in sequence, 1 bit is sent every two clock cycles, and finally the stop bit is sent. The sending process ends and xmit_bit is 1.
Send control word
In Figure 5, clk is the clock signal; a is the hexadecimal control word sent by the PC, which is the parallel output dataout in Figure 4; ma1cnt, ma2cnt, and ma3cnt are three registers; clrr is the system clear signal; ddsclr is the DDS configuration signal; fifo_clk, fifo_rd, fifo_wr, and ram_rst are the clock, read, write, and clear signals of the FIFO; start_xmit is the sending start flag; and b is the data to be sent. When receiving a is 1, fifo_wr is set to 1; when a is 18, the value of ma1cnt is sent to b. Other operations are similar, mainly the setting of ports and the control of FIFO read and write status.
Read and write data from FIFO
In Figure 6, SER_CLOCK is the system clock 3.6864MHz, sa is the divided frequency 57600bit/s; SIN is the serial input; data is the data to be output; SOUT is the serial output; fifoclk, fifowr, and fiford are the read clock, write, and read enable of FIFO. Read process: When the read enable is valid, 6 read clocks are generated first, but no data is sent to SOUT, because the first 6 cycles of FIFO are not valid data. Then a read clock is generated, and the data of FIFO is sent to data, and sent out through SOUT according to the communication protocol. After the transmission is completed, another read clock is generated to read the data of FIFO and perform the next serial output.

Conclusion
With the continuous development and widespread application of programmable devices, the communication between FPGA and peripheral devices is increasing. The implementation of serial communication introduced in this article is replicable and can be used in other occasions by simply changing the system clock frequency and control module.

Keywords:FPGA Reference address:Implementing serial communication between FPGA and PC

Previous article:Design of a high-precision digital frequency meter for synchronous period measurement based on FPGA
Next article:An example of the CPU reading/writing memory process

Recommended ReadingLatest update time:2024-11-16 19:28

Using Freeze Technology to Implement Low-Power Design in FPGA
System designers are more concerned about power consumption now than ever before, due to tighter power constraints, specifications, and standards. For next generation designs, power budgets are usually stabilized or reduced, but more features and processing power are required. Often, despite the increasing demand fo
[Power Management]
Using Freeze Technology to Implement Low-Power Design in FPGA
Boréas BOS1921 meets the needs of ultra-thin PC touch panels for high-performance, low-cost tactile functions
Boréas BOS1921 meets the needs of ultra-thin PC touch panels for high-performance, low-cost tactile functions Piezo haptic drivers save BOM cost and hardware footprint while improving responsiveness and resolution Bromont, Quebec, Canada - September 29, 2022 - Boréas Technologies introduces the BOS1921, a micro pi
[Internet of Things]
Boréas BOS1921 meets the needs of ultra-thin PC touch panels for high-performance, low-cost tactile functions
Design of CNC system for remote temperature sensor based on FPGA
Abstract: This paper introduces the structure and working principle of the remote temperature sensor, designs the data acquisition and control system of the remote temperature sensor CNC system based on FPGA, uses the Cyclonell series FPGA of Altera to realize the control functions including data acquisition and dat
[Embedded]
Design of CNC system for remote temperature sensor based on FPGA
ARM is the way to go. What kind of PCs will we see besides Apple?
      Last winter, Apple's Apple Silicon showed us the unlimited potential of ARM chips. Compared with the x86 platform, ARM has obviously become the representative of advanced productivity, at least it is the future trend. Apple has a strong ability to integrate software and hardware, and it has been very smooth on t
[Mobile phone portable]
ARM is the way to go. What kind of PCs will we see besides Apple?
Development and application of programmable platforms for driver assistance systems
Safety is the most important concern for car consumers. Figure 1 shows the results of a study conducted by Visteon, which shows the requirements of customers for cars, with vehicle safety at the core. The focus on car safety is not only for the driver and passengers, but also for others on the road. Safety equip
[Automotive Electronics]
Development and application of programmable platforms for driver assistance systems
Samsung launches the world's first LPCAMM memory for PC: removable, size reduced by 60%
According to news on September 26, Samsung Electronics announced that it has developed its first 7.5Gbps (IT Home Note: 0.9375GB/s) low-power compressed add-on memory module (LPCAMM) form factor, which is expected to change the form factor of personal computers and laptops. DRAM (Dynamic Random Access Memory) market,
[Home Electronics]
Debug analysis: PC pointer analysis error based on kernel error information
When you write a driver, have you noticed that when we write the driver incorrectly and the kernel crashes, a lot of error messages will be printed. If we go back to our program and check the code line by line, it will be time-consuming and some logical errors will be difficult for us to see.
[Microcontroller]
Debug analysis: PC pointer analysis error based on kernel error information
Implementation of radar video accumulation algorithm on FPGA
1 Introduction Due to the complexity of the environment in which the radar is located, in addition to interference from ground objects, clouds, rain, and bird flocks, there may also be asynchronous interference from neighboring radars and radio stations. All interference enters the signal processor through t
[Embedded]
Implementation of radar video accumulation algorithm on FPGA
Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号