Atmega32L Arduino Bootloader installed! And working arduino sketch!!! *WHEW!*

Here is what to do to set up an Atmega32L to use arduino ide made hex files!!! ide support not yet working.. but should be in the future.. I'll explain later

1a. Wire up the board as shown:

Uploaded with ImageShack.us

1b. Flash the Arduino As ISP sketch to your arduino if you are going to use it as an avr programmer, or skip this step if you already have an icsp programmer.

  1. Go here: Alternate CORE files for Arduino
    download the arduino-extras.zip

  2. Make sure to make a backup of your arduino folder as we will be changing some files.

  3. Go to: your arduino folder to here: arduino-0022\hardware\arduino Delete all files in this folder.

  4. Dump the contents of the Arduino Extras zip (within the arduino extras folder) into the directory you just deleted the arduino files from.

  5. In your arduino folder go here: arduino-0022\hardware\arduino\bootloaders\atmega

  6. Copy the ATmegaBOOT_168_diecimila.hex file into this folder: arduino-0022\hardware\tools\avr\bin

  7. Now we are going to get things going. DO THIS EXACTLY AS I DO!!!!! with the exception of what port/baudrate/and programmer you have

Go to the command prompt, and get to the arduino-0022\hardware\tools\avr\bin\ folder
*Windows Vista, and 7 users, just right click away from a file in this directory while holding shift and select "open command prompt here"

First we will check to ensure everything is ok. Type this:
avrdude -p m32 -c name of your programmer -P port/com/usb -b 19200

It should say this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.14s

avrdude: Device signature = 0x1e9502

avrdude: safemode: Fuses OK

avrdude done. Thank you.

This will set the chip to be unlocked, and use the internal 8mhz oscillator. To use an external resonator or another speed, go here: AVR® Fuse Calculator – The Engbedded Blog

avrdude chipname programmer name baudrate com-port erase-chip.
avrdude -p m32 -c avrisp -b 19200 -P com4 -e -U lfuse:w:0xd4:m -U hfuse:w:0x99:m

Now unlock to bootloader:
avrdude -p m32 -c avrisp -b 19200 -P com4 -U lock:w:0x3F:m

Now flash the arduino bootloader:
avrdude -p m32 -c avrisp -b 19200 -P com4 -e -U flash:w:AtmegaBOOT_168_diecimila.hex

You should see this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e9502
avrdude: erasing chip
avrdude: reading input file "AtmegaBOOT_168_diecimila.hex"
avrdude: input file AtmegaBOOT_168_diecimila.hex auto detected as Intel Hex
avrdude: writing flash (16294 bytes):

Writing | ################################################## | 100% 3.35s

avrdude: 16294 bytes of flash written
avrdude: verifying flash memory against AtmegaBOOT_168_diecimila.hex:
avrdude: load data flash data from input file AtmegaBOOT_168_diecimila.hex:
avrdude: input file AtmegaBOOT_168_diecimila.hex auto detected as Intel Hex
avrdude: input file AtmegaBOOT_168_diecimila.hex contains 16294 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 18.74s

avrdude: verifying ...
avrdude: 16294 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

Now LOCK the bootloader! failure to do so will cause you to overwrite the bootloader when you do the next step!
avrdude -p m32 -c avrisp -b 19200 -P com4 -U lock:w:0x0f:m

You should see this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e9502
avrdude: reading input file "0x0f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.12s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0f:
avrdude: load data lock data from input file 0x0f:
avrdude: input file 0x0f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: 1 bytes of lock verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

Minimize the command line for a moment. It's time to make a blinky sketch!

Now, go into the modified arduino folder, and run the IDE. Throw this code in.

