Skip to content

Serial Bootloader for AVR ATMega8

March 19, 2012

One great thing about AVR microcontroller is that they can “program theirselves”. This is not unusual for nowadays microcontrollers but for a legacy like device like an AVR it is really nice to have.

The idea is: When the AVR wakes up from reset a special program is started, called the boot loader. This program usually waits for some kind of action like a pulled up pin or data reception via the serial port. If non of these events occur in a specified time, the boot loader hands the control on to the main program.

For many applications it is nice to be able to change the program running on the microcontroller without the need of a special programming hardware. The boot loader presented in this post will enable you to do so.

Quick guide:

  • Check out my repository using mercurial ( hg clone https://bitbucket.org/befi/remote-controlled-socket )
  • The folder uc/avrprog_boot_v0_85 contains the boot loader
  • Type make to build the bootloader
  • Insert the ATMega8 into your AVR-MK2 programmer and type make program and the boot loader will be flashed and the fuses of the AVR are set accordingly (clock is set to 8MHz)

The makefile uses avrdude to flash the chip. If you use a different programmer than the MK2 you can change the parameters in the Makefile.

Ok, now we have a AVR with a serial boot loader installed. What next? Take a look at the folder uc/analog2usb in my repository. You’ll find an example program which reads values from the ADC and outputs them via the serial port.

What is interesting about that example is the Makefile. You can flash the program over the serial port into the microcontroller without using a programmer.

Quick guide:

  • Attach a Serial-To-USB converter to your microcontroller. This should give you a /dev/ttyUSB0 device unter Linux
  • Reset the microcontroller and within 2 seconds execute make program from the analog2usb example
  • Voilà, your AVR is now programmed via serial

To explain what has happened here: After reset the AVR waits for two seconds for the programming byte “S” via the serial line at 19200 baud. If the “S” character is received within two seconds, the boot loader emulates a AVR109 serial programming dongle. After that avrdude is called to flash the main program into the chip.

Advertisements

From → Uncategorized

6 Comments
  1. eparis permalink

    Why do you say that the AVR is a “legacy” microcontroller? It seems to be a current architecture. Yes, it is an 8-bit architecture but it has features (timers, PWM, ADC, bootloader support, pin change interrupts, etc.) found in bigger architectures and it is adecuate for many uses. PIC, TI MSP430 family, AVR are in widespread use and actively supported by their respective companies. The 8051 family would be something I’d consider “legacy”. Cheers!

    • You are right, it is still in widespread use. But compared to Cortex-M0/M3 devices, it looks quite “old”. These ARM cores often consume equal or less power, they are much faster and also cheaper.
      I think the majority of AVR users are hobbyists that know the chip well and just want to get their project working without getting to know a newer chip. That is also true for me. But it doesn’t change the fact, that the AVR is becoming nearly 20 years old. So maybe we can agree on calling them outdated instead of legacy? 😉

      • eparis permalink

        I see. I am also a hobbyist and the AVR has definitely spread pretty widely in that community, especially because of the Arduino. I have no experience with ARM. Guess I’ll have to try them sometime. Outdated instead of legacy seems like a good compromise 😉

        Thanks for the interesting post.

      • Ah well, the problem as a hobbyist (like me) that I can’t (or don’t want?) do SMD etc, I am happy to have uC in DIP packages I can solder. I am not fan of buying “ready” boards, it does not feel then to be made myself, or so 🙂 I guess there is not so much uCs in DIP packages among ARMs and such. But correct me if I am wrong, I would interested in ARMs too if it’s available in a “hobby friendly” package [DIP] 🙂

Trackbacks & Pingbacks

  1. How to add USB to radio controlled sockets « befinitiv
  2. » Adding web connectivity (via USB ) to remote controlled sockets – Part 2 (software) Jake Rowan Byrne

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: