AVR Butterfly Part 2: Setting the BOOTRST Fuse with ISP Cable

11 07 2009

With a little more research I decided to hack together an ISP programming cable using a computer parallel port to toggle the BOOTRST (Select Reset Vector) fuse on my AVR Butterfly, rather than send it to someone to fix it or back to Mouser. Schematic shown below,

direct_ave_parallel_access_cableNOTE: the 1K resistor going from pin 11 of the DB25 to the MISO is too high of resistance. When I tried to use this cable with AVRdude I got the following error,

avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

I just removed that MISO resistor entirely and got it working correctly. A lower value might be good to avoid accidentally damaging your LPT port; some schematics said 300 ohms. If you still get the above error without the resistor, check all your wires. Also, be careful and DO NOT plug in and turn on the AVR when the computer is off. This will possibly damage your LPT port from what I’ve read.

To get my male DB25 I cut off an end from an old printer cable, which also works well because it is shielded. The plans on the Internet recommended you keep the cable below 70cm in length to avoid interference problems. I forgot how many wires are in these things… If I ever make a bomb, I shall construct it with DB25 connectors.

“Cut the orange wire!”

“but.. WHICH ONE?!”

DSCN0801As far as I can tell there is no standard for the wire colors inside,  so you just have to strip each one and test it with a meter. If you’re following along with this, I hope you have a good pair of wire strippers. Either that, or I’ve found for this small of wire you can put an old tip on your soldering iron, crank the heat up all the way, and then just let it sit on the bit of exposed wire on the end. The insulation should peel enough to test it with a meter easily.

AVRdude is a command line utility that can easily toggle the fuse bits using this cable and the butterfly, and it comes with WinAVR. There is a great tutorial for how to set fuse bits here. The following is just a quick summary.

First, read the current configuration of the high fuse byte.

avrdude -c dapa -p m169 -U hfuse:r:hfuse.txt:b

This will create a file called hfuse.txt containing something like,


The #1 (last, LSB) bit of the high fuse byte is the BOOTRST bit which needs to be programmed to activate the bootloader.  In Atmel jargon, a bit is “programmed” if it is 0 and not programmed if it is 1. In my case, flipping (programming) the last bit will result in 0b10011000, or 0x98 hex. To write that to the fuse byte,

avrdude -c dapa -p m169 -U hfuse:w:0x98:m

Success! Going back to AVR Studio and writing a simple program to blink some LEDs in a Cylon eye pattern to the AVR worked fine.

DSCN0804RISE MY CYLON BRETHREN! Er.. maybe I’ve been sniffing the solder fumes a bit much.

AVR Butterfly: Part 1

10 07 2009

After thinking about doing something interesting like making a robot for some time, I always end up getting bogged down in details and never get around to it. Instead of such a big project, I decided to just pick up an AVR Butterfly demonstration board to play with and learn more about programming micro-controllers. It’s got an d ATmega169PV with 512KB of memory; as well a handful of input/output pins with a built in clock, LCD, temperature sensor, buzzer, voltage sensor and analog to digital converter. It can also (in theory, see below) can be programmed with an RS232 port and no special hardware, and using all free software to compile C code or just program straight Assembly. And all this for only $20, hard to beat. I ordered it from Mouser and got it in the mail yesterday.

For assembly I found that I had a ton of male header connectors, but no females. A trip to radio shack came up with nothing, so I stripped apart an old computer and found what I needed. The cables that go to the serial and parallel port are 10 pin female and work well. Only downside is that they are stranded wire and will be a pain to push into a bread board.


The connectors are too wide for all 3 of the 10 pin headers, but the middle one I think is just JTAG stuff for the most part and won’t be used for now at least.


For the RS232 I used the female connector on the end of the power button,  along with a spare pin off a front LED connector.


The other end just goes to a DB9 I had laying around. Only downside to all this is that it’s quite easy to plug things in the wrong direction.

DSCN0799I hook it up to the RS232 and manage to make it say, “Hello”. After that when I try to actually program a simple C program into it though, I find that I happen to have one of the misprogrammed/recalled AVR butterflies which do not have the boot loader bit set correctly on them. Instead of starting instructions at the beginning of memory, it skips the bootloader and isn’t programmable through the RS232 until I toggle a bit using either JTAG or SPI.  The way to diagnose the problem is to note that when you apply power, instead of sleeping until you press up on the joystick, it will just start tickering AVR Butterfly across the screen right away. It also won’t send the series of question marks to the serial port on boot that are expected. The details on how to change the bit with SPI are elusive, since it’s something most people trying to program chips via JTAG or SPI should already know apparently, and the schematic link I found for using a parallel port to program the SPI was dead, so I’m currently waiting on some forum replies plus an email to Mouser to see if they will do anything about sending me a recalled product. They’ll probably tell me I can send it back and get a new one, but it’s really not worth the trouble, especially if they charge for shipping; and I also soldered on my header connectors already… Worse case I’ll make friends with some people at the lab at work and see if I can get ahold of a JTAG programmer during my lunch break.

Internship Coming Along

9 07 2009

Just a random post to let people know I’m still alive, and this blog may actually be updated every now and then. I’m currently doing a summer internship at Emerson Network Power, which is keeping me rather busy (40 hours a week). The details I can’t really go into, but it can best be summed up as automation scripts in a bunch of languages no one has ever heard of, for software most people haven’t heard of, on an interesting project that I’d have to kill you if I told you about.

In another news, I’ve ordered an AVR Butterfly to play around with in my spare time and learn some C programming for embedded microcontrollers. It should be coming in the mail today (woot). That should provide some useful rambles about hacking and programming to put here.