Arduino Forum

Using Arduino => Microcontrollers => Topic started by: NickyG on Apr 10, 2016, 07:20 am

Title: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 10, 2016, 07:20 am
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) (http://www.ebay.com.au/itm/191275641504?euid=d2dd83a6d3884dae8a4cbe906b4915ab&cp=1) 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 (http://www.vwlowen.co.uk/arduino/bootloader/page2.htm).

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

Code: [Select]
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
Title: Re: Bootloading ATMEGA328P with Optiloader
Post by: westfw on Apr 10, 2016, 08:22 am
Does your breadboard have the crystal and caps as well?  It needs them.

Quote
if they are preloaded with optiboot are they not already burnt?
Yes, I would think so.
Title: Re: Bootloading ATMEGA328P with Optiloader
Post by: NickyG on Apr 10, 2016, 08:33 am
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.

Title: Re: Bootloading ATMEGA328P with Optiloader
Post by: NickyG on Apr 10, 2016, 08:48 am
(https://photos-3.dropbox.com/t/2/AAC0V_YEikLedKZ-ieqd0Sm8FQt2Sfoi39IYv7nNoGs00A/12/36358420/jpeg/32x32/1/_/1/2/IMAG1138.jpg/EOzG0hsY0BkgAigC/PDZWGy_M7XmApigcpWEPCn7yAkZ393t1Azl1Bryr6iU?size_mode=5)

Thats my setup at the moment.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 10, 2016, 10:13 am
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
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: westfw on Apr 10, 2016, 10:39 am
Quote
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 :-(
Malhar's ideas might work, applied to optiloader as well as arduinoISP...
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 10, 2016, 10:57 am
Hi Guys,

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

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

Code: [Select]
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.

(http://s14.postimg.org/9szbvc88w/unspecified.jpg)
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 10, 2016, 11:09 am
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.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 10, 2016, 11:31 am
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

(http://s30.postimg.org/cjn67ym2p/setup2.jpg)
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 10, 2016, 11:42 am
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 ?
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 10, 2016, 12:01 pm
I don't see a GND connected to pin 8.
That may be the problem.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 10, 2016, 12:05 pm
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)

(http://s27.postimg.org/lte782tw2/IMAG1141.jpg)

Current error
Code: [Select]
avrdude: Device signature = 0xff7fff
avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 10, 2016, 12:17 pm
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
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 10, 2016, 12:36 pm
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.

(http://s27.postimg.org/8b434676b/image.jpg)

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.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 11, 2016, 10:09 am
Given these chips are ATMEGA328P-PU's do I need to change the avrdude.config file or is that just for the ATMEGA328P
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 11, 2016, 11:40 am
No, you don't need to change anything in avrdude.conf.
I suspect that the chip or the crystal is faulty.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 11, 2016, 11:52 am
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.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: Budvar10 on Apr 11, 2016, 12:00 pm
Quote
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.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 11, 2016, 12:08 pm
Quote
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.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: Budvar10 on Apr 11, 2016, 12:50 pm
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 (http://forum.arduino.cc/index.php?topic=277260.0) and similar, always with the capacitors.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: chucktodd on Apr 11, 2016, 10:00 pm
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)

(http://s27.postimg.org/lte782tw2/IMAG1141.jpg)

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

THE PROBLEM IS WITH YOUR BREAD BOARD!

You have Power and Ground (RED and BLACK jumper connected to the the RED and BLUE busses on the top of the Bread board.  Do you SEE the RED and BLUE stripes?  DO you SEE the VOID (at pin 30) in the RED and BLUE STRIPES?  

Those stripes mark were the pins are connected.  The VOID marks were EACH buss STOPS  THERE are FOUR BLUE busses, FOUR RED busses.  NOT TWO of each.

Either put jumpers over the VOIDS or only connect to the Same segment.

Chuck.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: pegwatcher on Apr 12, 2016, 12:44 am
Wow, good catch. I've never seen a board with split rails like that one.
I wonder how many people have been driven to the brink of insanity by those boards?
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: dmjlambert on Apr 12, 2016, 01:14 am
Or driven to the brink of getting out a multimeter and checking continuity of every connection.  I have seen those breadboards before.   They are handy for multiple/flexible busses.   Sharp eye, Chuck.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: chucktodd on Apr 12, 2016, 03:15 am
Wow, good catch. I've never seen a board with split rails like that one.
I wonder how many people have been driven to the brink of insanity by those boards?
I speak from personal experience.  I have been caught by that problem.  It really, Really Sucks!

Chuck.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 12, 2016, 12:38 pm
THE PROBLEM IS WITH YOUR BREAD BOARD!

You have Power and Ground (RED and BLACK jumper connected to the the RED and BLUE busses on the top of the Bread board.  Do you SEE the RED and BLUE stripes?  DO you SEE the VOID (at pin 30) in the RED and BLUE STRIPES? 

Those stripes mark were the pins are connected.  The VOID marks were EACH buss STOPS  THERE are FOUR BLUE busses, FOUR RED busses.  NOT TWO of each.

Either put jumpers over the VOIDS or only connect to the Same segment.

Chuck.
I misssed it. I have bridged the voids on the day I got the boards and never worried about it,hence,I forgot about it. Last week, I boughe 2 new boards and installed jumpers permenantly.

:palm:

-Malhar
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 12, 2016, 12:50 pm
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.

Alright so reading from 5v to xtal1 get a volt reading of 1.45v. Although that 2.5v you mention is that across the crystal I.e from xtal1 to the capacitor.

Checked all the wires to ensure they werent broken and they are all good did it with an LED and also on the DMM (Why on both, well just to be sure). Also fixed up the wiring issue with the buss' cheers for that. Still no luck.

Same error, even picked up a 100microfarad capacitor and hooked in on as per this link (http://www.instructables.com/id/Bootloading-ATmega328-with-Arduino-Mega2560/). I'm about to run a continuity test over the entire breadboard.

I'm starting to think this is going to be a wood from the trees result :S

Here is the setup at the moment.
  (http://s30.postimg.org/htjousssg/setup3.jpg)
Don't worry about the extra LED's and the other microcontroller off to the right
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 12, 2016, 01:25 pm
Check the voltage at pin 7 of the 328p....

Do you SEE "30" near the top rails ?? Its where the rails are not connected. let me attach an image.
See those ed and green wires in drawings ???
You have to place wires there.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 12, 2016, 01:29 pm
Another IMAGE
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 12, 2016, 01:53 pm
Another IMAGE
Do i need connections across there if i got nothing going to those buss' the other microcontroller and jumpers to the right are just left overs from another job.

Voltage on from pin 7 on the 328p to GRD is 5v
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 12, 2016, 02:51 pm
Try it, most of the breadboards do not have connections there. You have to connect it. That has nothing to do with the another microcontroller. Remove the connections to the other micro or power the arduino from external source.
-Malhar
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 14, 2016, 04:08 pm
OK so I've still to check the bridging of the buss but I'm also going to solder up the setup on a protoboard to see if it's a dodgy connection. Dmm couldn't find anything
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: MalharD on Apr 14, 2016, 04:22 pm
OK so I've still to check the bridging of the buss but I'm also going to solder up the setup on a protoboard to see if it's a dodgy connection. Dmm couldn't find anything
Did you bridge those gapes with some jumper wires as suggested ??
Should I send you an frizzing image explaining it ??
But running fritzing may take half an hour on my machine....

-Malhar

Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: Budvar10 on Apr 15, 2016, 10:14 am
Alright so reading from 5v to xtal1 get a volt reading of 1.45v. Although that 2.5v you mention is that across the crystal I.e from xtal1 to the capacitor.
I meant XTAL1 - GND voltage, it should be close to 2.5V (if VCC=5V), measured as DC with any DMM. In perfect condition it is square signal 50%:50% at clock frequency, so the DMM measure the average value, half of 5V. 1.45V seems to be less than it should be if you measured correctly.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 17, 2016, 02:09 pm
Hi guys,

Haven't had a chance to check yet. Will do tomorrow. Malhar I fully understand what you mean. No need for the frizzing.

Budvar I'll recheck that value reading from the points you noted.
Title: Re: Bootloading ATMEGA328P-PU with Optiloader
Post by: NickyG on Apr 18, 2016, 12:17 pm
bridged the buss, no change, still get the same error.

Measured across Xtal1-GND got a volt reading of 1.6.

Any tips