Custom Atmega328pb board not storing sketch on power off and on

Hi all, I have a Custom made board with the Atmega328pb chip and i had some issues earlier burning bootloader and specific sketches using the extra I2C pin. Fortunately i got lucky using another core, and can load bootloader and sketches, but when powered down, the board looses everything, and when powered up i need to burn bootloader again and sketch and keep the board on to use. I'm Currently using the MCUdude Minicore package build from Github to upload sketches. One thing i noticed is that, the burning of bootloader fails the first time then, next time it works.
Here is the first error

Arduino: 1.8.15 (Windows 10), Board: "ATmega328, Yes (UART0), EEPROM not retained, 328PB, BOD  disabled, LTO disabled, External 16 MHz"



avrdude: Version 6.3-20201216

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2014 Joerg Wunsch



         System wide configuration file is "C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf"



         Using Port                    : COM16

         Using Programmer              : stk500v1

         Overriding Baud Rate          : 19200

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15

         AVR Part                      : ATmega328PB

         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

           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

           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00



         Programmer Type : STK500

         Description     : Atmel STK500 Version 1.x firmware



avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14



avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x02



avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10

         Hardware Version: 4745024

         Firmware Version: 0.4611299

         Topcard         : STK502

Error while burning bootloader.

         Vtarget         : 1.8 V

         Varef           : 0.0 V

         Oscillator      : Off

         SCK period      : 0.1 us



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



avrdude done.  Thank you.





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

Then this is the proper bootload on second run

avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf"

         Using Port                    : COM16
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328PB
         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
           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
           efuse          0     0     0    0 no          1    0      0  4500  4500 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.02s

avrdude: Device signature = 0x1e9516 (probably m328pb)
avrdude: erasing chip
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.01s

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:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0b11110111"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

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

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0b11011110"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

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

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0b11111111"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

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

Reading | ################################################## | 100% 0.01s

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

avrdude done.  Thank you.


avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf"

         Using Port                    : COM16
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328PB
         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
           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
           efuse          0     0     0    0 no          1    0      0  4500  4500 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.02s

avrdude: Device signature = 0x1e9516 (probably m328pb)
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 "C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex"
avrdude: writing flash (32768 bytes):

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

avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex:
avrdude: load data flash data from input file C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex:
avrdude: input file C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328pb/16000000L/optiboot_flash_atmega328pb_UART0_115200_16000000L_B5.hex contains 32768 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 32768 bytes of flash verified
avrdude: reading input file "0x0f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.02s

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

Reading | ################################################## | 100% 0.01s

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

avrdude done.  Thank you.

After this i can load sketches, and the board executes them while it is on, but then i have to restart this whole process after power off.
Someone please help, it's through this forum i was able to get help on the MCUdude Minicore suggestion

Post the schematic for the custom board.

2 Likes

Hi, thanks so much, i added the reset resistor though, here is the schematic


it's kinda messy but you can see the reset resistor near the top left corner, next to the controller board icon

Nice schematic. It appears you are missing high frequency bypass on the 5V, I don't think that is the problem but.

Is it a hardware issue, I tend to think it's a software one cause the board can be bootloader, and can run code, I think it's an issue about the bootloader or something but I'm not sure

That's ... theoretically impossible. For a sketch to run, it must be in flash, which does NOT go away on a power-cycle.

Are you using "upload" or "upload using programmer" for uploading the sketch?

Ohh exactly yes, I'm using an Arduino ISP programmer, please explain why it's not going to get stored, thanks really

I have uploaded to Arduino nano with another nano using the Arduino as ISP programmer before, and I had no issues, the board stored the code irrespective of power cycles

When you upload a sketch "using programmer", it will erase the bootloader, but leave the fuses set as if a bootloader were still present. Normally, this is OK, because when the CPU starts at the bootloader address at the end of flash, it will just "loop" around the address to the real code at 0x0. But if your sketch is quite large and has "some" code where the bootloader ought to be, random things can happen (depending on exactly what that fragment of code does.)
Also, I guess it's possible (but unlikely!) that the 328pb behaves differently than a 328p.

if you're using MiniCore, there's a tools setting for "bootloader: no bootloader" that you should use. (Despite the name, you can still use the "burn bootloader" command to set the fuses, and it should set them as appropriate for not using a bootloader.)

Thanks a lot, I did this, but it's not loading the code on startup, the code is stored on the chip actually, but when I turn off and turn on again it doesn't start running the program, but when I try bootloading, the first error comes up, and then the board starts executing the code on it like normal without uploading bootloader a second time and the sketch too, don't know what's wrong, I'm also using the no bootloader option as of now

ohh, i just discovered that, the code is stored on the board now and works on power on and off, i used blink sketch to test the board, and when trying to upload i think the Arduino ISP program loaded on the programmer board pulls down pin 13 on startup, so if i check my custom board if the blink works, i'm using the builtin LED on the programmer (because pin 13 on arduino programmer is SCK and pin 13 on the custom board, so i won't see the LED flash due to the pull down on the programmer, i'm not sure about this, but i think this is the primary reason why the first time i try loading code to my board, or burning bootloader, it always fails the first time, then works the second.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.