Uploading Sketches to ATMEGA324p using MEGA

I want to burn a bootloader to an ATMEGA324p (I changed my mind since the previous topic). I have tried the 1284p bootloader (GitHub - maniacbug/mighty-1284p: Mighty 1284P Platform for Arduino), adapted to the 324p (ATmega324P 1.0 IDE - Microcontrollers - Arduino Forum). After changing the lock and bits to values that made avrdude stop complaining about them, double checked my wiring, and much frustration, all I get is:

avrdude stk500_getperm(): (a) protocol error. expect=0x14, resp=0x14
avrdude: stk500_getperm(): (a) protocol error. expect=0x14, resp=0x10
avrdude: stk500_initialize(): (b) protocol error. expect=0x10, resp=0x01
avrdude: initialization failed. rc=-1
     Double check connections and try again, or use -F to override this check.
avrdude: stk500_disable(): protocol error. expect=0x14, resp=0x10

Then, I tried using what was done at http://www.avrfreaks.net/forum/atmega324p-sanguino-bootloader-0023r4 using the bootloader.zip file at the very bottom of the page. STILL NO SUCCESS.

I am 100% certain everything is wired correctly, I have quadruple-checked everything. Where can I get a bootloader file that works for the 324p, and how can I configure it?

What are you using for a Programmer?

An Arduino Mega r3 with the ArduinoISP sketch.

EDIT: For details, I am using Debian to use Arduino and avrdude.

Ah. I only have Windows/Arduino IDE experience. Sorry.

I haven´t done it yet, however I´m researching since probably I fried my ATmega328, so this might help:

If you bought a new microcontroller, you can burn the bootloader in different ways. The easiest way (in my opinion) is getting an ISP Programmer, like the AVRISP:

Like I said, I have no experience doing this however it seems fairly easy since you only have to plug the ISP programmer to you computer (via USB) and the other side goes to the 2X3 pins - de one ones next to the microcontroller (via a 6-pin cable).

Then, in the Arduino IDE go to TOOLS -> Programmer -> AVRISP mkII (I believe this one is for the second version of the AVR programmer).

Then burn the bootloader, once everything is connected.

This is in theory, based on my research. If my ATmega328 is in fact fried, I´m going to do this for sure so I´ll let you know about my experience.

The other ways to get this done are longer and a bit more complex, like making your own ISP programmer with a breadboard (if you wanna go full hacker):

Best regards!

Please note that AVR ISP MKii does not provide power to Pin 2, it only monitors the pin and sets its IO levels accordingly.
Don't need much to power a device tho - I've used a 3xAA or 3xAAA battery pack connected to pins 2 and 6 if my circuit did not include a power source.

MISO 1 2 VCC
SCK 3 4 MOSI
Reset 5 6 GND

MKii Will program all the Atmel chips tho, while some programmers will not work correctly with 128K and 256K flash memory chips.

I have never seen a "AVR ISP MKi" in my 4+ years of Arduino-ing (summer 2010).

Yay, back from vacation and snow storm of DOOM.

The tutorial is nice, but I am NOT using a 328. I am using a 324p, a completely different ucontroller from the Arduino Uno. My question is why my attempts towards burning a bootloader are not working.

EDIT: I tried to upload the bootloader using my Windows computer, still 324p with Mega r3 as ISP. Now, I get the error:

Arduino: 1.0.6 (Windows 7), Board: "ATmega324P via Arduino ISP"
avrdude: ERROR: address 0x1fc10 out of range at line 3 of C:\Users\Student\Documents\Arduino\hardware\ATMEGA324p\bootloaders\optiboot\optiboot_atmega1284p.hex
avrdude: read from file 'C:\Users\Student\Documents\Arduino\hardware\ATMEGA324p\bootloaders\optiboot\optiboot_atmega1284p.hex' failed

Verbose: Verbose Errors - Pastebin.com
What do I do now?

Are you trying burn the bootloader for 1284p to 324p? It doesn't work! Address is out of range, of course this one has 32k only. You have to use appropriate bootloader for 324p exactly. You have to build one.

'324P is a smaller memory version of 1284P.
Use these files

and add a boards.txt entry for a '324P chip board.

avrdude.conf already has entries for the 324P:

#------------------------------------------------------------
# ATmega324P
#------------------------------------------------------------

# similar to ATmega164P

part
    id               = "m324p";
    desc             = "ATMEGA324P";
    has_jtag         = yes;
    stk500_devcode   = 0x82; # no STK500v1 support, use the ATmega16 one
    avr910_devcode   = 0x74;
    signature        = 0x1e 0x95 0x08;

Or just go to a 1284P. Part is like a dollar more at mouser.com, but it has way more memory:
164 / 324 / 644 / 1284:
– 16 / 32 / 64 / 128KBytes of In-System Self-programmable Flash program memory
– 512 / 1K / 2K / 4KBytes EEPROM
– 1k / 2k / 4k / 16KBytes Internal SRAM

