ATMega8 Arduino
This project enabled me to use an ATMega8 as an Arduino. I used an 8MHz crystal, as opposed to the internal oscillator, as my project required some precise timing. This project is all based on a Windows environment and using the Optiboot boot loader.
Contents
Step 1 - Edit the Makefile
Go to the Optiboot directory in your Arduino install. Something like C:\Users\Fred.Bloggs\Documents\arduino-1.0.1\hardware\arduino\bootloaders\optiboot. Now, use a text editor (I use Notepad++) to edit 'Makefile'. You need to add the lines shown below-
# ATmega8_8MHz # atmega8_8mhz: TARGET = atmega8_8mhz atmega8_8mhz: MCU_TARGET = atmega8 atmega8_8mhz: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=57600' atmega8_8mhz: AVR_FREQ = 8000000L atmega8_8mhz: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe atmega8_8mhz: $(PROGRAM)_atmega8_8mhz.hex atmega8_8mhz: $(PROGRAM)_atmega8_8mhz.lst atmega8_8mhz_isp: atmega8_8mhz atmega8_8mhz_isp: TARGET = atmega8_8mhz atmega8_8mhz_isp: MCU_TARGET = atmega8 # SPIEN, CKOPT, Bootsize=512B atmega8_8mhz_isp: HFUSE = CC # 2.7V brownout, Low power xtal (8MHz) 16KCK/14CK+65ms atmega8_8mhz_isp: LFUSE = BF atmega8_8mhz_isp: isp
Step 2 - Edit boards.txt
You now need to edit 'boards.txt'. You will find this in a folder something like C:\Users\Fred.Bloggs\Documents\arduino-1.0.1\hardware\arduino\. You need to add the following lines to the end of the file-
############################################################## # # Source: http://www.indianbeantree.co.uk/wiki # atmega8_8.name=ATmega8 Optiboot (8MHz external OSC) atmega8_8.upload.protocol=arduino atmega8_8.upload.maximum_size=7680 atmega8_8.upload.speed=57600 atmega8_8.bootloader.low_fuses=0xbf atmega8_8.bootloader.high_fuses=0xcc atmega8_8.bootloader.path=optiboot atmega8_8.bootloader.file=optiboot_atmega8_8mhz.hex atmega8_8.bootloader.unlock_bits=0x3F atmega8_8.bootloader.lock_bits=0x0F atmega8_8.build.mcu=atmega8 atmega8_8.build.f_cpu=8000000L atmega8_8.build.core=arduino atmega8_8.build.variant=standard # ##############################################################
You will note that the baud rate is 57600, not 115200 as with most Optiboot images. I spent a long time trying to get other people's code to work until I tried lowering the baud rate. Only then was I able to upload sketches.
Step 3 - Make the source file
Open up a command prompt. Start=>Run=>cmd. then type in cd C:\Users\Fred.Bloggs\Documents\arduino-1.0.1\hardware\arduino\bootloaders\optiboot making any changes to the path name that are needed. In other words, the same path as in Step 1. Now type "omake atmega8_8mhz". If all goes well, this should make two files optiboot_atmega8_8mhz.hex and optiboot_atmega8_8mhz.lst in your Optiboot folder
Volume in drive C has no label. Volume Serial Number is 58A0-D531 Directory of C:\Users\Fred.Bloggs\Documents\arduino-1.0.1\hardware\arduino\bootloaders\optiboot 06/04/2013 10:57 <DIR> . 06/04/2013 10:57 <DIR> .. 31/10/2012 11:43 34,011 boot.h 31/10/2012 11:43 324 makeall 06/04/2013 10:23 13,845 Makefile 31/10/2012 11:43 111 omake 31/10/2012 11:43 60 omake.bat 31/10/2012 11:43 22,344 optiboot.c 31/10/2012 11:43 1,467 optiboot_atmega168.hex 31/10/2012 11:43 19,585 optiboot_atmega168.lst 31/10/2012 11:43 1,388 optiboot_atmega328-Mini.hex 31/10/2012 11:43 1,467 optiboot_atmega328.hex 31/10/2012 11:43 19,588 optiboot_atmega328.lst 31/10/2012 11:43 1,401 optiboot_atmega8.hex 31/10/2012 11:43 19,802 optiboot_atmega8.lst 06/04/2013 07:14 1,475 optiboot_atmega8_8.hex 06/04/2013 10:23 1,401 optiboot_atmega8_8mhz.hex 06/04/2013 10:23 20,411 optiboot_atmega8_8mhz.lst 31/10/2012 11:43 1,932 pin_defs.h 31/10/2012 11:43 3,438 README.TXT 31/10/2012 11:43 1,636 stk500.h 06/04/2013 10:58 0 text.txt 20 File(s) 165,686 bytes 2 Dir(s) 7,411,531,776 bytes free
Step 4 - Burn the bootloader
I used an Arduino Duemilanove as my ISP (programmer). There is a tutorial that shows how to connect this up - Using an Arduino as an AVR ISP (In-System Programmer). I used a breadboard set-up like this: Breadboard ISP.
Having connected up, load the Arduino as ISP sketch into your Arduino. Then change the board to ATmega8 Optiboot (8MHz external OSC), which should now be in your list of boards. Now, in the Tools menu, click on Burn Bootloader. You should now have an ATMega8 8MHz Arduino. Remember, this version needs an 8MHz Crystal. The first test you can do is to connect an LED with something like a 1K ohm resistor to pin 19 of the ATMega8 (equivalent to Arduino Pin 13). If you dab a ground wire to pin 1 (reset) you should see the LED flash three times.
Step 5 - Start programming
Now, all you need to do is to connect a USB to Serial adapter to your breadboard and you can use it like any other Arduino board. Upload the 'Blink' sketch and be amazed as your LED flashes on and off!