Using the AVR Atmega16 with Arduino

Hi, I am trying to basically get Arduino working with an atmega16 micro (as shown here: Welcome! | Ralph Kistler). I am fine with uploading the code with an ISP, as apposed to serial, but I want to be able to write, compile and link the code code (create a hex file basically) in the Arduino IDE.

I found this Ok, on to Atmega32 - Development - Arduino Forum forum relating to the issue, but I haven't been able to make it work. It's also a very old forum now. It looked like a few people had it tested and (sort of) working. I want to find out where the latest version is and how to make it work with (ideally) the latest version of the IDE.

I would start with the mighty-1284P core files, GitHub - maniacbug/mighty-1284p: Mighty 1284P Platform for Arduino
This should be installed in your \sketches\hardware\ folder.

Then add these files to mighty-1284p folders.
\hardware\mighty-1284p\variants\Mega16\pins_arduino.h (see attach below)
\hardware\mighty-1284p\bootloaders\optiboot\optiboot_atmega16.hex (see attach below)

Append these entries to \hardware\mighty-1284p\boards.txt
(or if you will not be using the other entries, you can remove them from this file)

##############################################################

mighty16h.name=Mighty ATmega16 (16MHz)
mighty16h.upload.protocol=arduino
mighty16h.upload.maximum_size=15360
mighty16h.upload.speed=115200
mighty16h.bootloader.low_fuses=0xFF
mighty16h.bootloader.high_fuses=0xda
mighty16h.bootloader.path=optiboot
mighty16h.bootloader.file=optiboot_atmega16.hex
mighty16h.bootloader.unlock_bits=0x3F
mighty16h.bootloader.lock_bits=0x0F
mighty16h.build.mcu=atmega16
mighty16h.build.f_cpu=16000000L
mighty16h.build.core=standard
mighty16h.build.variant=Mega16

##############################################################

mighty16.name=Mighty ATmega16 (8MHz)
mighty16.upload.protocol=arduino
mighty16.upload.maximum_size=15360
mighty16.upload.speed=57600
mighty16.bootloader.low_fuses=0xFF
mighty16.bootloader.high_fuses=0xda
mighty16.bootloader.path=optiboot
mighty16.bootloader.file=optiboot_atmega16.hex
mighty16.bootloader.unlock_bits=0x3F
mighty16.bootloader.lock_bits=0x0F
mighty16.build.mcu=atmega16
mighty16.build.f_cpu=8000000L
mighty16.build.core=standard
mighty16.build.variant=Mega16

Update: changed hfuse to 0xda

optiboot_atmega16.hex (1.44 KB)

pins_arduino.h (4.75 KB)

Then do I just have to go tools->boards->Mighty ATMega16 (16 MHz) and upload the boot loader, or how does it work?

This is kind of an aside, but to program it with an ISP do I need the external crystal oscillator? I would ideally like to run it off the internal oscillator which has a max clock of 8 MHz I think.

Add this to boards.txt:

##############################################################

mighty16.name=Mighty ATmega16 (8MHz, Internal)
mighty16.upload.protocol=arduino
mighty16.upload.maximum_size=15360
mighty16.upload.speed=57600
mighty16.bootloader.low_fuses=0xE4
mighty16.bootloader.high_fuses=0xda
mighty16.bootloader.path=optiboot
mighty16.bootloader.file=optiboot_atmega16.hex
mighty16.bootloader.unlock_bits=0x3F
mighty16.bootloader.lock_bits=0x0F
mighty16.build.mcu=atmega16
mighty16.build.f_cpu=8000000L
mighty16.build.core=standard
mighty16.build.variant=Mega16

Update: changed hfuse to 0xda

Then select from tools->boards->Mighty ATmega16 (8MHz, Internal)
Then burnbootloader to set the fuse bits correctly.(Even though you will not be using the bootloader to upload, you need to set the fuses using this step.)
Then you should be able to upload your sketch with File->Upload using programmer.

Thanks! That seems to have done the trick. How did calculate the high and low fuses with the internal RC oscillator though? I can't see how you set the values for the clock speed and source from the tables on pages 260 and 29 of the data sheet.

Check out AVR® Fuse Calculator – The Engbedded Blog

Ok, doesn't that mean the clock is only 2 MHz though (not 8 MHz)?

"0" means programmed, box checked.
"1" mean un-programmed, box unchecked.