@CrossRoads: I tried using the bootloader you linked to, still got the same error. Is there any way to recompile the .hex file to be in-range?

Did you update boards.txt for a '324P chip?
Can you post that?
I don't know how to change the bootloader files, I've never dug that deep into the code.

##############################################################

arduino_324p.name=ATmega324P via Arduino ISP

arduino_324p.upload.protocol=arduino
arduino_324p.upload.using=arduino
arduino_324p.upload.speed=19200
arduino_324p.upload.maximum_size=30720

arduino_324p.bootloader.low_fuses=0x3F
arduino_324p.bootloader.high_fuses=0xD2
arduino_324p.bootloader.extended_fuses=0xfd
arduino_324p.bootloader.path=optiboot
arduino_324p.bootloader.file=optiboot_atmega1284p.hex
arduino_324p.bootloader.unlock_bits=0x3F
arduino_324p.bootloader.lock_bits=0xEF

arduino_324p.build.mcu=atmega324p
arduino_324p.build.f_cpu=13500000L
arduino_324p.build.core=arduino
arduino_324p.build.variant=standard

Here are 16MHz and 13.5MHz versions of the optiboot for ATmega324P. I had no chance to test it because of I have no 324P chip so it is up to you. Both are for UART0, LED on B7 and 115200 baud upload speed.
You have to add it into board.txt. Here is for 1.6.0 for ext. xtal:

arduino_324p.name=ATmega324P

arduino_324p.upload.tool=avrdude
arduino_324p.upload.protocol=arduino
arduino_324p.upload.maximum_size=31744
arduino_324p.upload.maximum_data_size=2048
arduino_324p.upload.speed=115200

arduino_324p.bootloader.low_fuses=0xF7
arduino_324p.bootloader.high_fuses=0xDC
arduino_324p.bootloader.extended_fuses=0xfd
arduino_324p.bootloader.path=optiboot
arduino_324p.bootloader.file=optiboot_atmega324p_13.500MHz.hex
arduino_324p.bootloader.unlock_bits=0x3F
arduino_324p.bootloader.lock_bits=0x0F

arduino_324p.build.mcu=atmega324p
arduino_324p.build.f_cpu=13500000L
arduino_324p.build.core=arduino
arduino_324p.build.variant=standard

I hope it is correct.

optiboot_atmega324p.zip (1.96 KB)

Once more here is 512 byte version (previous is 1k). In this case high_fuse = 0xDE, maximum_size = 32256.

optiboot_atmega324p_512b.zip (1.58 KB)

I used the 512 byte version, and it burned! Thanks a lot!

Would you mind telling me the pinout?

EDIT: Trying to upload a 'blink' sketch brought errors for standard Arduino terms:

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "ATmega324P"
Blink.ino:18:21: error: Arduino.h: No such file or directory
Blink.ino: In function 'void setup()':
Blink:20: error: 'OUTPUT' was not declared in this scope
Blink:20: error: 'pinMode' was not declared in this scope
Blink.ino: In function 'void loop()':
Blink:25: error: 'HIGH' was not declared in this scope
Blink:25: error: 'digitalWrite' was not declared in this scope
Blink:26: error: 'delay' was not declared in this scope
Blink:27: error: 'LOW' was not declared in this scope

It also does this with the 1k version.
Can you help me here? Thanks.

Pinout? Just LED is important. It is on B7 and UART0 is used for upload. If you want to change the led pin I could make
another one according your needs.

I am using the diagram @ here.
Would you mind setting the LED so it is on PD5, and the rest of the pins are as shown? I'd appreciate it.

EDIT: By the way, it seems I am missing an Arduino.h file for this, so the GUI has no idea what any of the functions mean. How can I remedy this?

This error has nothing with bootloader I think.It is during compilation, isn't it? You have to create your own variant (pins_arduino.h) at first.
PD5 is not a problem. Frequency? 13,5MHz?

Yes, 13,5 MHz. That's the largest crystal I have at the moment.

How can I create a pins_arduino.h file, and where would I put it?

EDIT: Used the fix at [SOLVED] Custom hardware - pins_arduino.h: No such file or directory - Libraries - Arduino Forum and now it compiles. Problem now is that the red Warning LED on the Arduino ISP setup glows and avrdude complains:
avrdude: stk500_getsync(): not in sync: resp=0x00
I tried resetting the Mega, the 324p, both at once, and just about everything I could think of. I tried connecting 'slave reset' to both SS and RESET on the 324p, that did nothing.

Am I missing something? Is UART0 supposed to be connected to something, and if so, what pin is it on the 324p and to what pin on the MEGA?