Pages: [1]   Go Down
Author Topic: Arduino for ATMEGA16 40pin  (Read 4648 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an old STK200 programmer with the ATMEGA16 40 Pin package that was given to me and I would like to use it in the Arduino environment. I have got it so that it will upload the boot loader by changing
  • upload.using=parallel in the preference file
  • Creating a new entry in boards :
    Code:
    ##############################################################[/li][/list]

    atmega16.name=ATmega16

    atmega16.upload.protocol=pony-stk200
    atmega16.upload.maximum_size=14336
    atmega16.upload.speed=19200

    atmega16.bootloader.low_fuses=0xff
    atmega16.bootloader.high_fuses=0xdd
    atmega16.bootloader.path=atmega168
    atmega16.bootloader.file=ATmegaBOOT_168_ng.hex
    atmega16.bootloader.unlock_bits=0x3F
    atmega16.bootloader.lock_bits=0x0F

    atmega16.build.mcu=atmega16
    atmega16.build.f_cpu=16000000L
    atmega16.build.core=arduino
    I assume a lot of this is wrong smiley-wink
  • parallel.protocol=pony-stk200 in programmers.txt

I also had to fiddle with some preprocessors in the hardware/cores/arduino to get it to compile. Which I know some of what I put down was incorrect so I won't post it here right now. I would like to work and help someone to port this micro to the Arduino platform as this chip has more pin i/o and 2 extra analog i/o which I could use.

The chip information can be found on avrfreaks.

N.B please no responses about buying the right equipment, this is about having a challenge and providing the information back to the code base.  smiley

Regards
Andrew
Logged

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

the Chip information is here : http://www.avrfreaks.net/index.php?module=Freaks%20Devices&func=displayDev&objectid=56
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the bootloader work with the atmega16?
I use an atmega32 and it did not work, so I had to burn a modified version... And I guess that if you replace mega8 by mega16 in all source files and of course edit the arduino_pin.c the atmega16 can be used.

The mega32 works fine, but PORTC has some issues.
Logged


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

Yes the bootloader will write to the ATMEGA16. But since the programmer I have is parallel only I can only upload the code - I don't have anything to check if it is working correctly smiley. What issues did you have with PORTC?

I just had a look at the Sanguino code for the 644 and while not the same chip it has almost the same pin i/o's. I'm going to look as what is different between to 2 and see if I can adapt it to work. It would be nice if the Sanguino code was put in the standard code base smiley

I will try this tonight and report back to see how I go.
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PORTC does not work at all on my mega32. And I am sure that I ported the core correctly. Maybe my chip is broken, because all other ports work as they should.

I do not really understand what you mean by this:
Quote
But since the programmer I have is parallel only I can only upload the code - I don't have anything to check if it is working correctly
Did you upload a blink example to your mega16? Or are you not sure if your bootloader is running on the chip?

Don't forget to set the fuses and lock bits... And the Arduino bootloader is very big - I wonder if it fits into the (1024 words small) bootspace of the mega16?
Logged


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

Did not get a chance to check Sanguino code last night - will hopefully get to it tonight smiley

Sorry wasn't clear on the parallel bit  - I can upload to the ATMEGA16 various code examples in the Arduino Software with no problem over the stk200 via the computer parallel port. When I set the verbose in the preference file for uploading it all looks and verifies ok. I'm just not sure if it is working though as I haven't attached any outputs (i.e LEDs) yet to the ATMEGA16 because I know the pins don't match, and I'm being cautious... smiley

To be honest I don't understand the fuses and lock bits correctly. I know I removed the extended fuse preference from boards.txt to make it work. It was a guess and I really didn't know what I was doing.

I noticed in the C preprocessing there is stuff for __AVR_ATMEGA8. If I was to put in my own preprocessing for the ATMEGA16 is there any difference for the 16 vs the 168 chips? and what would they be? I might look into the AVR GCC code to see if I can see a difference.
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

simply replace ALL __AVR_ATMEGA8 by __AVR_ATMEGA16

this should work, because they are one family (with the mega32). The mega168 is a different story...

the pin mapping can be found in pins_arduino.c
look what pin 13 is. If you use this file from the arduino core then pin 13 is PD7. Look in the datasheet and connect an LED (with resistor) to this pin (PD7) and try the Blink sketch... should work.


« Last Edit: March 24, 2009, 07:26:17 pm by bohne » Logged


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

Ok I got the ATMEGA16 setup for arduino smiley I think there are still some issues with it and I'm going to be testing each pin as much as I can tonight to make sure they do what they are supposed to do.

In the end I based it of the Sanguino core and modified that to match the ATMEGA16 and then compiled and tested it. Unfortunately I don't have the code on me now to post  - And I'm not sure where to upload it in any case smiley-sad

Bohne thanks for the tip regarding preprocessors I thought that was the case and you just confirmed it for me smiley And yes I now have a led blinking at me.

I am going to test each of the pins and then I'm going to try and get the STK200 4 Bit LCD going. There is some code around for that so I'm going to try what I can to get it going.
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

great.

when you tested your code we can think about releasing a core that supports mega16 and mega32 if you want. Right now I am very busy (LumiNet) but in a few weeks we can try to work on this core if you want.
Logged


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

General update : I now have the LCD going using  pins PC2-7. I tried using the Liquid Crystal and then LCD4Bit libraries and neither of these seem to work. I then tried another piece of 4Bit library from these forums and that seems to work just fine!

I'm now able to get on with my coding and see the debugging on my screen smiley
Logged

Pages: [1]   Go Up
Jump to: