ATMega32 Optiboot

02/18/2012
Adding the Optiboot bootloader to an ATMega32 microcontroller

As I mentioned before, the ATMega32 is my go-to chip for microcontroller projects.

So with all the fuss about Arduino going around I decided to essentially build my own.

All that's really required is an ATMega32 chip with this bootloader installed and a USB-TTL serial

adapter to communicate with the chip and the bootloader. Adding a 16MHZ crystal will make it

more compatible with existing Arduino libraries. (NOTE: not all libraries will work on this device)

Here how the hardware is set up:

This is the 8MHZ version using the internal 8MHZ RC oscillator. (you don't really need all those LEDs)

Add a 16MHZ crystal and appropriate caps to pins 12 & 13 for the 16MHZ version.

You'll also have to adjust the MAKEFILE and boards.txt entry for the higher F_CPU value.

Once the chip is programmed you need to add the ATmega32 folder inside the "variants" folder where

your Arduino IDE software is installed additionally you'll need to add the "ATMega32" board entry to

the boards.txt file similar to what's described in the instructions. (those were for version 1.0 of the IDE)

When everything is configured you can then write Arduino code just like you would for an UNO.

You'll have access to more I/O pins. (The mapping is shown below)

But everything else should work pretty much the same since the ATMega328p is quite similar in design

to the ATMega32.

Another item to note is the reset circuit. On the Arduino, the DTE signal is activated when a terminal (including

the IDE serial monitor) is connected to the Virtual COM port. This signal typically sends a reset pulse to the ATMega

chip activating the bootloader. If the bootloader gets no response after a predetermined time it simply executes

the currently loaded application code.

Not all USB-TTL serial adapters have this DTE signal exposed as I have shown in the schematic.

If this is true in your case, simply hold down the reset switch until the IDE status bar says "Uploading"

The immediately release it. You should then see the status LED connected to pin 1 on the ATMega32 respond to

the upload.

If you'd rather not use the Arduino IDE and it's libraries but simply compile code with WINAvr you're in luck as well.

The bootloader responds to AVRDUDE as programmer "arduino" just specify the COM port and a baud rate of 19200.

on the AVRDUDE command line like this: avrdude -p m32 -c arduino -P COM7 -b 19200 -U flash:w:{your_Hex_file}.hex

The programmer is no longer required and the serial adapter is conveniently connected and available for your program to use.

Resources and Tools:

Download and install WinAVR (the AVR GCC compiler) http://sourceforge.net/projects/winavr/files/WinAVR/20100110/

Download and install the latest Arduino IDE software http://arduino.cc/en/Main/Software

the attached file optiboot_m32.zip contains a document with explicit instructions on how to build and install the bootloader.

You will of course need an AVR programmer or an Arduino board which can be configured as a programmer.

Breadboard setup with USB-TTL Serial adapter connected.

(note my own special reset button that lives on top of the ATMEga32 chip so it take no breadboard space)

ATMega32 Arduino Pin Mappings

Screenshot of the board selection once the IDE
configuration has been made.

Screenshot of the Serial Monitor in the Arduino IDE running SerialBlinkPA0.ino

Download Link Details:

optiboot_m32.zip Source code and instructions for making and installing the bootloader

SerialBlinkPA0.ino Sample Arduino source for and example using the serial monitor and LED

Fade.ino Sample Arduino source for an example of the Fade project modified for the AMega32