/*
  atmega32blinkpin32- *modified blink sketch for atmega32L by hexskrew*
  Turns on an LED on for one second, then off for one second, repeatedly, one by one for all 32 outputs. 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  pinMode(32, OUTPUT);     
  pinMode(31, OUTPUT);     
  pinMode(30, OUTPUT);     
  pinMode(29, OUTPUT);     
  pinMode(28, OUTPUT);     
  pinMode(27, OUTPUT);     
  pinMode(26, OUTPUT);     
  pinMode(25, OUTPUT);     
  pinMode(24, OUTPUT);     
  pinMode(23, OUTPUT);     
  pinMode(22, OUTPUT);     
  pinMode(21, OUTPUT);     
  pinMode(20, OUTPUT);     
  pinMode(19, OUTPUT);     
  pinMode(18, OUTPUT);     
  pinMode(17, OUTPUT);     
  pinMode(16, OUTPUT);     
  pinMode(15, OUTPUT);     
  pinMode(14, OUTPUT);     
  pinMode(13, OUTPUT);     
  pinMode(12, OUTPUT);     
  pinMode(11, OUTPUT);     
  pinMode(10, OUTPUT);     
  pinMode(9, OUTPUT);     
  pinMode(8, OUTPUT);     
  pinMode(7, OUTPUT);     
  pinMode(6, OUTPUT);     
  pinMode(5, OUTPUT);     
  pinMode(4, OUTPUT);     
  pinMode(3, OUTPUT);     
  pinMode(2, OUTPUT);     
  pinMode(1, OUTPUT);     
}

void loop() {
  int pinwrite = 0;
 do
 {
  digitalWrite(pinwrite, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(pinwrite, LOW);    // set the LED off
  delay(1000);              // wait for a second
  pinwrite++;
 }
 while(pinwrite < 33);
 }

Now! Make sure you select "Embedded Market Atmega32" for the 8mhz internal oscillator version if you changed to the outboard oscillator and running 16mhz, chose "Arduino-Penguino AVR"

Hold shift, and hit the play button on the arduino ide and anytime for now that you write a sketch for your atmega32. Notice the folder (just the numbers, ill tell you the rest).

Go to this folder (Windows 7 or Vista, XP users it will be different so just look at what folder the ide outputted to):
C:\Users\YourName\AppData\Local\Temp\buildbuncha numbers i told you to remember.tmp\

Copy the file: atmega32blinkpin32.cpp.hex

Paste that hex file into the arduino-0022\hardware\tools\avr\bin folder.

For a final horah before we get to the happy ending, open a beer, grab every led you can, and try to fill all 32 outputs on the Atmega32L.

Go back to the command line, and type this to flash the arduino sketch to your chip.
avrdude -p m32 -c avrisp -b 19200 -P com4 -U flash:w:atmega32blinkpin32.cpp.hex

You should see this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.12s

avrdude: Device signature = 0x1e9502
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "atmega32blinkpin32.cpp.hex"
avrdude: input file atmega32blinkpin32.cpp.hex auto detected as Intel Hex
avrdude: writing flash (1212 bytes):

Writing | ################################################## | 100% 1.56s

avrdude: 1212 bytes of flash written
avrdude: verifying flash memory against atmega32blinkpin32.cpp.hex:
avrdude: load data flash data from input file atmega32blinkpin32.cpp.hex:
avrdude: input file atmega32blinkpin32.cpp.hex auto detected as Intel Hex
avrdude: input file atmega32blinkpin32.cpp.hex contains 1212 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.44s

avrdude: verifying ...
avrdude: 1212 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

If everything went ok, then you should see your lights blinking in ecstacy one by one for the delay time you have in the sketch :smiley:

Final Step Very important
Chug your beer, slap your girlfriend's A** and grunt like hell. You just did what people thought was almost impossible :slight_smile:

Good job! :slight_smile:

I have to give some crazy props to these people for my venture:
Dunno who he/she is but they rock!:
http://www.avr-developers.com/ HEAVILY FOR THE FIRMWARE PACKAGE AND FOR ARDUINO COMPATIBILITY!!!
Carlyn Maw: At ITP physical computing for a detailed hookup of an "Arduino on a breadboard"
http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard
Everyone in this form thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1161487016/30
Lukus from NTDS.net for detailed info on burning a bootloader to an Atmega32L:
http://ntsdt.net/2009/08/22/burning-the-arduino-bootloader/

These are the real stars of the show, I just did some data gathering and proof of concept work :stuck_out_tongue:

Hey,

Nice writeup there.

I assume this method would work for programming other AVR's over the ICSP also?

I have a Sparkfun AVR Pocket Programmer (USB to ICSP), and want to program a ATMega644P on a board which only has a ICSP port.
I created another post about this, this morning - however no luck yet. I then found your post.

If I use the Sanguino bootloader, I assume I can do basically what you did with a few steps missed out?
I should be able to write the bootloader via the IDE as I have done that before. I then just write the hex file (found in the directory listed by holding shift and clicking Play) like you did?

So if I program the Sanguino bootloader via the IDE, copy the hex to the appropriate directory and then write the following, then that should work?
avrdude.exe -F -c usbtiny -p atmega644p -U flash:w: BrakePress.cpp.hex

?

Regards
J

Yes, that is exactly how you would need to do it. I will however also say that if you add either a serial port or ftdi chip (if that 644p has rx and tx pins which I believe it does) then you can just adjust the boards.txt and the ide will flash your code to the chip as well. I haven't tested this yet, but that's exactly what all the arduinos do.

Also what I come to find out (thanks to westFW for this info) is that you can use the ide and this method to write code for ANY atmega chip regardless if it even has a bootloader or not. Come to find out the Arduino bootloader is not needed at all for specific compatibility with code compiled from the arduino ide, as it just compiles into the standard hex format for the chip anyways. I am still gathering info on what exactly the Arduino bootloader is needed for, but what I do know is you need it for rx/tx functionality for easy uploading of sketches from the ide, but as far as I have known that's about it. I know there is more to it but you can use my method as described and upload without bootloader at all which in turn also gives you the option of writing larger programs.

Also I am soon going to try to find a method whereby you can use the ide to upload to the chip over an icsp programmer :slight_smile: Should be easily feasible just haven't gotten to that part yet.

Found this!
I haven't tested it yet, but replacing the lines for the Atmega32L in the boards.txt with this code should let the IDE flash code straight to the chip WITHOUT having to search around for the hex code and ext!

##############################################################
ecavr_atmega32.name=[avrisp]Embedded market atmega32 8mhz

ecavr_atmega32.upload.using=avrisp
ecavr_atmega32.upload.maximum_size=57344
ecavr_atmega32.upload.speed=115200

ecavr_atmega32.bootloader.low_fuses=0xff
ecavr_atmega32.bootloader.high_fuses=0xdd
ecavr_atmega32.bootloader.extended_fuses=0x00
ecavr_atmega32.bootloader.path=atmega
ecavr_atmega32.bootloader.file=ATmegaBOOT_168_diecimila.hex
ecavr_atmega32.bootloader.unlock_bits=0x3F
ecavr_atmega32.bootloader.lock_bits=0x0F

ecavr_atmega32.build.mcu=atmega32
ecavr_atmega32.build.f_cpu=8000000L
ecavr_atmega32.build.core=arduino

I am still gathering info on what exactly the Arduino bootloader is needed for, but what I do know is you need it for rx/tx functionality for easy uploading of sketches from the ide, but as far as I have known that's about it. I know there is more to it but you can use my method as described and upload without bootloader at all which in turn also gives you the option of writing larger programs.

The bootloader is needed for only one function, to allow the IDE to upload a sketch via AVRDUDE using a serial protocol. Once the sketch is loaded and running the bootloader is not used or required by any of the Arduino core commands or libraries. It is just a way to program a AVR chip without requiring an independent hardware programmer.

If you already have such a hardware programmer or even a spare arduino board running the ArduinoISP sketch then there is really no reason to burn a bootloader to the chip. It's really a user's choice these days, however as the IDE and arduino boards ship they assume and utilize the bootloader method to upload sketches, and is simpler for first time arduino users to get going with.

Lefty

This post is a bit of a duplicate to what I have discovered today also and have written here
http://arduino.cc/forum/index.php/topic,53556.0.html

The question is though, is it possible to get the IDE to set the fuse bits etc without having to write in a bootloader...

More details in that link above to what I want to achieve, which by the looks is what you will want to achieve here too.
No reason to have a bootloader to program with the ICSP, but there is the need to be able to program in the fuse bits...

Hopefully someone can answer.

Regards
J

I think maybe we need to take these needs to the ide dev part of the forum, because there are a few things that I feel would be better if we had them built into the ide, but maybe under an "advanced options" tab in options for the ide or something. Just have like a disclaimer stating that there is no support for advanced options.

Good evening everyone

I am new to this forum and the same applies to my experience with AVRs and Arduino

I have read the above thread and must say the procedure is impressive. Detailed and understood for the newbe as me.

Have got however a question to the author or someone who has already applied this one: what is the mapping of the uC pins? Which ones are analog and digital? Where are the PWMs and so on? Has someone documented this somehow? I will appreciate the answer

Thanks in advance
Pawel

No problem pafcio! Everything you ever wanted to know about this chip (and tons more lol) can be found n the datasheet for it found here: http://www.atmel.com/dyn/resources/prod_documents/doc2503.pdf

And just a heads up, at least for atmel chips and most well known ic components, there is always a free pdf datasheet to be had that documents the information needed for it (and most of the time, simple applications for said ic too!)

Thank hexskrew

This is not exactly I have requested. What I am after is the something as below in bold (example taken from pins_duino644.cxx file from Alternate CORE files for Arduino)

Thanks in advance
Pawel

// ATMEL ATMEGA644P / SANGUINO
//
// +---/---+
// INT0 (D 0) PB0 1 | | 40 PA0 (AI 0 / D31)
// INT1 (D 1) PB1 2 | | 39 PA1 (AI 1 / D30)
// INT2 (D 2) PB2 3 | | 38 PA2 (AI 2 / D29)
// PWM (D 3) PB3 4 | | 37 PA3 (AI 3 / D28)
// PWM (D 4) PB4 5 | | 36 PA4 (AI 4 / D27)
// MOSI (D 5) PB5 6 | | 35 PA5 (AI 5 / D26)
// MISO (D 6) PB6 7 | | 34 PA6 (AI 6 / D25)
// SCK (D 7) PB7 8 | | 33 PA7 (AI 7 / D24)
// RST 9 | | 32 AREF
// VCC 10 | | 31 GND
// GND 11 | | 30 AVCC
// XTAL2 12 | | 29 PC7 (D 23)
// XTAL1 13 | | 28 PC6 (D 22)
// RX0 (D 8) PD0 14 | | 27 PC5 (D 21) TDI
// TX0 (D 9) PD1 15 | | 26 PC4 (D 20) TDO
// RX1 (D 10) PD2 16 | | 25 PC3 (D 19) TMS
// TX1 (D 11) PD3 17 | | 24 PC2 (D 18) TCK
// PWM (D 12) PD4 18 | | 23 PC1 (D 17) SDA
// PWM (D 13) PD5 19 | | 22 PC0 (D 16) SCL
// PWM (D 14) PD6 20 | | 21 PD7 (D 15) PWM
// +--------+

nice work, i wish i would have found it some weeks ago. :wink:

i did something similar.
i have the arduino bootloader on the atmega32 and i can upload sketches like you.
i can control all 32 i/o pins with digital write and so.

but!

i have problems to connect my RTC-Clock over sda/scl.
there i get nothing back.
the clock works perfect on a 328 arduino, but not on the sda/scl pins on the atmega32.

does anyone of you have a idea what could be the problem?
is there something missing in the wiring.d or something in this direction? i can do something, but this is still a bit too complicated for me to get by myself the solution what might be missing.

...eok

here the "blink"

multiplexing 110 leds work as well

but not the rtc. :frowning:

I do not have the detail knowledge about I2C interface but you should modify the port settings in the twi.c.

void twi_init(void)
{
// initialize state
twi_state = TWI_READY;

#if defined(AVR_ATmega168) || defined(AVR_ATmega8) || defined(AVR_ATmega328P)
// activate internal pull-ups for twi
// as per note from atmega8 manual pg167
sbi(PORTC, 4);
sbi(PORTC, 5);

to
sbi(PORTC, 0);
sbi(PORTC, 1);

Nadir:
I do not have the detail knowledge about I2C interface but you should modify the port settings in the twi.c.

hi nadir,
thanks for your help. i made the change you suggested and they make kind of sense to me, so i think its one step in the right direction. but unfortunately it still does not work.
i get no error message, so it is hard for me to pinpoint the "problem".
it just dont work like in the 328 arduino.

im a bit frustrated, because i see the problem, but im unable to come up with a solution.
because i looked through the files in the ide. and maybe i directly looked at the position i have to change, but i just simply dont recognize it.

...eok

Doesn't that image (first post) contradict to: Arduino Playground - DisablingAutoResetOnSerialConnection

If the 120R resistor goes from RESET to GND, the processor is held in reset state all the time.

I downloaded the SDK v0022 (was using 1.0.5) and installed on a seperate hard drive in windows 7. downloaded all of the extras and followed your instructions. when I try to run the test command per your instructions I get an error back from avrdude about "avrdude line.xxx unrecognized character "a".

I'm thinking it's referring to the compiler switch (-c avrisp). any idea what is wrong? I also previously tried the same steps with SDK 1.0.5 but it didn't work.

trying to flash an atmega32A 40 pin MCU. all connections were checked.

madworm:
Doesn't that image (first post) contradict to: Arduino Playground - DisablingAutoResetOnSerialConnection

If the 120R resistor goes from RESET to GND, the processor is held in reset state all the time.

Quite so, but there are other (minor) faults in that diagram as well. :astonished:

I'm not using the reset setup you have in the diagram, nor am I using LED's. just simply a cap to prevent reset, communication lines, and resonator. i'm working on it tho, eventually I'll figure it out and post any results here. Arduino 1.0.5 should be able to communicate with this MCU from all of the data sheets I've read.

Hopefully my next reply will be a remedy with a working blink sketch and flashed bootloader :wink:

I've followed all instructions but get this error in the cmd window when entering the very FIRST programmer command

avrdude.conf:320 unrecognized character "a"

I looked at this file and it's just a declaration of the arduino -c parameter. any ideas?