let's make
share what you make

- Featured:
- Intel IoT
- Laser Cutting
- Life Hacks
- Jewelry

# FTDI in C

by Ladvien
Download
Share
Favorite I Made it! Collection
Show All Items

### Setting Up the GCC Compiler

I setup a C environment as basic I could. There may be easier ways to go about this, but I wanted to use GCC to compile.

To setup the environment:

1. I downloaded and setup MinGW32.
2. I then downloaded FTD2XX libraries. This included the ftd2xx.h file and ftd2xx.lib.
3. I then stole the test code from Hack-a-Day's article on bitbanging with the FTDI.
4. I modified the code as they suggested by including, in this order, the Windows compatibility files:

    #include <stdio.h>
    #include <stdarg.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <windef.h>
    #include <winnt.h>
    #include <winbase.h>
    #include <string.h>
    #include <math.h>
    #include <stdbool.h>
    #include <stdint.h>
    #include "ftd2xx.h"
    #include <sys/time.h>

Code Link

I used this line to build it:

    $ gcc -o main main.c -L./ -lftd2xx

You must have both the ftd2xx.h and ftd2xx.lib in the same directory as you attempt to build.

As for editing, I've really grown to love Sublime Text 2.

If you have issues, make sure directory containing your files is in your PATH environment variable (I go over how to add the directory to your environment variables in this post).

## Step 1: D2XX

D2XX -- FTDI Support

The FTDI chips are highly controversial chips in the embedded world. I will not begin the debate on their efficacy. I chose this particular serializer since I felt most roboticist would have at least one, making software released using the chips reach a greater range of people on the spectrum of hobbyist to professional.

There are two basic interfaces for the FTDI chips:

1. Virtual COM port.
2. FTD2XX.DLL

I will be using the DLL. This is what the "-L./ -lftd2xx" part of our compile command is referring. It is including the ftd2xx library found in working directory.

The D2XX library is pretty nifty. It provides a collections of C++ functions to interact with the FTDI chip, and thereby, anything speaking UART. A full list of the commands and C code examples may be found in the,

- D2XX Programmers Guide

One last caveat regarding the reason I selected using the D2XX libraries instead of using the chip as a virtual COM port. I wanted as much control over the metal of the chip is possible. Originally, I had set out to write a downloader that'd use the already existing Sparkfun FTDI breakout, meant to program the Arduino Pro Mini and LilyPad, as no-need-to-modify programmer for my LPC1114 board. To accomplish this, I needed bit level control over all of the pins of the FTDI chip, which the D2XX has, but the COM port does not.

« Previous Next » View All Steps Download

​

"I Made It" comments require images. Uncheck for normal comment.

We have a be nice comment policy.
Please be positive and constructive.

# Welcome to DIY heaven.

The best technology projects at your fingertips

I'm in!

Already a member? Login »