Programming an ATmega8 with a Bootloader: Part II

USBTinyISP programmer, modified 8 MHz bootloader and Arduino IDE 1.0.5.

This is one of the 4 methods I will be describing for programming an ATmega8 with a Bootloader. I have split this instructable in four sections so that the reader can directly access its preferred method.

In this section, we will use USBTinyISP programmer, modified 8 MHz bootloader and Arduino IDE 1.0.5. If you haven’t yet read the introduction this is a good time to do it…Programming an ATmega8 with a Bootloader: Intro.

A modified ATmega8 bootloader needs to be compiled because of the 8 MHz external crystal that we decided to use (default bootloader is 16 MHz). So we first compile a new bootloader with the following characteristics:

  • f_cpu=8000000L
  • speed=57600

Need to run make command in order to compile a new bootloader. For this, install Arduino IDE version 1.0.5 r2 (probably any 1.0.x version will do); go inside optiboot folder (C:\Program Files (x86)\arduino-1.0.5-r2\hardware\arduino\bootloaders\optiboot) and modify makefile.

Add the following:

# 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

From command line type: omake atmega8_8mhz

which will build .hex file in optiboot folder.

Arduino UNO needs to recognize the new board “ATmega8 Optiboot (8Mhz external OSC)” so we need to create a virtual board, modify it and copy it into boards.txt.

Where is boards.txt located?

C:\Program Files (x86)\Arduino\hardware\arduino\avr                                 (If you can’t find it, just use search command…)

boards.txt contains information of all the boards that the IDE shows us when we execute the command Tools->Board.

A BRIEF NOTE ON boards.txt: It is much better to use boards.txt that is located in your Arduino Sketchbook folder which is located in your user folder…in my case I have a folder Metaboards\avr:

C:\Users\Carlos\Arduino\hardware\MetaBoards\avr

This way, when you update your Arduino with a new version, you will not overwrite your boards.txt.

Open boards.txt with WordPad; each different board definition is separated by a line of “#”.

Copy the following board definition at the end (or wherever you want) separated by lines of “#”.

##############################################################
#
#  Source: <a href="http://www.indianbeantree.co.uk/wiki">http://www.indianbeantree.co.uk/wiki</a>
#
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
#
##############################################################

This board definition ATmega8 Optiboot (8Mhz external OSC) will let us program ATmega8 with an external crystal of 8MHz.

The next time you start up the Arduino software, you should have a new entry of “ATmega8 Optiboot (8Mhz external OSC)” in the “Boards” menu:

ide_optiboot8

From this point you could burn the bootloader onto the ATmega8 chip by going to Tools menu select Programmer > USBTinyISP and hitting “Burn Bootloader”.

Now, let’s test uploading a sketch using both i) the Arduino UNO and ii) FTDI USB-serial conversion breakboard.

Test using Arduino UNO board:

Once your ATmega8 has the optiboot bootloader on it, you can upload programs using the Arduino UNO board serial communication pins. The UNO board has a USB-to-serial convertor chip (ATmega8U2) built in.

To do, just remove the microcontroller (ATmega328) from the Arduino board so the ATmega8U2 chip (FTDI chip in former board revisions) can talk to the microcontroller on the breadboard instead.

The diagram below shows how to connect the RX and TX lines from the Arduino board to the ATmega8 on the breadboard.

To program the microcontroller, select ” ATmega8 Optiboot (8Mhz external OSC) ” from the Tools > Board menu and upload as usual.

  • Connect Arduino UNO as serial
    • Remove ATmega328 chip
    • Connect Rx, Tx, VCC and GND
  • Tools menu:
    • Serial: Choose your COM port
    • Board: Atmega8 optiboot (8mhz external OSC)
    • Programmer: Arduino as ISP
  • Upload blink sketch!!
    • no need to use upload using programmer, i.e., shift + upload arrow
    • Reset ATmega8: set pin 1 to gnd (you will see three flashes)
    • Press arrow (upload button).

arduino-serial-setup

Test using FTDI chip:

Once the target chip (ATmega8) has the bootloader, just load your code through a normal serial connection. It requires the following:

Use a 0.1uF cap between DTR and the reset pin. From there, all you need are 4 pins to connect to the target circuit – Ground, reset, Tx, Rx. This way you don’t need another Arduino to load code, and the serial monitor will work through the same hardware. Use any Arduino IDE!!

Connect FTDI connector as serial

  • DTR to pin 1 via 0.1 uF cap
  • Reset pin1
  • ATmega8 pin2 Rx connect to FTDI Tx
  • ATmega8 pin3 Tx connect to FTDI Rx
  • Tools menu:
    • Serial: Choose your COM port
    • Board: Atmega8 optiboot (8mhz external OSC)
    • Programmer: USBTinyISP or Arduino as ISP (it doesn’t matter since it uses serial com)
  • Upload blink sketch!!
    • no need to use upload using programmer, i.e., shift + upload arrow
    • Reset ATmega8
    • Press arrow (upload button).

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: