Burning bootloader on standalone Atmega328(internal clock 8MHz)

Thank you John,
I did as you said and I can see some progress - still not success but I have different error message.
This time it is:
"Could not find tool avrdude"
I was trying to google it, but without success. This how my 'boards.txt' file looks like:
##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.tool=avrdude
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

Any advice?

Looking at the ATtiny core for Arduino 1.6.x it looks like you have to use 'arduino:avrdude' instead of just 'avrdude' in your custom boards.txt files. Sorry I did not know that before.

Without using a custom boards.txt file you can get the same effect (328p with internal clock) by treating your ATmega328p as a LilyPad Arduino board with an ATmega328 processor (Select Tools->Board->LilyPad Arduino, then Tools->Processor-> ATmega328)

John, every advice from you is taking me further, but I am still not quite there yet.
Now I have another error message:

'avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.

Error while burning bootloader.'

I can see this error in both cases: for LilyPad and for standalone Atmega 328 and on both IDE's: 1.6 and 1.6.1.

Do you have any idea what to do next?

I'd try with 1.0.6 IDE, 1.6 I recommend for Yun and Due.

Did you, by any chance, purchase an ATmega328 instead of the ATmega328P used in all the Arduinos? The 'P' (Pico-power) version has a different signature.

johnwasser:
Did you, by any chance, purchase an ATmega328 instead of the ATmega328P used in all the Arduinos? The 'P' (Pico-power) version has a different signature.

He should set to verbose output (in preferences) to obtain exact signature bytes. If it is zero or not.

johnwasser:
Did you, by any chance, purchase an ATmega328 instead of the ATmega328P used in all the Arduinos? The 'P' (Pico-power) version has a different signature.

No. I checked that and I have only ATmega328P. I am able to run my project with the external oscillator but I would like to shrink it, and that is why I need to use internal oscillator.

Budvar10:
He should set to verbose output (in preferences) to obtain exact signature bytes. If it is zero or not.

I did it as well and this is what I am getting:

System wide configuration file is "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf"
User configuration file is "/Users/AndrzejKonto/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port : /dev/tty.usbmodem14211
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

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.06s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.

What model Arduino are you running the ArduinoISP sketch on? One of the page you link to is for an Arduino Micro.

Did you select "Arduino as ISP" (not "ArduinoISP") from Tools->Programmer before selecting Tools->Burn Bootloader?

"avrdude: Device signature = 0x000000"

That tends to indicate a wiring error. The wiring will somewhat depend on which model Arduino you are using for ArduinoISP.

Has the ATmega328P you are programming been set to expect a crystal? If so you have to provide a crystal or an alternative clock. Adafruit has an alternative version of ArduinoISP that uses Arduino Pin 9 for an 8 MHz clock output. You can connect it to pin 9 (XTL1) of the ATmega. GitHub - adafruit/ArduinoISP: A fork of the ArduinoISP that has 8mhz output clock

johnwasser:
What model Arduino are you running the ArduinoISP sketch on? One of the page you link to is for an Arduino Micro.

I am running ArduinoISP sketch on UNO.

johnwasser:
Did you select "Arduino as ISP" (not "ArduinoISP") from Tools->Programmer before selecting Tools->Burn Bootloader?

Yes

johnwasser:
"avrdude: Device signature = 0x000000"

That tends to indicate a wiring error. The wiring will somewhat depend on which model Arduino you are using for ArduinoISP.

This is what I using for wiring: oddWires: Burning a bootloader into a bare ATmega328

johnwasser:
Has the ATmega328P you are programming been set to expect a crystal? If so you have to provide a crystal or an alternative clock. Adafruit has an alternative version of ArduinoISP that uses Arduino Pin 9 for an 8 MHz clock output. You can connect it to pin 9 (XTL1) of the ATmega. GitHub - adafruit/ArduinoISP: A fork of the ArduinoISP that has 8mhz output clock

I have 3 ATmega 328P. Only one of them should be set to work with crystal and it works with crystal. The other 2 are new and it shouldn't work with external crystal but when I was trying burn bootloader on them I can see this:
' Oscillator : Off'

so I am not so sure anymore.

I tried to use 'GitHub - adafruit/ArduinoISP: A fork of the ArduinoISP that has 8mhz output clock' file.

  • I enabled LOW_SPEED, and loaded it to the programmer.
  • I connect Arduino pin 9 with with Atmega XTL1
  • I switched to 'LilyPad Arduino'
  • I tried to 'Burn Bootloader'

This is the error message I got:

'avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex"
avrdude: writing flash (32652 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x00
avrdude: stk500_cmd(): programmer is out of sync
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.'

After previouse attempt I loaded regular 'ArduinoISP' sketch, and with the Arduino pin 9 still contected to ATmega XTL1 I tried to burn bootloader again. In this case I recived below error message:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e950f
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing | ***failed;
################################################## | 100% 0.16s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

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

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0x00 != 0x3f
avrdude: verification error; content mismatch

avrdude done. Thank you.

That symptom looks like what I saw when I had not disabled auto-reset on the Arduino UNO running ArduinoISP. The Arduino bootloader uses the same protocol as the ArduinoISP. The bootloader will return the signature for an ATmega328P but then it will return 0 if you try to read memory or fuses.

Did you connect a 1 to10 uF capacitor from Reset (+) to Ground (-)?

I tried with the capacitor and I have exactly the same errors like before...

I've run out of ideas. :frowning:

John, could you please give me the setup which you are using for the same task to make me sure that I have done everything as it should be?
I will not give up on this :slight_smile:
The only thing is that for the next 2 weeks I will be offshore so I have to suspend my efforts.

Burning a Bootloader
(Arduino 1.6.1 running on MacBook Pro w/ OS X 10.10.2)
ISP Arduino: Arduino Diecimila w/ATmega168 (didn't have a second ATmega328P available)
Target chip in breadboard: ATmega328P (has UNO bootloader and no crystal)

Connect the USB cable to the PC and ISP Arduino

Install the ArduinoISP sketch in the ISP Arduino.
File->Examples->ArduinoISP
Tools->Board->Arduino Duemilanove or Diecimila
Tools->Processor->ATmega168
Tools->Port->(serial port for ISP Arduino)
File->Upload

Go to Preferences... and check the box for "Show verbose output during: [ ] compilation [X] upload"

Install the breadboard wiring:

Target
Pin
Arduino
Pin
Target
Pin
Arduino
Pin
1 Pin 10 28
2 27
3 26
4 25
5 24
6 23
7 +5V 22 GND
8 GND 21
9
20 +5V
10 19 Pin 13
11 18 Pin 12
12 17 Pin 11
13 16
14 15

Attempt to burn bootloader without disabling auto-reset on ISP Ardiuino.
Tools->Board->Arduino UNO
Tools->Port->(serial port for ISP Arduino)
Tools->Programmer->Arduino as ISP
Tools->Burn Bootloader.

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

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

Note: If the ISP Arduino had an ATmega328P processor this check would have passed and an error would occur further into the process. Here is what happens if I put an ATmega168 into the breadboard and try to burn a Diecimila 168 bootloader to it:

avrdude: Device signature = 0x1e9406
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing |  ***failed;  
################################################## | 100% 0.13s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

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

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x3f
avrdude: verification error; content mismatch

Added a 10 uF capacitor to the ISP Arduino with the positive side of the capacitor going to Reset and the negative side of the capacitor going to Ground.

Now attempt to burn a bootloader. If the chip is not set to expect a crystal or external clock then this should be successful. If the chip came with (or has had burned) an Arduino bootloader it will fail like this:

Tools->Burn Bootloader.

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check..

This is a symptom of the target chip's clock not running. An ATmega that is expecting a crystal won't accept serial programming without a crystal or ceramic resonator between pins 9 and 10, or an external clock injected into pin 9. I found a crystal between 8 MHz and 20 MHz (14.3180 MHz in my case) in my 'salvaged parts' box and plugged it into the breadboard between pins 9 and 10.

Attempt to burn bootloader again: Tools->Burn Bootloader.

avrdude: verifying ...
avrdude: 1 bytes of lock verified

avrdude done.  Thank you.

SUCCESS!

Here's what I did:

  1. locate your installed boards.txt (mine was in /usr/share/arduino/hardware/arduino/avr/boards.txt)
  2. add the following at the end. Restart the IDE and choose ATmega328 on a breadboard from the list

hope that works for you!
##############################################################
atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.maximum_data_size=2048
atmega328bb.upload.speed=57600

atmega328bb.bootloader.tool=arduino:avrdude
#atmega328bb.bootloader.tool=avrdude

atmega328bb.upload.tool=avrdude

atmega328bb.bootloader.low_fuses=0xE2
#atmega328bb.bootloader.low_fuses=0xFF
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
#atmega328bb.build.core=arduino:arduino
atmega328bb.build.core=arduino
#atmega328bb.build.variant=arduino:standard
atmega328bb.build.variant=standard
###Experimental name:
atmega328bb.build.board=AVR_BARE

Guys thank you for all your help.

Final I managed to burn bootloader on the standalone Atmega328P.

To accomplish that I removed all old Arduino IDE's (all together with the all boards.txt files with which I was playing), I installed Arduino 1.6.3, afterwards I edited boards.txt with the instructions from johshmoh, I took brand new Atmega328P and followed johnwasser instructions. Everything went smoothly. It works even without 10uF capacitor.

I checked all my microcontrollers with Atmel Studio and Atmel ICE and I found that during my first attempts of upload bootloader I changed the fuses to use external oscilator... I don't know how it happend.

Anyway now everything works how it should.

update 1.6.4 broke things. here's the new boards.txt section:
##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.tool=avrdude
atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard

johshmoh, your update is not corect, i had to add the line "atmega328bb.bootloader.tool=arduino:avrdude" to make it work.
Please check and confirm.