The original blog is in Turkish and in www.dincay.blogspot.com. This is the English translation of it.

6 Ekim 2010 Çarşamba

PC – FPGA Communication with RS232 – 1


I managed to transfer data between fpga and PC in both directions with rs232 protocol.

I wrote a software for this application. It asks a number from the user and send it to fpga. Fpga displays this number in 3rd and 4th digits of its 7 segment display. After that, software waits for a data from fpga. In order to send data from fpga, button 1 should be pressed. When the button is pressed the number coded with the switches is send to PC. The good point abut this system is it uses USB port other than old rs232 port. Ftdi chip converts the usb data to appropriate rs232 data. There is no need a separate program to control the ftdi chip. There is a library for it. By calling appropriate functions in a c program, I can control ftdi chip as I want. This gives a great flexibility to develop an application. I had made a game by using ftdi library before. It can be reached from that link.

The verilog code consists of 3 main parts: Baud generator, transmitter and receiver. I used baud rate of 19200. Since there is no separate clock line in rs232, baud generator creates 19200x16 Hz pulses to precisely adjust the sampling point. Transmitter and receiver counts the pulses. Each bit lasts 16 pulses. So transmitter advances it output in each 16 pulses after start signal is received. Receiver counts to 8 when detects a data is started to send to sample the data in middle of bit. I copy the algorithm from the book but the coding is mine.

This diagram shows the main blocks and their connections inside the fpga.

There are RS ffs after transmitter and receiver block. Most of the time rs232 module will be a peripheral for another module. Therefore it requires some flags for easy operation. Two control signals newdata and busy are generated inside the rs232 module with these 2 RS ffs.

I will explain the software in my next entry.

Program codes can be downloaded from here.

Hiç yorum yok:

Yorum Gönder