Think Create | Deqing Sun

Arduino porting to Atmega48

by on Aug.12, 2010, under My gadgets


Arduino is a fascinating board. It is extremely easy to handle and do quick prototyping. Since it uses AVR-GCC compiler, standard C is also acceptable to maximize its performance. But one problem is, we do not need a large Rom in all case especially to the programs written by C. So some modification can be made to enable Arduino to support cheaper chips. In this time I use Atmega48 because the only difference between the original Atmega328 and the Atmega48 is the flash and sram. The pinouts and the registers are totally the same. So modifications in the sketches are NOT needed.

First I added the Atmega48’s information to boards.txt

I do not use a bootloader in atmega48. The bootloader doesn’t bother in a chip with large flash but it really matters to a chip with only 4K flash. Besides, my Dragon programmer is not supported by Arduino so any programmer besides the bootloader will do.

Then choose the new board and compile the sketch by press the “Verify” button. A hex file will be generated in temp folder. It must be copied before you exit the Arduino IDE because the exiting process will empty the build folder.

The temp folder can be entered in this way.

And the file we need is located in a build folder.

It dose work! I loaded the hex file to a virtual atmega48 and it really blinks!

PS: I will try it with a real Arduino and atmega48 in a few days.

Board.txt: boards

Update:

Hold ”Shift” on keyboard and press “Verify”, Arduino IDE will show the target file’s location.


14 Comments for this entry

  • ast

    I also try it, but analogRead() doesn’t work… Did you have same trouble?

  • seer

    OK, I just simulated the example “Analog input”. First I run the code on a naked AVR it said “[AVR AD Converter] Reference value=0;”. So I opened the IO registers and find ADMUX on 0x7c which read “0x40”. That means it uses AVCC as reference. Connect it to power will eliminate the problem. To real AVR, connect AVCC to power and add a decoupling capacitor between AREF and ground.

  • ast

    thx, man) i have done all like you said, but i get new problem – analogRead(0) doesn’t return analog value on pin 0 (which is 23 pin on atmega48 board)… any suggestions?

    P.S. sorry for my poor english, i’m from russia )))

  • ast

    Also, serial transmit only triangles )))))) baudrate is fine

  • ast

    my bad, i forget, that i use some wiring.c modifications, and analogRead doesn’t work with it.

    But Serial still unaviable

  • seer

    I’m sorry to tell you that there isn’t any problem. I used Arduino Ver 0018. Do you use the chip on your own board and use the internal RC oscillator? If so, change the clock settings in the boards.txt. The factory setting of a mega48 is using 1M clock. Because of the inefficiency of Arduino, I unchecked the CKDIV8 fuse and set the f_cpu in boards.txt to 8000000L.
    I think there might be problems in your modification of the C files. I left them unchanged.

  • Enam

    Thanks!

    That is what i was looking for the last days.
    I didnt think it could be so simple.

    I will try it out.

    Regards, Enam

  • Enam

    Hi

    Why cant you programm the 48 within the Arduino IDE ?

    Does Avrdude in Arduino need a special setup for flashing to the 48 ?

    I tried it, it works !!!
    Seems that it works when you enable option -f for avrdude in a way like here the serial
    http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1221234452

    🙂 Enam

  • Enam

    I’m happy, Analoginput works wit my ATMEGA48PA too !

    Do you know where i can find what to change in Boards.txt for ATMEGA88 ?

    I couldnt get it to work with Arduino until now.

    Regards, Enam

  • seer

    Actually, I use an AVR-DRAGON to program my chips.
    the SIZE should be 8*1024-2=8190 instead of 4094
    then change all 48 to 88
    I guess the fuse settings are similar. Oh, I checked it. It is the same.
    http://www.engbedded.com/fusecalc

  • Enam

    Hi seer

    At the arduino forum (the link in my post) I had a discussion about the “bootloader” fuse settings in the boards.txt

    The conclusion was that fuses would not be set until a bootloader is written, so the factory settings (internal 8mhz , ckdiv8) would stay at 1mhz until you change them manually.

    No problem for me, i know how to change them and i am very happy to be able to programm the ATmega48 within the Arduino IDE.

    Maybe interesting to know for others.

    Regards, Enam

  • seer

    Thanks for sharing the information.

  • alexc

    Hi I’m very interested in programming atmega48 within arduino IDE but I ran into the same problem of the analorgWrite and Read that doesn’t work. The difference is that I’m not familiar with the process you did upthere to make it work, any way you could share a tutorial?

1 Trackback or Pingback for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...