Return to previous page.
Arduino and ATmega1284(P) Problem Issues

1. Lack of 1284 Support in Arduino Libraries
2. 1284 Bootloaders
3. Board Variants
4. 1284 Library Installation
5. ATmega1284 Chip vs 1284P
6. RX0 and Sketch Uploading Problems
7. 1284 Fuse Settings
8. Arduino Forum 1284 Threads
9. Bobuino Variant Library Errors
10. Misc IDE Files and Libraries Checked for ATmega1284(P) Support
11. Miscellaneous Issues

There are several issues involved with getting the Arduino environment to work with ATmega1284 and 1284P chips, including:

  • lack of support for ATmega1284 chips in the standard Arduino libraries.
  • different bootloader versions.
  • errors in the library files for the most commonly used 1284 bootloaders.
  • problems with uploading sketches to the 1284 chips.

This page has been compiled after many months of work with ATmega1284 and 1284P chips, and many hours spent on the Arduino Forum troubleshooting these problems, in conjunction with other forum members.

1. Lack of 1284(P) Support in Arduino Libraries

For some reason, Arduino central command didn't include support for ATmega1284(P) chips in the libraries that come packaged with the Arduino IDE. These libraries can be seen by opening the IDE "File > Examples" menu, and include: EEPROM, Ethernet, LiquidCrystal, SD, Servo, on and on.

The fix for this problem is "relatively" simple, because the 1284 and 1284P chips have a similar port assignment to the ATmega2560 and 1280 chips. So, the procedure is:

  1. find the specific Arduino library in the IDE directory, eg in path:

  2. look through the source files in the directory, and also any subdirectories, for lines such as:
    #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
      inline static void initSS()    { DDRB  |=  _BV(4); };
      inline static void setSS()     { PORTB &= ~_BV(4); };
      inline static void resetSS()   { PORTB |=  _BV(4); };
    and simply add the 1284P extension to the header (call this Fix #1):
    #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
      inline static void initSS()    { DDRB  |=  _BV(4); };
      inline static void setSS()     { PORTB &= ~_BV(4); };
      inline static void resetSS()   { PORTB |=  _BV(4); };

  3. note also that a more comprehensive version of Fix #1 is shown in the "Arduino.h" file of IDE version 1.0.5:
    #if  defined(__AVR_ATmega1280__)  || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__)
      || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__)  || defined(__AVR_ATmega644A__)
      || defined(__AVR_ATmega644P__)  || defined(__AVR_ATmega644PA__)

So, anytime one of the Arduino IDE libraries is used, or a 3rd party library is installed for use with the 1284(P) chips, all of the .cpp and .h source files in the library should be immediately examined to see whether they need the change described here.

Also, see item 10. Misc IDE Files and Libraries Checked for ATmega1284(P) Support, below.

2. 1284(P) Bootloaders

The most commonly used bootloader for 1284(P) is maniacbug optiboot with 16 Mhz crystal, having file name "optiboot_atmega1284p.hex". The same library also contains the older bootloader files "ATmegaBOOT_1284P.hex" and "ATmegaBOOT_1284P_8MHz.hex", which include firmware for both 16 and 8 Mhz operation.

Other bootloaders for 1284(P) chips can also be found on the internet, including for 20 Mhz operation, as well as firmware for ATmega644 and Reprap devices, but they're not considered here.

3. Board Variants

In the maniacbug library, there are several different board variants which use the exact same bootloader firmware, and have names like "Mighty 1284p 16MHz using Optiboot", "avr-developers.com pinouts 16MHz using Optiboot", and "Bobuino", and all three of which use optibootloader file "optiboot_atmega1284p.hex".

The difference between these board variants relates to how the port pins (eg PB0..PB7, PC0..PC7, &etc) of the chip map into different Arduino "functional pin numbers" (ie D0..D13 and A0..A7), and this info is not burned into the chip with the bootloader. Rather, this remapping is taken care of by selecting a particular board in the IDE "Tools > Board" menu when sketches are compiled, and then the appropriate "pins_arduino.h" (pin remapping) file is used.

A typical entry in the boards.txt file in the maniacbug library directory is as follows. It has info on: "name" of the board variant, protocol for "uploading" sketches using the avrdude utility, which "bootloader" is used by the particular board variant, and finally, information used when compiling ("building") sketches for the variant.


mighty_opt.name=Mighty 1284p 16MHz using Optiboot





The variant shown uses the "optiboot" bootloader running at 16 Mhz on the ATmega1284P chip, and a so-called "standard" pin remapping, as detailed by the "pins_arduino.h" file in the variant's file directory. Notice also, that the processor fuse settings are specified here, and not in the bootloader file itself, and these are the values burned into the chip when the bootloader firmware is burned. To change any of the fuse settings involves re-burning the bootloader into the chip.

