Sunday 2 February 2014

HELP FTDI USB module

I have just bought an FTDI USB module. And searched the web for information about wiring it and coding for it. This module is a UART converting USB serial data to "RS232" serial interface data. It is not strictly RS232 as the signals are not all there and the interface is 5V versus the RS232 spec of 12V signals. But is does provide a valid USB interface with vendor & product IDs and unique serial number.

And what confusion there is on blogs about the operation and use!

So I decided to look into the chip used and the signals to/from the module. And here are my findings:

Screen Shot 2014 02 02 at 09 36 13

As you can see the module has a mini-USB plug and six pin connections. These are

Arduino		FTDI

Reset?          DTR output, LOW when FT232 ready (Data Terminal Ready)
TX              RXI Arduino data out
RX              TXO Arduino data in
GND             CTS input, LOW when FT232 can send data (TXO)
GND	        GND


The power to the module is provided BY THE USB INPUT (not the 3V3 pin!). The 3V3 pin is an OUTPUT from the FTDI chip able to provide 50mA at 3V3 from the USB 5V supply.

The DTR signal is "Data Terminal Ready" and is an output LOW active signal showing when the device is ready to accept signals. It has been suggested that this could be connected to the Arduino RESET line - certainly it must not be connected directly or the Arduino will be held in reset permanently - but it could be pulled positive by a 10K resistor and connected via a 10nF . This would have the effect of sending a reset pulse to the Arduino when DTR goes LOW. I can't see the value in this but... probably best to leave DTR unconnected.

The CTS signal is an active LOW input. it tells the FTDI interface when the Arduino is ready to accept data from the TXO pin. For all intents and purposes this can be connected to GND as you can assume the Arduino is always ready to accept data. At least as much as will fill its incoming buffer... but you could connect this an Arduino pin and pull it LOW when you are ready to accept data.

The RXI signal goes to the Arduino TX pin (see below for pins and software code), and the TXO goes to the Arduino RX pin.

Each FTDi module has a unique serial number. Mine is reported by my Mac computer as:

FT232R USB UART
Product ID 0x6001
Vendor ID 0x0403 (FTDI Ltd)
Serial # A702LESX


The Mac will create a device for I/O called
/dev/tty.usbserial-A702LESX
when the USB is connected. This is the port to use for data I/O, for example using a terminal program such as CoolTerm.

Screen Shot 2014 02 02 at 10 08 03

There is a documentation error on the schematic from the supplier, the default operation is 5V and there is a tiny connection between the supply pad and the 5V pad on the back of the module. However the schematic says 3V3 operation... which is incorrect.

Code

TX and RX should NOT be pins 0 & 1 of the Arduino as these are tied to the onboard USB interface. Use the library
#include "SoftwareSerial"
and create a serial object to talk to the FTDI module. For example:

#define RX 10
#define TX 11

SoftwareSerial usb(RX, TX);

void setup()
{

  usb.begin(9600); // sets FTDI interface to 9600 baud

}


OK that's it, now it should work just fine. Try it.

No comments: