Programming AVRs with FTDI cable or FTDI Friend

AVRDude 6.3 seems to finally support bitbanging using FTDI cables and friends (Adafruit FTDI Friends, for example :). You can do this using the ftdi_syncbb programmer type. Here’s the relevant section of avrdude.conf:

# FTDI USB to serial cable TTL-232R-5V with a custom adapter for ICSP
# http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm
# http://www.ftdichip.com/Support/Documents/DataSheets/Cables/DS_TTL-232R_CABLES.pdf
# For ICSP pinout see for example http://www.atmel.com/images/doc2562.pdf
# (Figure 1. ISP6PIN header pinout and Table 1. Connections required for ISP ...)
# TTL-232R GND 1 Black  -> ICPS GND   (pin 6)
# TTL-232R CTS 2 Brown  -> ICPS MOSI  (pin 4)
# TTL-232R VCC 3 Red    -> ICPS VCC   (pin 2)
# TTL-232R TXD 4 Orange -> ICPS RESET (pin 5)
# TTL-232R RXD 5 Yellow -> ICPS SCK   (pin 3)
# TTL-232R RTS 6 Green  -> ICPS MISO  (pin 1)
# Except for VCC and GND, you can connect arbitual pairs as long as
# the following table is adjusted.
programmer
 id    = "ttl232r";
 desc  = "FTDI TTL232R-5V with ICSP adapter";
 type  = "ftdi_syncbb";
 connection_type = usb;
 miso  = 2; # rts
 sck   = 1; # rxd
 mosi  = 3; # cts
 reset = 0; # txd
;

It took a bit for me to piece together what these values mean since they seem to vary depending on the programmer type. First, the names on the left (miso, sck, mose, and reset) refer to the AVR pins to connect to. Check out your data sheet for info on which pins these are, but for the ATTiny2313:

ATTiny2313 pin name

ATTiny2313 pin #

SCK

 19

MISO

18

MOSI

17

RESET

1

The numbers on the right of the config (e.g. the 2 in ‘miso = 2’) refer to the data bits in FTDI’s bitbang mode. You can find more info in the application note for bitbang mode. Regrettably, only the pin numbers are listed and not the pin names (which is what I needed to find out which pinouts on the FTDI Friend corresponded to which pins on the FTDI chip). You can check the datasheet for the FT232R for these, but to save you some time here’s a list of the pins and their respective name and bit bang data bit:

FT232R pin #

FT232R pin name

Bit bang data bit

1

TXD

0

5

RXD

1

3

RTS#

2

11

CTS#

3

2

DTR#

4

9

DSR#

5

10

DCD#

6

6

RI#

7

You can see in the avrdude.conf the author has nicely put the pin names in comments next to each line. These match up with the handy names printed on the FTDI Friend:

2016-02-21 19.11.22.jpg

A standard FTDI cable is above for reference. The pinouts are the same.

You can see that the pins we have immediately available to us (aside from VCC and GND) are CTS, TXD, RXD, and RTS. This works great with the ttl232r programmer already present in avrdude.conf, but if your cable/board has different pins available, just use the above table to create a new programmer entry with the data bits you have available.

With the above information we can now wire up our programmer to the AVR!

FTDI Friend pin #

FTDI Friend pin name

ATTiny2313 pin #

ATTiny2313 pin name

1

GND

10

GND

2

CTS

17

MOSI

3

VCC

20

VCC

4

TXD

1

RESET

5

RXD

19

SCK

6

RTS

18

MISO

2016-02-21 19.39.36.jpg

(VCC and GND are connected through the bus lines on the breadboard)

Programming

Once it’s all connected up, we can program to our heart’s content with AVRDude (6.3 as of the time of this writing). One important thing to note here is that the ATTiny2313 (and probably many other AVRs) uses a slow internal clock by default (1MHZ). In order for programming to work with this slow clock I’ve had to turn down the baudrate of the programming with the -b parameter:

avrdude -c ttl232r -p t2313 -b 4800 -U {memory commands go here}

We can speed up the clock by unprogramming the CLKDIV8 fuse bit in the LFUSE. By default the LFUSE of the 2313 is set to 0x64 and the MSB is CLKDIV8 (A bit is “programmed” as logical 0, and “unprogrammed” as a logical 1). To do this, we set LFUSE to 0xE4 with the following command:

avrdude -c ttl232r -p t2313 -b 4800 -U lfuse:w:0xE4:m

Once set, the default baudrate seems to work just fine so you can remove the -b parameter.