AVR (ATMega16) Bootloader Experiments
I needed to get a serial bootloader onto an Atmega16. Here is how I went about doing it. First, install `avrdude' - it's a much more capable program than `uisp'. We need it because `avrdude' supports a lot of methods to burn code - including communicating with a bootloader based on the Atmel Appnote AVR109 - Self programming. AVRDUDE has a peculiar command line interface. Here are a few samples: avrdude -p m16 -c dapa The "-p m16" option selects the processor, in this case, a mega16. The "-c dapa" option chooses a programming circuit, direct access parallel port, which uisp also supports. Before executing the command, make sure that you have the parport drivers loaded (check out `lsmod' or `dmesg'). On my Debian Etch system, there was no /dev/parport0 entry even though the drivers were loaded. So, I had to create one: mknod /dev/parport0 c 99 0 This invocation of `avrdude' simply checks whether the processor is present. Here is another sample: avrdude -p m16 -c dapa -U hfuse:w:0xd9:m The -U option is for performing a `memory operation' as specified by the next argument - which basically says write (w) to the high fuse byte (hfuse) the immediate (m) value 0xd9. How do we write hex files? Simple: avrdude -p m16 -c dapa -U flash:w:a.hex Once we have tested `avrdude' satisfactorily, its time to download a bootloader. This one works well: Download bootloader as .zip file The makefile as well `main.c' will have to be changed a bit - instructions are given in readme.txt. `make' will build the bootloader and `make program' will burn it onto the Atmega16 using the `dapa' interface. For `make program' to work properly, you will have to change one or two strings in the makefile. Control will get into the bootloader (upon reset) when a particular pin is held low - which port/pin should be used can be defined in `main.c'. I changed the default to use Port C, pin 0 (PC0). Reset the controller (with PC0 held low) and try: avrdude -p m16 -c butterfly -P /dev/ttyS0 You should see avrdude establishing communication with the on board bootloader. To upload a program: avrdude -p m16 -c butterfly -P /dev/ttyS0 -u -U flash:w:blink.hex Reset the processor (with PC0 NOT grounded) and the code should start working. Note that you have to manipulate the high fuse byte of the mega16 so that we get boot flash size = 2kb and `reset vector pointing to boot flash' (BOOTSZ1,BOOTSZ0 both cleared to 0 and BOOTRST also 0). The fuse value I am using is 0xd8 for fuse high and 0xef for fuse low. It may be good to set the lock bits to protect the bootloader from being overwritten - but I am able to get things working without it.
Sat Jan 26 13:05:44 2008
Hi Sir, That was a useful article. I tried this with my STK500 Development board. I could able to successfully program bootloader and it s working..!! Expecting more articles from you about AVR. Thanks.
Sun Feb 24 19:13:20 2008
Oh this looks good! I'm going to try this soon :)
Tue Aug 19 06:15:17 2008
hi sir, all the work you have done is in Window XP or Linux environment? because i'm not sure how to install avrdude in window. thanks.
Mon Dec 29 14:11:16 2008
Does this work for atmega 128 ?
Sat Jun 27 19:49:25 2009
yup i have developed a can 128 bootloader and it works as smooth as butter.