Monday, March 26, 2012

Wise Clock 4 with ATmega1284

I thought that replacing the ATmega644P with its bigger brother ATmega1284P in Wise Clock 4 would be trivial. How wrong I was.

The first step was to burn the bootloader. After a bit of research, here is what I found out:
  • USBtinyISP from adafruit cannot program chips with more than 64K of flash (see this thread);
  • if you don't want to start from scratch (that is, compile the source code and figuring the fuses) there are at least 3 sources: ryanmsutton, maniacbug and calunium;
  • USBtinyISP half-works: it writes to the flash, but reading back for verification purpose fails because of a bug in the firmware; I ignored the verification error;
  • although burning the bootloader (any of the three mentioned above) seemed successful, uploading any sketch afterwards always failed;
  • the setup from ryanmsutton did not work for me (I guess the fuses are wrong; then the core files also point to the arduino folder, instead of the sanguino, as it should be);
  • with the bootloader from calunium (atmega1284p_16MHz.hex) I was able to upload sketches; these are the settings in boards.txt I used: W/ ATmega1284p 16mhz

Note the upload protocol (stk500v1), note the fuses and note the core folder (last line).
  • in the end, since the booloader from calunium worked for me, I did not try the one from maniacbug, which (from what I read on the forum) seems to be very popular and work very well;

To compile the code for Sanguino with ATmega1284P, some macros must be updated as well, by adding
defined(__AVR_ATmega1284P__)  to any defined(__ATmega644P__)

like this:

#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__) // sanguino

In the end, the program space is about 126K (compared to 62K in ATmega644P) and the available RAM is 16K (compared to only 4K in Atmega644P). Not a bad upgrade for only a few bucks more.

Note: ATmega1284 is not defined in avrdude.conf shipped with Arduino 22 or 23 (folder \arduino-22\hardware\tools\avr), but it is defined in Arduino 1.0.


  1. It´s not better run it at 20Mhz?

  2. Maybe, but there may be some other implications (e.g. millis()).
    It's worth an investigation though.

  3. Florin,

    Will there ever be a way to compile WiseClock3/4 without having to use the Sanguino hack? By using one of the boards listed in the Boards.txt file. The reason I ask is that I've started using Eclipse and the latest Arduino plugin requires that you use Arduino 1.5.x. Unfortunately, 3rd party cores (Sanguino) are not yet supported without a lot of hacks.

    Needless to say, WiseClock3/4 won't compile with Arduino 1.5x unless I choose a 2560 or 1280 board, which of course can't be uploaded to the 644. But, I'm still working on it!


    1. Hi Kenny,
      For some reason, Arduino never officially supported the Sanguino board. So, for as long as that happens, we will need to use the "hack".
      The good thing is that the hack is pretty simple and straightforward. In essence, like with the officially supported boards, you only need a "core folder" with the sanguino files and one section in the boards file. With this structure in place, there should not be differences (when compile and upload) between an official Arduino board and Sanguino/Wise Clock 4.
      One day I may try compiling in Eclipse myself too.

    2. Did you ever get this to compile and load with 1.53 or .54


    3. No. I only used Arduino IDE 1.0 and 1.0.4.