Bootloading ATMEGA328P-PU with Optiloader

Hi Guys,

First post so excuse me if my terminology is off.

I'm new to Arduino and have been tinkering around getting ready to start a few pet projects. At the moment i'm gearing up to make some standalone arduino's.

I have purchased a few ATMEGA328P-PU microcontrollers (See here for item details) and the seller notes that the microcontrollers are pre loaded with the optiboot bootloader. However they also note that in order to write to these microcontrollers I need to burn them.

Taking a step back and please correct me if I'm wrong but if they are preloaded with optiboot are they not already burnt?

Regardless I figured I may as well learn how to burn them myself and have researched Optiloader and loaded it onto my programmer.

I have setup my Arduino Mega as the programmer and on my breadboard I have wired up everything as per this link.

However when I run the sketch and look at the serial monitor all I get is this.

OptiLoader Bootstrap programmer.
2011 by Bill Westfield (WestfW)

Target power on! ...
Starting Program Mode

It never progresses past this and seems to do nothing. Any idea where I could have gone wrong, I have checked my wiring a few times and everything seems right, the power light is on but no life from the TX or RX LED's

Does your breadboard have the crystal and caps as well? It needs them.

if they are preloaded with optiboot are they not already burnt?

Yes, I would think so.

westfw:
Does your breadboard have the crystal and caps as well? It needs them.
Yes, I would think so.

Hi WestFW,

Yes the crystal and caps are in there as well.

Thats my setup at the moment.

The image is broken. Please post a new one.
The wiring
for a MEGA and a UNO to burn a bootloader is entirely different.
Upload ArduinoISP in the examples in Arduino IDE to your mega.
Modify the following pin connections,Leave everything else as it it.

pin name: mega Atmega 328P
slave reset: 53 1
MOSI: 51 17
MISO: 50 18
SCK: 52 19

Then go to IDE,Select the board as Arduino UNO,Programmer Arduino as ISP and then click burn bootloader.
Greetings,
-Malhar

for a MEGA and a UNO to burn a bootloader is entirely different.

Ah; I didn't notice that you're using a MEGA. I wouldn't expect that to work :frowning:
Malhar's ideas might work, applied to optiloader as well as arduinoISP...

Hi Guys,

Yes after reading a little more i realised the pin map was completely different.

MalharD:
The image is broken. Please post a new one.
The wiring
for a MEGA and a UNO to burn a bootloader is entirely different.
Upload ArduinoISP in the examples in Arduino IDE to your mega.
Modify the following pin connections,Leave everything else as it it.

pin name: mega Atmega 328P
slave reset: 53 1
MOSI: 51 17
MISO: 50 18
SCK: 52 19

Then go to IDE,Select the board as Arduino UNO,Programmer Arduino as ISP and then click burn bootloader.
Greetings,
-Malhar

Malhar,

I used the method you have suggested and get the following feedback

Arduino: 1.6.8 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Program Files\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM6 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m 

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM6
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Error while burning bootloader.
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0xff00ff
avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.

Any idea why the signatures are wrong.

Here is the amended setup.

As the error says, please check the connections.
Can you post a photo of the circuit ?
Is the crystal attached ?
Try removing the two caps attached to the crystal.

MalharD:
As the error says, please check the connections.
Can you post a photo of the circuit ?
Is the crystal attached ?
Try removing the two caps attached to the crystal.

Crystal is attached, have tried removing the two caps, no real change, slightly different signature same error code

Is +5v connected to pin 7 and Pim 8 to to GND ?
Connect pin 20 to VCC and pin 22 to GND.
Try connecting a 100u capacitor to +5v and GND.
Power the mega with external supply.
Can you post a photo ?

I don't see a GND connected to pin 8.
That may be the problem.

MalharD:
Is +5v connected to pin 7 and Pim 8 to to GND ?
Connect pin 20 to VCC and pin 22 to GND.
Try connecting a 100u capacitor to +5v and GND.
Power the mega with external supply.
Can you post a photo ?

Ok everything has been connecting except the 100uf capacitor, I dont have any at the moment (awaiting to arrive). All i got is a few 10uf.

The Mega is powered through the USB serial. Correct me if im wrong.

Grd is there to pin 8 (far right white wire)

Current error

avrdude: Device signature = 0xff7fff
avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.

Two or three 10u wil do.
Try removing the two 22p caps.
I was unable to bootload to some of my chips with those caps connected
Try connecting external supply to the mega

MalharD:
Two or three 10u wil do.
Try removing the two 22p caps.
I was unable to bootload to some of my chips with those caps connected
Try connecting external supply to the mega

Thanks for your ongoing support.

three capacitors used still no luck. Also removed the 22p caps and added external power.

I swapped out the microcontroller and the signature went to 000000, from reading WestFW's posts I figured this is due to the controller not sitting right in the breadboard. Played around with it and the signature went back to 0x7f007f.

Given these chips are ATMEGA328P-PU's do I need to change the avrdude.config file or is that just for the ATMEGA328P

No, you don't need to change anything in avrdude.conf.
I suspect that the chip or the crystal is faulty.

No worries I'll change out the crystal and I've contacted the buyer for instructions. A mate has my multimeter at the moment but I'll check the circuit again with that.

Given these chips are ATMEGA328P-PU's do I need to change the avrdude.config file or is that just for the ATMEGA328P

PU means only package type DIL (AU, PU, MUR). It is ATmega328P. Do not change config file.
You definitely need 22p caps from XTALs to GND. Switch on detailed log in IDE preferences. Check your wiring. It seems to be badly connected something, broken wire etc. Also, you can check the clock signal if it is present, simply with the DMM. The voltage about 2.5V DC on XTAL1 pin indicates that it is oscillating.

You definitely need 22p caps from XTALs to GN

I have 5 boards which do not work when 22p caps are connectd. However, everyone says those are necessary.

Hmm, I have no such experience. For me, it works exactly as is described in the datasheet. Capacitance depends on the crystal properties but the value is not critical, something between 12-22pF. However, I can imagine that it works without the capacitors. I've built many of these Arduino clone with ATmega1284P and similar, always with the capacitors.