yes, but when I put the hex values into fuse calculator it shows a 2 MHz clock, that's what I'm confused about. It would have to be 0xE4 for the low fuse, right? (i.e. to get the bit values 0b0100 into the lower part of clock register, which the data sheet shows as the 8 MHz setting)

Sorry, was a typo. It should be 0xE4.

TopDog101:
Hi, I am trying to basically get Arduino working with an atmega16 micro (as shown here: Welcome! | Ralph Kistler). I am fine with uploading the code with an ISP, as apposed to serial, but I want to be able to write, compile and link the code code (create a hex file basically) in the Arduino IDE.

If you edit your "boards.txt" file you can make the IDE upload via a programmer instead of serial.

Look at the entry for ATiny85 (or whatever) for an example of a chip with no serial port/bootloader and copy it then change the chip type, clock frequency, etc.

Or just hold down the shift key when you upload, it uses the ISP programmer for upload.

I've been going through the changes needed to make the atmega16 work with Arduino, but I don't understand all of it. Could you elaborate on how you created the pins_arduino.h file and the modifications needed with boards.txt? Where there any changes made to the opiboot bootloader?

I have tried to use the atmega16 as a baseline to make Arduino work with with a atmega32u2 chip I have (similar to the project: http://www.mattairtech.com/index.php/development-boards/atmega32u2-usb-development-board-arduino-compatible.html). I tried the CDC bootloader, but I can't see anything on my computer when I try and enter DFU mode (device manger updates/refreshes but doesn't show anything new). Why would this be the case?

An ATmega32U2 is very different than the ATmega16. I would recommend looking at Leonardo designs for examples. The Leonardo uses an ATmega32U4 which has a little more features than the 32U2.

hiduino:
I would start with the mighty-1284P core files, GitHub - maniacbug/mighty-1284p: Mighty 1284P Platform for Arduino
This should be installed in your \sketches\hardware\ folder.
...

thx a lot, I was just wondering what it'd take to arduinize some old atmega16a in the junk box and that did the trick

would you happen to know what it take for some truly ancient at90s2313 and/or at90s4414 ?

rc3105:
would you happen to know what it take for some truly ancient at90s2313 and/or at90s4414 ?

Well, the AT90S2313 has been replaced by the ATtiny2313, so it might be able to use some core code from the tiny2313. You might have to modify the core code to support the AT90S2313. The main difference would be some lack of timer features that the tiny2313 has. The AVR tool chain and avrdude does appear to have support for the AT90S2313, so you would be good there.

For the AT90S4414 seems to be replaced with the ATmega8515. Can't find any documentation about the differences. The AT90S4414 is not similar to anything else, but there is support for it in the AVR tool chain and avrdude. So you may be able to get it working with the same core for the mega16. Just know that it does not have any ADC and limited timer support. Lookup the ATmega8515 for feature support.

ver 022 of the arduino ide has a boards.text entry for the 8515 (the 4414's genius evil twin) which works nicely with a few tweaks

I suspect at90s2313 support will come from tweaking the attiny2313 profile

Hi. I just uploaded the bootloader to the ATMega16 and I successfully uploaded the blink sketch using an FTDI adapter. But when I wanted to upload a new sketch it did not upload. So i reburned the bootloader and I again was successful in uploading the sketch. But again I could not upload another sketch. Why is it that only one time upload is possible?

It sounds like the auto-reset circuit is not working correctly, or possibly the fuse bit settings are not set correctly.

The reset circuit is working properly as I see the LED blinks for a small time so I don;t think it is the reset circuit.
The fuse bits are 0xFF for the LOW and 0xD9 for the HIGH
Should I change the Lockbits? According to the post in the beginning the Lock Bit is 0x0F but mine is 0xFF. But I am afraid of changing it because I can make the chip Read only.

See page 259
http://www.atmel.com/Images/doc2466.pdf

0x0F is partially unlocked. 0xFF is fully unlocked - there are 2 extra non-existing lock bits will read back as 1's.
7 - not used
6 - not used
5 - BLB12
4 - BLB11
3 - BLB02
2 - BLB01
1 - LB2
0 - LB1

BLB12, BLB11 = 11 = No restrictions for SPM or LPM accessing the Boot Loader
section.
BLB02, BLB01 = 11 = No restrictions for SPM or LPM accessing the Application
section.
LB2, LB1 = 11 = No memory lock features enabled.