Sep 192011
 
Programming AVRs

Programming an AVR microcontroller can be done by many ways. If you have an Arduino bootloader like this, it can be done via serial interface. If you use the one and only serial interface though, that’s not the best option.

One method is to use an existing Arduino, which is neat if you have one or want to use one dedicated as programmer.  Or you could get a dedicated programmer or something more generic. Or an FT245R. Which I happen to have flying around.

The instructions are simple to follow and worked out-of-the-box as long as the tested version of AVRDUDE and libftdi is used.

I installed this special version into /usr/local. Here some example invocations:

  • Setting fuses (default frequency of an 644P is 1MHz, so you must use -B 1 to slow the programming down):
    sudo avrdude-ftdi -v -p m644p -c ft245r -P ft0 -B 1 -U lfuse:w:0xE2:m -U hfuse:w:0x99:m -U efuse:w:0xFD:m
  • Reading all 64KB FLASH from the 644P (takes 13s):
    sudo avrdude-ftdi -v -p m644p -c ft245r -P ft0 -U flash:r:/tmp/644flash.hex:i

Small update: /etc/avrdude.conf must contain this:

programmer
  id    = "ftdi";
  desc  = "SparkFun FTDI Basic Breakout";
  type  = ft245r;
  miso  = 1;  # CB0
  sck   = 0;  # CB1
  mosi  = 2;  # CB2
  reset = 4;  # CB4
;