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

7 Ekim 2010 Perşembe

PC – FPGA Communication with RS232 – 2

There is a need for software program in addition to the logic implemented in fpga. There are two libraries that can be used to control ftdi chips: D2XX library and libftdi library. The first is official one, it has good documentation but it is no open-source. The latter one is open-source but it has poor documentation. I couldn't install the D2XX library in Ubuntu. However libftdi is listed in repositories, so installation is very easy with ant package manages (aptitude, synaptic etc...). Maybe the only website about libftdi is its documentation web site http://www.intra2net.com/en/developer/libftdi/documentation/index.html. Also there are a few samples in /usr/share/doc/libftdi-dev/examples folder. Among these examples, simple.c and serial_read.c helped me a lot.


Since the software is a trial only, I didn't try to write a meaningful thing. Software first reads data entered from keyboard and send to fpga then waits data from fpga in a loop. When data is received, it echoes data to screen.


Software can be divided into 3 parts: initialization, write and read. Since I am writing about software, all directions are named with respect to software i.e: write is write to fpga.


I took the initialization part from sample.c example. The communication speed, and data format is defined here. Since the fpga logic operates at 19200 baud with 1+8+1 bit data, software is adjusted with the same settings.


Write part is simple. Fpga is always ready for a received data to fpga. Only thing to do is call ftdi_write_data function.

Reading is the hardest part. It requires some knowledge about ftdi chips and software. There is only one line of explanation in documentation. serial_read.c example helped me a lot. Read function doesn't wait for data and returns 0 if no data is available to read. In fact, read function returns amount of read bytes. Therefore I called this function in a while loop until its output is >0.

One thing I noticed during testing is, the chip has a buffer in it. If more than 1 byte of data is send, the unread bytes are stored in chip and next time a data is read from the computer, these stored data are send. I noticed this when the send button didn't have a debounce filter.

I will try to do the same thing with VCP (Virtual COM Port) drivers at the next time.


Program codes can be downloaded from here.

Hiç yorum yok:

Yorum Gönder