Ok, on to Atmega32

Ok, I feel like I really know the Atmega168 now, so now I'm just pushing dev like the kind of project manager we have all hated at some point during our careers. Shoot me if this is going too far. I have an Atmega32. This thing rocks, hardware-wise. If Arduino can go here, at least in the software world, there is no end to what it can do. I see that the Arduino Atmega168 bootloader supports it. The question is: what are we going to need to add to the Arduino IDE to support it? I want an item in the dropdown. I just tried burning the Atmega168-compatible software to an Atmega32 in an Olimex AVR-P40-USB board and, well, nothing much happened when I then tried to upload an Arduino sketch. Perhaps someone can shine a light on the differences between an Atmega168 and an Atmega32 and how that applies to the dropdown in the Arduino IDE.

To start experimenting, you can change the "build.mcu" setting in your preference file. This is the setting that the Tools | Microcontroller (MCU) menu sets. Changing it to "atmega32" will tell the Arduino environment to compile your sketch for the atmega32, which means your .hex file will have the right opcodes at least (since I think the ATmega32 and the ATmega8 have slightly different instructions). You'll probably get a bunch of errors in the Arduino core, though, since the hardware - and thus the code - for the two chips are different. Take a look at ARDUINO/lib/targets/arduino/wiring.c and pins_arduino.c. Sadly, editing this file to work with the ATmega32 probably requires reading the ATmega32 datasheet (http://www.atmel.com/dyn/resources/prod_documents/doc2503.pdf), which is not the most fun way to spend a Sunday. Supporting different chips and different boards is definitely a long-term goal of the Arduino project, though, so any headway you make would be greatly appreciated.

even easier for beginning; try it without Arduino IDE, with the command line way-of-life. Arduino Playground - CommandLine. just edit the mcu type in makefile and adjust both files pins_arduino.c and wiring.c. probably, other files? anyway, i would be very interested in getting different atmel chips to work. would expand arduino community enormously.

Just to reiterate, since you were asking questions on another thread. You don't need to worry about the IDE (at least, not at first). You don't actually need a menu item for the chip you want to use, you can just edit your preferences file and set "build.mcu" to "atmega32". What you do need to do is edit the wiring.c and pins_arduino.c files in the ARDUINO/lib/targets/arduino directory. It shouldn't require too many changes, just changing some names of hardware registers and bits for doing particular hardware configuration things. It will probably mean spending a lot of time reading the ATmega32 datasheet, though. Once you get those files working, you can go in and add an ATmega32 menu item if you want.

hi,

what's the main advantage of the atmega32 over the 168 ?

i found an avr overview here: http://www.sander-electronic.de/datasheet/AVR.pdf

am i right that the difference is something like from the atmega8 to the atmega168?
i mean double sized memory + a few more I/O ?

not that i could not find a use for both of it,
i just wonder if there was another killer feature or possibility i didn't find being ignorant, like for USB-connectivity or energy-saving or something.

//kuk

Actually, a lot more i/o. and double the flash of the atmega168 and quadruple the atmega8. Anything with half the storage of my old commodore 64 should be able to do a lot of fun stuff. Still, at this point in Moore's Law I don't know why Atmel can't make a processor with a megabyte of storage that fits in the Atmega8 footprint. Imagine what that could do!

i see,

but how many more i/o is that? digital or analog... the pdf i found is not clear to me.

according to AvrFreaks there is 32 I/O pins, 4 are PWM and 8 are analog.

I would like to use an Atmega16 with the Arduino software. I have seen in the previous posts, there is a way to do this. But as the last post is from december 2006 I want to ask if maybe someone has already resolved this problem.
I want to switch from Bascom AVR (which is a programing language for Atmels in Basic) to an open source programme like Arduino or Wiring, but as far I see, there are only some types of Atmels supported at the moment.

Hi, I have also a spare ATmega16 which I'd like to use for Arduino. Some suggestions? So now there are two requests for ATmega16 support :sunglasses:

It would be nice if Arduino handled all AVR chips.

I'd figure out how to do it but I only have a 168.
Feel free to send me chips. :wink:

If the Arduino supported multiple chips then we could pick the right chip for the job, write the code and just hit the upload button.
Hell it would automatically make programs work on different chips.

I have taken a look to the files that mellis mentioned in one of the previous posts. I think, it will be not too complicated to make some Atmega16 or 32 files. I like the Atmega16 because it is cheap and have more I/O pins. As a first step, we could try to create the necessary files for Atmega16 and 32. So more experienced users would be able to upload their .hex files with an ISP programmer and AVRDude on homemade Atmel/Arduino boards.

