After finally switching my laptop and computer over to ubuntu permanently, i found no software that would support my PIC microcontroller programmer and after a few vauge and useless attempts to reverse engineer it (i'm really not that good at electronics, i wake up in the night wondering why i'm not doing a degree to become a tree surgeon), i finally thought "sod it" and splashed out a bit of my student loan on an AVR Dragon after seeing there was an open source c compiler for AVR microcontrollers and supporting programming software, also there's some absolutely wicked projects people have done with them.
It then promptly got discarded in my box of bits for a couple of months (i like to think it was laying dormant in its lair......its a dragon, get the pun?)
so anyways, here's how i got it working, this will probably work with most flavours of ubuntu that use synaptic (you can probably do it on any version of linux if you compile it from source and whatnot, i like synaptic because its easy) and its more a collection of information from various sources, but should hopefully get you up and running!
I realise there are other instructables for getting started with avr microcontrollers, but i couldn't find anything that applied to my situation, so i hope this is at least a bit of help to somebody.
Step 1: Getting the Software
there are 2 main pieces of software i'll be using
this is the gnu c cross compiler for avr microcntrollers. A cross compiler is needed because we're compiling code for a microcontroller on an architecture (personal computer) that cannot run the compiled code.
This will take the code you write in c and convert it into a "machine readable" format (loads of 1's and 0's) which can then be put onto a microcontroller.
This is what puts the code onto the microcontroller, it connects with the avr dragon and transfers the Hex file (the compiled code) onto the microcontroller.
to install these pieces of software go:
system -> administration -> Synaptic Package Manager
search for gcc-avr and then avrdude and mark them both for installation, then install! simple.
if you want to use the command line you could try
sudo apt-get install gcc-avr
sudo apt-get install avrdude
Step 2: Compiling the Code With Gcc-avr
i'll be using some c code from this website:
its under a beer-ware license so i guess i'm good to include it here.
also needed is iocompat.h which just makes sure the code is compatible with the microcontroller we'll be using. ( an ATMEGA8-16PU, although i reckon most of the atmega8 range should be ok)
so go ahead and download the code from below and put the flash.c and the iocompat.h into the same folder.
now for the compiling!
open a terminal and navigate to where the code is downloaded too. then run the following commands:
1.) avr-gcc -g -Os -mmcu=atmega8 -c flash.c
this produces an object file called flash.o which then needs to be linked using:
2.) avr-gcc -g -mmcu=atmega8 -o flash.elf flash.o
this has now produced a binary file called flash.elf, which is a GNU executable file. we gotta mess with it a bit more and grab some bits out of it to make the hex file
3.) avr-objcopy -j .text -j .data -O ihex flash.elf flash.hex
we now have a hex file which is suitable for putting onto the atmega8, we'll be coming back to this in a bit.
(for a more detailed description of what each of the commands and options do see here:
lets get the hardware sorted!
Step 3: A Bit About the Dragon
Of worthy note is it has in-circuit debugging, a similar system for PIC microcontrollers will set you back near ÃÂÃÂ£100 (the MPLAB ICD2, we use them alot at uni), i bought my dragon from http://www.rapidonline.com for around ÃÂÃÂ£34, so i was rather chuffed.
There is a large area on the board for you to add your own headers and ZIF socket's ect. i had none of these to hand so i kept it simple and used ISP to program my avr.
(for a brilliant instructable on populating the empty bits see this )
so to use the ISP thingy we need an ISP cable!
forward to the next step!
Step 4: Making the ISP Cable
Apparently most of the documentation for the dragon comes bundled with avr studio (the official windows only IDE from atmel) which, quite honestly, sucks (not the IDE, i cant really say, i've never used it, but the fact you cant get the documentation).
i've been told if you want a copy of the documentation you have to grab a copy from an installed version of avr studio, which means either having a friend with it installed or *shudder* switching to windows for a bit.
But even then its in a weird windows proprietary format so you have to find some software to open it (some does exist for linux).
shame on you atmel, whatever happened to PDF's?
But anyway, i didn't know any of this so i spent many a few minuets searching the atmel website trying to find the pin names for the ISP header on the Dragon. eventually i stumbled across them on a random website (i'm sorry i forget which) and here they are:
pin 1 MISO
pin 2 VIG
pin 3 SCK
pin 4 MOSI
pin 5 RST
pin 6 GND
i used some turned-pin sockets to make a connector by cutting some off a strip and soldering some ribbon cable onto the back. (the images below give a better impression)
we now have a cable to connect to the microcontroller from the Dragon and a compiled hex file to put onto it. step on to the next step!
Step 5: Building the Circuit
if you grab a copy of the datasheet for the microcontroller things may be a bit clearer.
Make sure the LED and resistor are connected to the pin labelled OC1 or OC1A.
Check lots of times to make sure all the ISP pins go to the right place on the microcontroller, if you do it wrong you may risk damaging the Dragon (or slaying it) or hurting the microcontroller, neither of which you really want to happen.
now you have all that set-up it should look something similar to the second picture (hopefully allot less scruffy).
now that done lets get on with dumping the hex file onto this badboy.
Step 6: Writing the Hex File
Avrdude is a fantastic bit of open source software that supports loads and loads of different AVR programmers.
Firstly connect your avr dragon to your computer via usb, then check one more time that all the isp connections are correct then plug your isp cable into the avr dragon board (checking lots and lots that its the right way around, labelling it in some way would probably be a good idea).
Now that everything is hooked up open up a terminal and type the following command:
sudo avrdude -p m8 -c dragon_isp -P usb -e -U flash:w:flash.hex
(n.b the sudo is required because you need root privileges to access the usb port)
Here's the breakdown of the options:
tells avr dude it an atmega8 we are trying to program.
tells it we are using the avr dragon and its isp programming mode
tells it that the dragon is connected to usb (defaults to parallel port usually??)
erases the microcontroller prior to putting the hex file on it.
this is the meat and two veg (or qourn if your veggie) of the operation, it tells ' avrdude to write the hex file to the AVR's memory
note: if this fails and returns "invalid device signature" or something similar try the following:
sudo avrdude -p m8 -c dragon_isp -B 10 -P usb -e -U flash:w:flash.hex
the -B 10 tells the dragon to program it a bit slower, i had some issues with this.
Step 7: All Done!
Here are some good links:
The forums are great, and seem very accommodating to newbs if you ask nice and polite.
A brilliant tutorial, pretty much makes this obsolete, but i only found it while writing this.
Great beginners tutorial for using avr-gcc
Pretty much all you need to know about avrdude
Where i get most of my bits and pieces from (i think its probably UK only)
various other good instructables made by people clever than i.
(just search for AVR and theres lots of good stuff)
hope this is of some use to somebody.
*tips top hat*