Typically, the same board variant will be selected when uploading sketches as was used when the bootloader was burned into the chip.

See the section below on errors in the Bobuino variant files of the maniacbug 1284P library. This variant was added after-the-fact by maniacbug, and has several errors that have not been fixed as of June 2013.

4. 1284 Library Installation

Although some people mistakenly install 3rd party libraries in the main Arudino IDE directory, the proper place is actually in the Arduino sketch directory. This way, new versions of the IDE will always be able to immediately find the 3rd party libraries. See Installing Additional Arduino Libraries page for exact details. Your Arduino sketch directory should end up with a subdirectory as follows:

  1. "c:\user_directory\Arduino\hardware\mighty-1284p-master", where "user_directory" will
    be as assigned for your PC.

  2. Note also - that some 3rd party libraries use '_' (underscores) rather than '-' (dashes) in their
    names, and the Arduino IDE does not seem to like this.

  3. furthermore, some 3rd party libraries seem to install one-level down too far in the subdirectory,
    and the files need to be moved up a level. Library files should reside at the next level down
    from ..\hardware, per above.

5. ATmega1284 Chip vs 1284P

The maniacbug library was written specifically for the ATmega1284P chip. However, the same bootloaders also work for the 1284 (non-P) chip, but we found that we needed to follow the following steps to use the 1284 chip with the maniacbug library and the Arduino environment:

  1. to burn a bootloader into a 1284 chip, the chip signature in the avrdude.conf file must be changed
    from that for the 1284P chip = "0x1e 0x97 0x05" to that for the 1284 chip = "0x1e 0x97 0x06".

  2. for IDE v.1.03, this file is located in the Arduino IDE directory in path:
    - "c:\...\arduino-1.0.3-windows\arduino-1.0.3\hardware\tools\avr\etc".

  3. then, the bootloader is burned by selecting one of the maniacbug board variants
    in the IDE "Tools > Board" menu.

  4. then, following bootloader burn, the signature in avrdude.conf must be changed back
    to that for the 1284P chip before uploading sketches to the 1284 (non-P) chip.

This scheme allows the 1284 chip to be used interchangeably with the 1284P with any of the maniacbug board variants, simply be selecting the variant in the IDE "Tools > Board" menu when sketches are compiled and uploaded.

6. RX0 and Sketch Uploading Problems - History

In the past, many [but not all] people had problems uploading sketches to ATmega1284P bootloader chips in DIP40 package. By default, this process uses hardware UART0, ie the RX0,TX0 pins.

It was common to have communications failures during sketch uploading, and several people referenced an avrfreaks forum thread on how to fix this. This fix involved using an RC low-pass between the FTDI USB-to-RS232 chip and the RX0 pin, with typical values of 1K-10K and 100pF.

Although this solved the comms-sync problem, several people investigated further, and came to the conclusion that the problem was actually related to the fact that the XTAL1 (oscillator input) pin is adjacent to RX0 on the DIP40 version of these chips, and the XTAL1 input was being affected by cross-talk. After some brilliant simulations by Pito, plus further investigations, it was generally decided that the "proper" fix was to change the bootloader Low-Fuse setting from low-power oscillator to full-swing oscillator, thus minimizing the effects of said cross-talk.

Ref section 9.2 Clock Sources, in the ATmega1284(P) datasheet .... to do this, one needs to change the following line in the boards.txt file located in the maniacbug 1284P library files.

  1. for the specific board variant being used, change the following line in the boards.txt file:
    - from: "[variant_name].bootloader.low_fuses=0xFF"
    - to: "[variant_name].bootloader.low_fuses=0xF7"

  2. as described in the 1284 Library Installation section above, this file is located in the
    3rd party hardware directory.

Note, as mentioned above, this change has not been incorporated into the original maniac1284 library, as of June 2013.

7. 1284 Fuse Settings

Related to the previous section, when trying to sort out the jumble of fuse settings for the 1284 or other chips, it helps to jump directly to "Section 27.2 Fuse Bits" of the ATmega1284 datasheet first, and then go back to individual sections, such as "Section 9.2 Clock Sources".

8. Arduino Forum 1284 Threads

