bootloading the arduino to run at 3.3v

Having moved over to a new lipo battery, I need to shift everything down from 5v to 3.3v. That has actually only meant that I need to (i) get a new (3.v) LCD display; and (ii) get the atmega328 running at 3.3v.

The trick to running the atmega328 at 3.3v and not 5v is to load a new ‘bootloader’ on it. The chip I purchased came on top of an Arduino Duemilanove. As such, it was pre-programmed (which is what the ‘bootloader’ code does) to run at 5v. (For more on ‘bootloaders’ and arduinos see here.) So I basically needed to load a new ‘bootloader’ on to the chip.

The bootloader I have used is the “Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328”. As the name suggests, this bootloader is the one found on an arduino pro. As can be seen, the major difference between the 5v and 3.3v bootloader is that at 3.3v the ‘speed’ of the chip needs to drop to 8MHz from 16MHz. (I was worried that this might affect the running of the lcd/bluetooth module/both but actually it all worked fine).

So, there are a number of ways of burning a new bootloader onto an arduino but the one I used was an AVRISP mkII programmer – seen on the right. The following are my steps to getting this to work…

Setup

1. Buy the AVRISP – mkII programmer.

2. Install the software (AVR Studio) from the internet even if it comes with a CD (so that get the most up-to-date version).

3. This should have installed the “Jungo driver” for the programmer that comes from AVR. The only thing is that I started by trying to use the Arduino to burn the bootloader and I ended up in a world of pain with two different drivers that didn’t play nicely. Best just to commit to AVR Studio at the outset and then all should install automatically and without incident. The drivers should look like the thumbnail.

4. Plug in the programmer to the USB port of the pc/laptop.

5. Plug in the arduino (which has the chip you want to programme sitting on/in it) via USB too.

6. Connect the six line header from the AVR programmer to the header chip on the arduino like this (note the red cable goes on the side of the arduino marked ‘1’):

7. Open AVR Studio (and ignore the inital welcome screen).

8. Click ‘Tools’-‘AVR Programmer’-‘Connect…’ and select ‘AVRISP mkII’. It should connect…

9. Then select the correct chip in ‘Device and Signature Bytes’

10. Then click ‘Read Signature’.

11. Hopefully all should match and you see something like this (assuming there is a bootloader has already been loaded on to the chip):

Programming

Intro

The way the programmer works is that each of the tabs from ‘Main’ to ‘HW Info’ detail different things that can be changed on the chip. Then, the last tab, ‘Auto’, can be used to automate the process – so under the ‘Fuses’ and ‘Lock Bits’ tabs you can describe the new settings, and then under the ‘Auto’ tab you can check ‘program fuses’ and ‘program lock bits’, and then run both commands by clicking ‘start’ on the ‘Auto’ tab.

Just to test this set-up, under the ‘Auto’ tab you can check the following:
– check signature
– read FLASH
– read EEPROM
– read fuses
– read lock bits
– enable fuse warnings

This series of commands will not make any changes to the chip, just store what is there.

If you click start, then it will prompt to store two hex code files (which I have always ignored but I guess they contain the existing hex codes for the chip), but more helpfully for a novice, the text window at the bottom of the screen will record what the programmer does. For my ATMega168 chip it gives me this:

Setting mode and device parameters.. OK!
Entering programming mode.. OK!
Reading signature .. 0x1E, 0x94, 0x06 .. OK!
Signature matches selected device .. OK
Reading FLASH .. OK!
Reading EEPROM .. OK!
Reading fuses address 0 to 2.. 0xFF, 0xDD, 0xF8 .. OK!
Reading lockbits .. 0xCF .. OK!
Leaving programming mode.. OK!
Writing FLASH output file.. OK
Writing EEPROM output file.. OK

Doing it…

After that test, time to actually programme the chip….

1. On the ‘main’ tab, in ‘programming mode and target settings’, set the ISP frequency to 2MHz (by selecting from drop-down list and pressing write).

2. In the ‘Program’ tab, look for the ‘Flash’ section and select the new ‘input hex file’ – which is the ‘hex file’ with the bootloader you want to load onto the chip. In Arduino release 022 these are found in:

hardware\arduino\bootloaders\atmega\

The file I need is the atmega328 pro at 8MHZ bootloader:

ATmegaBOOT_168_atmega328_pro_8MHz.hex

My settings looked like this:

3. For ‘fuses’, there is a slight ‘thing’ here. If you input the ‘official’ arduino settings you get hex values that look different to those which are found in the ‘board.txt’ document provided by arduino (found at: […] arduino-0022\arduino-0022\hardware\arduino\boards.txt). The reason for this is boring – something to do with atmel’s changes to the 328 and/or the arduino vs avr studio methods of reading the chip. See a discussion here. One way of testing this is to ‘read’ the values on an official arduino (ie bootloaded at a reputable source) and then comparing the fuse settings with board.txt. Anyway, the ‘fuse’ settings should look like this in AVR studio:

• the above is equivalent to the boards.txt values (I think) of:

pro328.bootloader.low_fuses=0xFF
pro328.bootloader.high_fuses=0xDA
pro328.bootloader.extended_fuses=0x05

• It’s also got ‘brown out detection’ on which means that if the battery drops below 2.7v then the chip will reset – which should prevent damage to the chip.

6. As for the ‘lock bits’, the arduino tutorial says this:

Once set the lockbits should read 0xFF for ATmega8 and 0xCF for ATmega168, which is equivalent to:
• Mode1: No memory lock features enabled
• Application Protection Mode1: No lock on SPM and LPM in Application Section
• Boot Loader Protection Mode3: LPM and SPM prohibited in Boot Loader Section

It looks like this on a 328p:

7. Job Done!

8. Finally, if you want AVR Studio to run these commands in one sequence, use the Auto tab with the following settings:

POST_SCRIPT: The only thing to remember is that having set the chip to run at 8MHz, it cannot now be programmed by an arduino running at 16MHz!

Ben

post a comment...

you must be logged in to post a comment.