I modified now the pins_arduino.c file and changed the build command in the preferences.
The compiling works fine without error message. As I have problems with upload (I have a STK200 parallel programmer), I use the .hex file that will be generated in the applet folder and upload it separately with AVRDude. At the end, writing is successful, but no reaction on my atmel16....

What can be the problem?
I didn't touch so far the wiring.c file because I hope that maybe the ATmega8 and 16 have the same parameters. No idea....

Although i get no error message with compiling I don't know, if the changes i made, are ok. Especially I don't know if #elseif is correct syntax at all.
I attach you the code of the file. I hope someone can help me to figure out what is wrong. Thanks!

#include <avr/io.h>
#include "wiring_private.h"
#include "pins_arduino.h"

#define PA 1
#define PB 2
#define PC 3
#define PD 4

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint8_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
#if defined(AVR_ATmega16)
&DDRA,
#else
NOT_A_PORT,
#endif
&DDRB,
&DDRC,
&DDRD,
};

const uint8_t PROGMEM port_to_output_PGM[] = {

//NOT_A_PORT,
#if defined(AVR_ATmega16)
&PORTA,

#else
NOT_A_PORT,
#endif
&PORTB,
&PORTC,
&PORTD,
};

const uint8_t PROGMEM port_to_input_PGM[] = {

//NOT_A_PORT,
#if defined(AVR_ATmega16)
&PINA,
#else
NOT_A_PORT,
#endif
&PINB,
&PINC,
&PIND,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 /
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /
8 /
PB,
PB,
PB,
PB,
PB,
PC, /
14 /
PC,
PC,
PC,
PC,
PC,
#if defined(AVR_ATmega16)
PC,
PC,
PA, /
22*/
PA,
PA,
PA,
PA,
PA,
PA,
PA,
#endif

};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D /
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /
8, port B /
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /
14, port C /
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
#if defined(AVR_ATmega16)
_BV(6),
_BV(7),
_BV(0), /
22, port A */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
#endif

};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
// on the ATmega168, digital pin 3 has hardware pwm
#if defined(AVR_ATmega168)
TIMER2B,
#else
NOT_ON_TIMER,
#endif
NOT_ON_TIMER,
// on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(AVR_ATmega168)
TIMER0B,
TIMER0A,
#elseif defined(AVR_ATmega16)
TIMER1B,
TIMER1A,
#else
NOT_ON_TIMER,
NOT_ON_TIMER,
#endif

#if defined(AVR_ATmega16)
TIMER2,
#else

NOT_ON_TIMER,
#endif
NOT_ON_TIMER, /* 8 - port B */
#if defined(AVR_ATmega16)
NOT_ON_TIMER,
NOT_ON_TIMER,
#else
TIMER1A,
TIMER1B,
#endif

#if defined(AVR_ATmega168)
TIMER2A,
#elseif defined(AVR_ATmega16)
NOT_ON_TIMER,
#else
TIMER2,

#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,/* 14 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
#if defined(AVR_ATmega16)
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /*22 port A */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
#endif

};

it works, it works!!! yupi....

There are still some problems with the ports addressing maybe and maybe we have to adjust the interupts for the timer and PWM... but in fact, I have some blinking LEDs here!

;D Welcome Atmega16 ;D

Congrats, well done!

Now, on to Atmega32?

I will check this week if it is really working properly. Until now it´s no more than playing around.
But if it will really work for Atmega16, why not for an Atmega32, too?
The problem is that I am doing no more than "try and error". Maybe someone can give me advice how to go on more sistematically.

Any update on this?

I am still playing around with it.
I realized that there is a mistake in the code of my previous post. Unfortunately I dont find the "edit" option to change this post and update it.
"// NOT A PORT" has to be changed twice in "NOT A PORT". Don't ask me why
I uploaded a small programme to test input and output, and it works fine and with the right ports now. But I still haven´t tested if all ports are really active and what happens with PWM,timer and so on.
I will take a look at it the next days.

You can edit your posts by clicking the 'modify' button at the top of the post (right side of screen).

Thanks for the update!

It seems that the editing of previous posts only is possible for some hours/days.... sorry.
To avoid that this happens again, I have put now all things on my webpage to be able to update it.

I have tried to make a documentation of the modifications I did and made a small sketch of a very basic Atmega16 board for around 5 Euros.

take a look at
http://www.subtours.com/ralph/theory/atmega16witharduino.html

As far as I have tested now, it seems that everything works fine (analog read and analog write (PWM) as well as serial).
Atmega32 should work as well because it has the same pin distribution.

At the end i took away all "if´s" for atmega8 and 168, because it was too confusing. So when you change the files, it only works for atmega16. Save the original files before testing!