Arduino Bootloader for ATmega168PA

I have burned an arduino bootloader to an ATmega168PA. I want to use the internal 8MHz oscillator for the ATmega, and I used an arduino Uno as an ISP. For that, I did the following:

  • Created the directory at Documents/Arduino/hardware/breadboard/avr. In there I placed a boards.txt file, and a bootloaders folder, which contained the .hex file. Both files can be found attached.
  • I found the hex file I used in this link. From it, I used the optiboot_atmega168pa_8000000L_57600.hex

The burning of the bootloader completed successfully. Also I successfully uploaded a blink example to my ATmega168PA via the arduino ISP and the Arduino IDE.

The problem is that when I try to upload something a second time, I get this error:

Arduino: 1.8.12 (Windows 10), Board: "ATmega168PA on a breadboard (8 MHz internal clock)"

Sketch uses 922 bytes (6%) of program storage space. Maximum is 14336 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 1015 bytes for local variables. Maximum is 1024 bytes.
An error occurred while uploading the sketch
avrdude: verification error, first mismatch at byte 0x01d3
         0xe1 != 0xe5
avrdude: verification error; content mismatch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

If I reburn the bootloader, I can again successfully upload a sketch. But once more, I cannot upload a second time.

boards.txt (856 Bytes)

optiboot_atmega168pa_8000000L_57600.txt (1.22 KB)

nnickg:
The problem is that when I try to upload something a second time, I get this error.

Please don't post pictures of text. That is very unhelpful. When you encounter an error you'll see a button on the right side of the orange bar in the Arduino IDE "Copy error messages" (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button. In a message here, click the code tags button (</> on the forum toolbar) and then paste the error.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

Failure to upload the second time is usually due to a problem in the auto-reset circuitry

pert:
Please don't post pictures of text. That is very unhelpful. When you encounter an error you'll see a button on the right side of the orange bar in the Arduino IDE "Copy error messages" (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button. In a message here, click the code tags button (</> on the forum toolbar) and then paste the error.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

Thank you for the information, my apologies. I believe it is right now

My advice is to use MiniCore:

It comes with the configuration settings and bootloader for ATmega169PA using the internal oscillator:

  • Tools > Board > ATmega168
  • Tools > Clock > Internal 8 MHz

I'm not sure what it causing the verification error you're getting, but I do know that MiniCore works well, whereas we don't know whether there might be some problem with the DIY configuration you made. So it's worth a try at least.

Regarding your setup, make sure it is meeting all the normal "checkmarks" - ie, you do have the decoupling caps (0.1uf ceramic cap between Vcc and gnd, and between AVcc and gnd (and they should be right next to the chip). Is your reset circuit right? 0.1uF cap between DTR or RTS of serial adapter and reset pin of board, 10k resistor from reset to vcc, and (ideally) a diode between reset and vcc, with band towards Vcc. Vcc and AVcc are both connected to power, AREF is not tied to Vcc.

Do you have the LED + resistor present? Give it an LED and resistor on the usual pin (arduino pin 13, SCK - I don't recall which physical pin it is)

Is it doing the triple blink? Does it do the triple blink when you start an upload the second time? If not, autoreset isn't working. Does it triple-blink in the middle of upload? Then somehow it's getting reset into optiboot again!

Your max sketch size calculation matches the efuse bootsz bits - but you're using optiboot man! That only takes 512b.... if you set bootsz fuses correctly, you could increase max sketch size by 1536 bytes.... But that doesn't explain your upload problem. It does give a perfect example of why you should use minicore....

If you upload a program via ICSP it overwrites the bootloader , so you need to then reload the bootloader !

Apologies for the late reply, I started checking the problem again, and it still exists.

DrAzzy:
Regarding your setup, make sure it is meeting all the normal "checkmarks" - ie, you do have the decoupling caps (0.1uf ceramic cap between Vcc and gnd, and between AVcc and gnd (and they should be right next to the chip). Is your reset circuit right? 0.1uF cap between DTR or RTS of serial adapter and reset pin of board, 10k resistor from reset to vcc, and (ideally) a diode between reset and vcc, with band towards Vcc. Vcc and AVcc are both connected to power, AREF is not tied to Vcc.

Do you have the LED + resistor present? Give it an LED and resistor on the usual pin (arduino pin 13, SCK - I don't recall which physical pin it is)

Is it doing the triple blink? Does it do the triple blink when you start an upload the second time? If not, autoreset isn't working. Does it triple-blink in the middle of upload? Then somehow it's getting reset into optiboot again!

Your max sketch size calculation matches the efuse bootsz bits - but you're using optiboot man! That only takes 512b.... if you set bootsz fuses correctly, you could increase max sketch size by 1536 bytes.... But that doesn't explain your upload problem. It does give a perfect example of why you should use minicore....

I follow all your recommendations, however let me make clear that I do not use serial programming, I want to program the ATmega328p without a bootloader. I use the arduinoUno as an ISP, and the only reason I am burning the bootloader is to set the fuses.

hammy:
If you upload a program via ICSP it overwrites the bootloader , so you need to then reload the bootloader !

Is this true? So, by following the procedure I mentioned (which can be also found here https://www.open-electronics.org/arduino-isp-in-system-programming-and-stand-alone-circuits/) I can only program my atmega once?
If I want to reprogram it, I have to re-burn the bootloader and then re-upload the updated sketch?

That is correct , or load your next program again via the ICSP connection too.

nnickg:
Is this true? So, by following the procedure I mentioned (which can be also found here https://www.open-electronics.org/arduino-isp-in-system-programming-and-stand-alone-circuits/) I can only program my atmega once?
If I want to reprogram it, I have to re-burn the bootloader and then re-upload the updated sketch?

No, you can program via ISP as many times as you like without ever reloading the bootloader. The quote you were referring to is intended for people who want to be able to program via the serial/USB interface, which requires the bootloader. Way too many people will burn the bootloader, then program a sketch via ISP as a test, not realizing that the bootloader is removed in the process.

Actually you never have to burn a bootloader to the chip. Using MCUdude's MiniCore for the 168PA, select the option for Bootloader: "No Bootloader", then Tools > Burn Bootloader will only set the fuses.