Arduino Pt.4

Doubling the Arduino Flash Memory once again

Times really flys when you’re having fun – it has been more two years since I posted this journal entry about how to double the Arduino board’s Flash memory by replacing the ATmega8 with an ATmega168 microcontroller. Lots has changed since then, e.g. the Arduino project now includes several board designs and layouts, most of which feature the ATmega168.

For the last couple of months now, the even better AVR 8-Bit RISC ATmega328P micro-controller was hard get. However, it’s now more broadly available and four of these 8-Bit Micros have arrived today, shipped form one of my favorite Online-Electronics stores: SparkFun. The ATmega328P features 32 KBytes of Flash, 2 KBytes of RAM, and 1 KByte of EEPROM a nice improvement over Arduino’s original configuration with an ATmega8: (8 KBytes of flash, 1 KByte of RAM, and 512 Bytes of EEPROM).
Time to revisit the Arduino Project, an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software, intended for anyone interested in creating interactive objects or environments.

Burn Baby Burn .. Again

Since switching form the ATmege8 to the 16, the Arduino’s Development Environment has also switched to avrdude, the software that loads programs from your machine onto the chips – manipulates the ROM and EEPROM contents of AVR microcontrollers. To use avrdude successfully with the new ATmega3258P, you may need to update its configuration file somewhere like here: /Applications/arduino-0013/hardware/tools/avr/etc, (look for the configuration file in theResources areas below).

Preparation …

At this point, the Arduino’s microcontroller had been replaced with the 32 KByte ATmega328P and everything but the ICSP port had been disconnected. The Arduino board itself was powered by a 7.5V 500mA power supply and the AVRISP-mkII connected the board with the Mac’s USB port.
On the software side, avrdude 5.5 was installed, the avrdude.conf file had been updated, and the ATmega328 boot-loader was made available here/AT328.hex, (look for the configuration file in the Resources areas below).

Burning, Fuses, and Flashing the Bootloader

Burning a new boot loader is a three-step process: unlocking the boot loader segment, uploading the new boot loader, and looking boot loader segment again. For an AVR microcontroller, the closest thing to a configuration file is its set of fuses. Fuses are used to configure important system parameters and a few important but obscure options can only be set through the ICSP. For instance, the ATmega328 defaults to the use of a 1 MHz internal clock and would ignoring the 16 MHz crystal on the Arduino board, if not told otherwise, through a fuse setting.

  1. Unlocking the boot loader segment, erase the chip, and set fuses (set boot loader size to 2K words [=2KByte]: 0x3800-0xFFFF, set clock speed to external 16 MHz)
    avrdude -p m328p -b 115200 -P usb -c avrispmkII -V -e -U lock:w:0x3F:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m -U efuse:w:0x03:m
  2. Uploading the boot loader
    avrdude -p m328p -b 115200 -P usb -c avrispmkII -V -D -U flash:w:/AT328.hex:i
  3. Re-locking the boot loader segment
    avrdude -p m328p -b 115200 -P usb -c avrispmkII -V -U lock:w:0x0F:m

Check out the Atmel AVR Fuse Calculator for more details.

Burn Log

Arduino IDE

After removing the AVRISP mkII In-System Programmer and changing the power-selector on the Arduino board, it was time to fire-up the Arduino IDE, but not before replacing the board definition file, required to make the IDE recognize the new micorcontroller, (look for the configuration file in the Resources areas below). Now the ATmega328 can be set by selecting Arduino w/ ATmege328 from the Tools/Board menu.
The Fibonacci program was quickly uploaded and running – the IDE reported Binary sketch size: 2020 bytes (of a 30720 byte maximum), which makes sense, considering that we set the efuse to preserve 2K words for the boot loader.

Fibonacci Program Output for the 1st 39 fibs

Share this post:

Leave a Reply