Few days ago I got package from Helsinki Hacklab. Some generic component stuff and a couple Atmel xmegas and breakout boards for them. Nice bit more powerful MCU’s than normal atmegas & attinys, but they eat only up to 3.3v, so better not to kill them with 5V logic. Luckily most 5v logics detect 3.3v as high, and their higher output can be lowered with resistor divider. Programing these xmegas also differ from their li’l brothers. Xmegas use PDI, which is kind of two wire system, constant clock signal and data I/O. I did not have expensive atmel programmer, so I improvised cheap ~2€ programmer using usbasp and avrdude using these patches.Compiling firmware for usbasp was easiest part. usbasp-pdi-patch my version can be downloaded from here, but I recommend you compile this yourself, this file may or may not work, no guarantee. You need another programmer for updating usbasp firmware. Plug usbasp to another programmer and connect JP2 jumper. Flash .hex file to usbasp following guides of your programmer. I had 2 usbasp so I just used one to program other one.
The hard part is avrdude. I could not get it compiled either in debian 6, xubuntu or freebsd even though I had all needed libs&stuff. Same goes for cygwin, no luck there. But in MinGW it worked, although not all programmers etc. are supported in my binary version. avrdude-usbasp-pdi-bin go to libusb folder and plug usbasp to usb port, run Inf_wizard, select usbasp from the list and install crated .inf driver file if usbasp not used or installed before. Patched Avrdude should recognize it when -C usbasp is used.
You may want compile avrdude yourself, it is after all executable program, so don’t blindly trust mine(It is virus and malware free I can assure you I tested it, but it may not be compatible with your system, it is compiled under 64-bit windows). Follow guide from original creator, I have patched source but you should try download and patch it yourself. For MinGW you need to put libusb files into mingw folder. ./bootstrap && ./configure && make should do the job. If you don’t know how to do this, ask somebody else who knows, I can’t help much because I can’t either get it working on other systems and even with different MinGW installation it caused problems.
And then we go to hardware part. As said, xmegas should newer get 5V in any IC pin, it will broke, there is no protection, and these ICs are definitely not as robust as DIP AVR’s. My usbasp was stupidly constructed, VCC for programming header can be selected between 3.3 and 5v, but programming logic levels are 5v in both case. I made little hack and converted usbasp to use it’s own regulator for main vcc(mega8 is hearth of usbasp).Who needs fuses, usb should anyway be well protected, and original fuse would not blow anyway if output is shorted(tested that, computer rebooted). Be sure which side is usb and which is vcc for usbasp, wire going from regulator output must be soldered to vcc, and vcc must be separated from usb power.VCC is connected to center pin of voltage selection jumper, so vcc can be selected between 5V and 3,3V. USB 5v is connected to input side of regulator. Important: in this version of usbasp board track going to regulator input to R4 must be cut, it separates vcc from regulator input. Now whole usbasp should work at 3.3V when jumper is set so. That small regulator can’t handle very much current, so use external power for target circuit, if it pulls more than 10-20mA. Test usbasp before connecting it to xmega, and hopefully your usb ports are forgiving…Resistors connecting MISO and SCK together. Build cable using this schematics from original post. Mine is build using connectors from old computer cases. Useful tip: cut one unused pin from pinheader, and block corresponding pin from connector, so you can only plug it in one way.
It is working! avrdude -c usbasp -p x32a4 -U flash:w:test.hex and let there be blinking light! Hello world to you!
P.S. Oh, wanna see more about xmega board? Here some pictures:
4 thoughts on “Programming xmega with usbasp & avrdude”
this chip(xmega32d4) was build in the circuit board of electric meter is there any way of reprogram it so as t make some modification to the chip if it possible i will attach the photo of the meter.
I built a RaspIO Board (designed for Arduino IDE, but I am running vanilla avr-gcc) last week to program an ATMega328P AVRDUDE via the GPIO pins which works really great (IDE is currently Geany under headless/VNC Debian Wheezy).
Next week I plan to connect an AVR XMEGA-A3BU Xplained with the Raspberry – any experience with this?
Here’s the link – http://raspi.tv/2015/raspio-duino-goes-on-general-sale-with-free-arduino-programming-ebook
Great solution for those where Atmel Studio 6 is overkill.