Pages: [1] 2   Go Down
Author Topic: Using the AVR Atmega16 with Arduino  (Read 6221 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
##############################################################

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 - downloaded 291 times.)
* pins_arduino.h (4.75 KB - downloaded 316 times.)
« Last Edit: December 31, 2013, 12:05:15 am by hiduino » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.   
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Add this to boards.txt:
Code:
##############################################################

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.
« Last Edit: December 31, 2013, 12:06:00 am by hiduino » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 23, 2013, 07:13:15 am by TopDog101 » Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Check out http://www.engbedded.com/fusecalc

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5522
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

central Texas
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Riley
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Wahiawa, Hawaii
Offline Offline
God Member
*****
Karma: 29
Posts: 600
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2   Go Up
Jump to: