Saturday, August 11, 2012

FT232R Bitbang Programmer

Need a emergency programmer for burning bootloader on Arduino? Don't worry, now we can do it with the FT232R directly without any AVR chips by using their "special" bitbang mode. Bitbang mode allows you to control every single pin on FT232R by using USB messages from computer. This pins can act as output or input, just like an AVR chips.
Actually, I've knew FT232R can work as a programmer long time ago from Avrusb500v2 project by Tuxgraphics. They're STK500v2 compatible programmer and uses FT232R (via uisp-bbpg program) to flash the Atmega8 chip. But, it stated that programming using uisp-bbpg is very very slow due to USB bitbang command packet can't handled like the USB bulk data transfer. In other words, we must send each byte one by one in one packet, not all bytes in one packet. It took about 30-40 minutes to flash 4 kbytes program (what the!?). After flashing the Atmega8, the fast programmer will be taken care by the Atmega8 and controlled using serial connection to the computer. After a few months, I tried to bootload AVR chip but my DIY Avrusb500 is stopped working and reflashing Atmega8 chip doesn't seem solve the problem. Bootloading or flashing my AVR chip directly with bbpg isn't a great idea too because it just wasting time.
So, after googling the world, I found out that FT232R bitbang mode can be clocked to run at higher speed without problems. Luckily I found this one. Mr. Suz has developed a modified version of avrdude (the uploader software that used by Arduino) called avrdude-serjtag. This modified avrdude adds support FT245R and FT232R to flash an AVR chip. Of course, this is way more faster than uisp-bbpg. I've bootloaded my Atmega328p using avrdude-serjtag and it only took about 20 secs.
Then, how do we set it up on our arduinos?

1. Download avrdude-serjtag04e.zip and Arduino software.

2. Open up your Arduino root directory. Then navigate it through hardware\tools\avr\bin.

3. Rename avrdude.exe to avrdude.exe.old or anything (just to backup the old one) and copy the new patched avrdude.exe from avrdude-serjtag zip file you've just downloaded.

4. Now, navigate to hardware\tools\avr\etc and copy avrdude.conf just like the exe one.

5. Open up avrdude.conf, go to the end of the file and add couple line below:
programmer
  id    = "ftdi";
  desc  = "FT232R BitBang Programmer";
  type  = ft245r;
  miso  = 5; # DSR
  sck   = 4; # DTR
  mosi  = 6; # DCD
  reset = 7; # RI
;
 The MISO, SCK, MOSI, and RESET pins are changeable. Use this table below for pin number reference.
PIN NO.     DATA LINE
   0           TXD
   1           RXD
   2           RTS
   3           CTS
   4           DTR
   5           DSR
   6           DCD
   7           RI
 Then, find this line
default_parallel   = "lpt1";
And change it to
default_parallel   = "ft0";
Why we're doing this?  This is because we can't set programmer port on Arduino other than Serial (COM) port, and there is no way to pass -P option from Arduino to Avrdude. So, we must set the default parallel port to FTDI port 0 (ft0) or avrdude will throw an error to Arduino software when we're trying to upload sketch or bootload AVR chip.

6. Now navigate to hardware\arduino and open programmer.txt. Then add line below at the end of the file.
ftdiprog.name=FT232R Fast BitBang Programmer
ftdiprog.protocol=ftdi

ftdislow.name=FT232R Low Baud Programmer
ftdislow.protocol=ftdi
ftdislow.speed=4800

7. Done! Now you can open up the Arduino software and select the FT232R Fast Bitbang Programmer under the Tools > Programmer menu. If you want to bootload a fresh new and virgin AVR chip, be sure to select the low baudrate programmer instead the fast one because their factory default fuses is set to 1MHz internal crystal clock speed so they will hate fast programmer (read: you will get error when you're try to bootload them). You should burn a new fuse (8 MHz int/ext crystal or 16 MHz ext crystal) before using the fast one.

2 comments:

  1. Thanks a lot sir,for the procedure...
    Do you know how to program 89s52 (8051) through SPI of 89S52 using bitbang of FT232R.
    I have a Induino board from simplelabs.co.in.

    http://www.simplelabs.co.in/content/induinox-arduino-learners-kit

    They have made CTS# ,DSR# etc pins out to program arduino bootloader by connecting them to SPI pins of atmega , without the use of any other arduino to work as is-system programmer.

    How can I use them to program 8051.
    I am desperately looking for solution.
    Thanks

    ReplyDelete
  2. Not set up for windows....ports are Linux

    ReplyDelete