Hi everyone:
I am having some difficulty programming a new ATMEGA328P-PU IC with a custom bootloader. The bootloader is a recompilation of optiboot so that the microcontroller will use an external 12Mhz crystal (configuration copied below). For a programmer, I am using a Nano-clone, programmed using the ArduinoISP sketch. The only oddity of this Nano board is that it uses the "old bootloader", although I don't think that matters. Also, I'm confident that the 328P is bare as it came straight from the LCSC electronics distributor though I don't know of a way to confirm that.
Each time I attempt to program the bare 328P IC, I receive a series of "stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
" messages, followed by "avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14
". The common suggestion for this issue is to install a 10uF capacitor between the reset and ground pins, but doing so then yields "avrdude: Device signature = 0x000000
" messages. Verbose logs are copied below for reference.
The breadboard circuit for the 328P is the bare-minimum circuit:
- 100nF decoupling capacitor across pins 7,8 and 21,22
- Pins 20,21 connected (voltage reference pins)
- 12Mhz crystal connected to pins 9,10
- 22pF capacitors connected to each side of the crystal and ground
- From the Nano SPI interface:
- Reset to pin 1
- MOSI to pin 17
- MISO to pin 18
- SCK to pin 19
- Power is received from the Nano SPI interface too, which measures around 4.7-4.8V
I'm a bit lost and not sure what to check next as this seems like a very standard setup for programming. I found this post that suggests that the lock bits in my configuration may be incorrect, but I don't want to blindly change those from 0F
to CF
without understanding what this will do.
Is there something wrong with my configuration or methodology?
Optiboot configuration (makefile)
atmega328_12mhz: TARGET = atmega328
atmega328_12mhz: MCU_TARGET = atmega328p
atmega328_12mhz: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega328_12mhz: AVR_FREQ = 12000000L
atmega328_12mhz: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
atmega328_12mhz: $(PROGRAM)_atmega328_12mhz.hex
atmega328_12mhz: $(PROGRAM)_atmega328_12mhz.lst
atmega328_12mhz_isp: atmega328
atmega328_12mhz_isp: TARGET = atmega328
atmega328_12mhz_isp: MCU_TARGET = atmega328p
# 512 byte boot, SPIEN
atmega328_12mhz_isp: HFUSE = DE
# Low power xtal (8-16MHz) 16KCK/14CK+65ms
atmega328_12mhz_isp: LFUSE = FF
# 2.7V brownout
atmega328_12mhz_isp: EFUSE = 05
atmega328_12mhz_isp: isp
Boards.txt configuration for 12Mhz programming
##############################################################
atmega328bb12.name=ATmega328 12MHz crystal
# atmega328bb12.vid.0=0x2341
# atmega328bb12.pid.0=0x0043
# atmega328bb12.vid.1=0x2341
# atmega328bb12.pid.1=0x0001
# atmega328bb12.vid.2=0x2A03
# atmega328bb12.pid.2=0x0043
# atmega328bb12.vid.3=0x2341
# atmega328bb12.pid.3=0x0243
atmega328bb12.upload.tool=avrdude
atmega328bb12.upload.protocol=arduino
atmega328bb12.upload.maximum_size=32256
atmega328bb12.upload.maximum_data_size=2048
atmega328bb12.upload.speed=115200
atmega328bb12.bootloader.tool=avrdude
atmega328bb12.bootloader.low_fuses=0xFF
atmega328bb12.bootloader.high_fuses=0xDE
atmega328bb12.bootloader.extended_fuses=0xFD
atmega328bb12.bootloader.unlock_bits=0x3F
atmega328bb12.bootloader.lock_bits=0x0F
atmega328bb12.bootloader.file=optiboot/optiboot_atmega328_12.hex
atmega328bb12.build.mcu=atmega328p
atmega328bb12.build.f_cpu=12000000L
# uno.build.board=AVR_UNO
atmega328bb12.build.core=arduino
atmega328bb12.build.variant=standard
Verbose log without 10uF capacitor (reset->ground)
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM5 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"
Using Port : COM5
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 : 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
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: 4744608
Firmware Version: 0.4611299
Topcard : STK502
Vtarget : 1.8 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
Error while burning bootloader.
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.
Verbose log with 10uF capacitor (reset->ground)
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM5 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"
Using Port : COM5
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.02s
avrdude: Device signature = 0x000000 (retrying)
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x000000 (retrying)
Error while burning bootloader.
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.