Wednesday, July 11, 2007

Luckier than I Deserve to Be

I've had mixed luck with the AVR Dragon. It seems like I can use it to do ISP programming on a remote device, but that's about it. Thing is, it works perfectly, every time. But if I try to do ISP programming on a device that's plugged into the Dragon's ZIF socket, it fails in some weird way every time.

So on this last project I wound up using the STK500 and the Dragon in concert. The STK500 has two serial ports on it: one to program the device, one that can be attached to the device's onboard UART (if it has one... or more than one.) Problem is my laptop has no serial ports, so I was swapping my USB to serial adapter from one port to the other for programming and testing. It was a drag. In the end I wound up plugging the device's RS-232 port into my Linux box, using VNC on my laptop to connect to the Linux box, and ran it that way. This was better, but it was still a drag.

So this morning I brought in my Dragon, plugged it in as an ISP programmer for the ATmega16 plugged into the STK500, and voila, everything worked perfectly. The laptop's serial cable talks to the device's RS-232 port, and the Dragon acts as a programmer. Perfect.

But wait a sec... How come this only works for off-board targets?! I started to pry. That's when I realized what a doof I've been. After going through the connection diagrams for the ATmega16 (the one I'm using for the Tcl/Tk project), I realized that every time I'd installed a chip on the Dragon, I'd installed it backward. EVERY TIME.

That explained a lot.

So with shaking hands I put in an ATtiny85 (a little 8-pin processor that can crank out 20MIPS with the right crystal plugged in.) With even shakier hands I cabled it up for ISP / debugWIRE. (Since buying the Dragon I have never ever been able to get debugWIRE or JTAG debugging to work because I am a doof.) Click, start AVR Studio. Click, choose the LED blinker app I'd written for the '85. Click, compile. Click, program via the Dragon's ISP interface. So far so good. (For what it's worth, I had never reached this stage before since the Dragon had always failed to power up with the ATtiny85 cabled up to the ISP interface. Funny what electronics will do when you install stuff backwards.)

Now for debugWIRE... Click, click, click, yeah I'm sure I want to disable ISP and enable debugWIRE. Click... Holy cow! It's running live code on the ATtiny and I'm seeing the contents of its memory LIVE! This ROCKS! I'm a doof, but this rocks! Yeah, so this is just an LED blinker application. But now I can see the ADCs, timers, and everything live!

So with slightly less shaky hands I unplugged the Dragon and thought about this. I can't count how many people on AVRFreaks have reported that they've blown up their Dragons. Among other things, there's a very sensitive part of the on-board power supply that responds poorly to changes in capacitance -- like when a human finger touches it and changes the dielectric constant of its package. So here I am, I've been repeatedly plugging in various AVR chips backwards, and mine still works flawlessly.

Despite all my bad luck with accidents (this is a running joke at work), cards (I simply don't play), life (the water leak at my house), and everything else, maybe I really am a lot luckier than I thought. Or maybe my Dragon just likes me.

It's good to have a Dragon for a friend.

Tom

No comments: