Go Down

Topic: Using the AVR Atmega16 with Arduino (Read 7779 times) previous topic - next topic

TopDog101

Hi, I am trying to basically get Arduino working with an atmega16 micro (as shown here: http://www.subtours.com/ralph/theory/atmega16witharduino.html). 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 http://forum.arduino.cc/index.php?PHPSESSID=0neot70puan42qbtnniko46qu6&topic=24073.0 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.

hiduino

#1
Jun 20, 2013, 02:02 pm Last Edit: Dec 31, 2013, 06:05 am by hiduino Reason: 1
I would start with the mighty-1284P core files, https://github.com/maniacbug/mighty-1284p/
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)
Code: [Select]

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

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

TopDog101

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.   

hiduino

#3
Jun 21, 2013, 08:59 pm Last Edit: Dec 31, 2013, 06:06 am by hiduino Reason: 1
Add this to boards.txt:
Code: [Select]

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

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.

TopDog101

#4
Jun 23, 2013, 02:01 pm Last Edit: Jun 23, 2013, 02:13 pm by TopDog101 Reason: 1
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.


TopDog101

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

hiduino

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


TopDog101

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)

hiduino

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


fungus


Hi, I am trying to basically get Arduino working with an atmega16 micro (as shown here: http://www.subtours.com/ralph/theory/atmega16witharduino.html). 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.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

TopDog101

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?

hiduino

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.


rc3105


I would start with the mighty-1284P core files, https://github.com/maniacbug/mighty-1284p/
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 ?

hiduino


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.

Go Up