For reference, there have been several long threads on the Arduino Forum dealing with these problem. See,

  • Help in programming the Atmega1284 with maniacbug-mighty-1284p - (159 replies).
  • Boards with 1284p - full swing oscillator setting - solving upload issues? - (159 replies).
  • Problem with using Bobuino 1284 bootloader as ArduinoISP - (8 replies).
  • funny A/D channel readings with Bobuino-1284 ??? - (46 replies).
  • ATmega1284P: End to End using 1.0 IDE - (579 replies).
  • Issue with Mighty 1284P Optiboot bootloader on STK500 - (25 replies).

    There are also related threads on the avrfreaks forum.

    9. Bobuino Variant Library Errors

    There are several errors in the "pins_arduino.h" file for the Bobuino board variant of the maniacbug library, but as of June 2013, these had not been fixed. This file is located in the maniacbug library in the "\variants\bobuino" subdirectory. The following information was posted to github in February 2013, see Issue #4.

    Errors in Bobuino pins_arduino.h
    There are 4 problems in referenced file.
    First, the following line should be changed to the one below:
    #define analogPinToChannel(p) ( (p) < NUM_ANALOG_INPUTS ? NUM_ANALOG_INPUTS - (p) : -1 )
    #define analogPinToChannel(p) ( (p) < NUM_ANALOG_INPUTS ? (NUM_ANALOG_INPUTS-1) - (p) : -1 )
    Secondly, the following line produces a compile time error if you try to upload the
    ArduinoISP sketch into a mighty-1284P bootloader chip using the Arduino IDE 
    with Board selection = Bobuino.
    extern const uint8_t digital_pin_to_timer_PGM[NUM_DIGITAL_PINS];
    It should be removed, or else the line ... #include "pins_arduino.h" ... should be
    removed from the ArduinoISP sketch itself.
    Thirdly, the line of item 2 also does not match the array being referenced, ie
    const uint8_t PROGMEM digital_pin_to_timer_PGM[NUM_DIGITAL_PINS] = {...}
    Fourthly, it also does not match the associated line in Arduino.h in the IDE directory:
    extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

    The first error causes the A/D channel values, 0..7, to be assigned to the wrong pins. The second error is related to some change which wasn't uniformly made throughout every file used when the IDE was upgraded from the older versions 0022, and earlier, to the newer 1.0.x versions. The last two errors are simple inconsistensies between assignments located in different file locations.

    10. Misc IDE Files and Libraries Checked for ATmega1284(P) Support

    The following files in Arduino IDE version 1.0.5 have been checked for ATmega1284(P) support. There may also be some support in earlier versions of the IDE, but those are not dealt with here. These files are in the ArduinoCore ".\hardware\arduino\cores\arduino" subdirectory in the Arduino IDE.

    • "Arduino.h" = ok ... since 1284(P) support has been included in IDE v1.0.5.
    • "Client.h", "IPAddress.h", and "IPAddress.cpp" files = ok ... no direct references to cpu types.

    NOTE - the "Arduino.h" file in newer versions of the IDE have support for several different ATmega1284(P)and ATmega644(P) chips, as indicated above, in regards Fix #1.

    Also, the very end of "Arduino.h" has a < #include "pins_arduino.h" > statement, so it will automatically handle different board variants with different pinouts.

    We also checked the following standard Arduino libraries, found in IDE subdirectory "\libraries" :

    • SPI library = ok ... since SPI.cpp references only "pins_arduino.h", the SPI pin callouts are
      taken care of in the specific 1284 variant being used.
    • EEPROM library = ok ... no cpu references.
    • SoftwareSerial library = ok ... no cpu references.
    • Wire library = ok ... references only "Arduino.h" and "pins_arduino.h".

    • Ethernet library = needs fixing ... as of IDE v.1.0.5, file "w5100.h" still requires Fix #1 listed above.
    • Servo library = needs fixing ... file "Servo.h" requires Fix #1 listed above
    • SD library = needs fixing ... both "S2dCard.h" and "Sd2PinMap.h" require Fix #1 listed above,
      plus the latter file requires more serious attention.

    We've also checked the following 3rd party libraries for ATmega1284P support:

    • Xively library = ok.
    • HttpClient library (used with Xively) = ok ... references "Arduino.h", "Client.h", and "IPAddress.h",
      which are all ok, per checks listed above.
    • Twitter library = ok ... references "Ethernet.h" and "EthernetDNS.h", which are ok, as long as
      "w5100.h" is fixed as indicated above.
    • Time library (used by Twitter) = ok.
    • Sha library = ok.

    • LowPower Labs RF12 library (used with Hope RFM12 modules) = works ... includes
      Sanguino/644 support (but totally NFG for Bobuino variant).
    • Mikem RFM22 library (used with Hope RFM12 modules).
    • maniacbug nRF2401 library = ok ... uses only references to "Arduino.h" and "SPI.h".

    • ElecFreaks ColorLCD library = needs fixing ... file "ColorLCDShield.cpp" requires Fix #1
      listed above (note - this fix also applies to the Sparkfu ColorLCDShield library).
    • Jeelib library (used with Hope RFM12 modules) = has so many bugs we don't use it.

    11. Miscellaneous Issues
    [needs editing!!]

    <| TOP

    © OT-Hobbies, revised Oct 2013, orig May 2013