Context
This is my first embedded project and with a lot of help from friends etc I have designed a PCB which has an ATMega328P wired to ISP header. There is no external clock.
Problem
When I use Arduino IDE or avrdude to communicate with the 328P I get this error
Target doesn’t answer
Log from Arduino IDE:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cusbasp -Pusb -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 : usb
Using Programmer : usbasp
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 : usbasp
Description : USBasp, http://www.fischl.de/usbasp/
avrdude: auto set sck period (because given equals null)
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
Some blog posts suggested using avrdude on the command line with the -B flag to slow down the speed to 1MHz to work with the AVR in default config and where as I can see this is changing the frequency the ATMega328P is still not responding.
I ran the command from log above in console, with tail of log is:
>>> avrdude -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -vvv -patmega328p -cusbasp -Pusb -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m -B 800
avrdude: usbasp_initialize()
avrdude: usbasp_spi_set_sck_period(0.0008)
avrdude: try to set SCK period to 0.0008 s (= 1250 Hz)
avrdude: set SCK frequency to 1000 Hz
avrdude: usbasp_program_enable()
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Even when I just try to read the fuse settings it fails
>>> avrdude -vvv -p m328p -c usbasp -P usb -b 19200 -U efuse:r:-:i -U hfuse:r:-:i -U lfuse:r:-:i -B 800
avrdude: usbasp_initialize()
avrdude: usbasp_spi_set_sck_period(0.0008)
avrdude: try to set SCK period to 0.0008 s (= 1250 Hz)
avrdude: set SCK frequency to 1000 Hz
avrdude: usbasp_program_enable()
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
I now realize that I probably can’t program it from the Arduino IDE since that expects the ATmega328P to be on a board with an external clock. I was going to try different fuse settings but if I can’t read from the chip then I doubt that’ll make it work.
I have tested connections between the programmer and ATMega328P pins on the PCB and they seem fine.
So, what is the right avrdude command to upload the bootloader?
And then can I upload my program from Arduino IDE or do I need to use avrdude? If avrdude must be used again then how do I generate the .hex file?
Note: If these steps are clearly documented in an up to date tutorial then send me the link as I haven’t managed to find it.
Any and all help will be greatly appreciated
PS: One forum post suggested using an oscilloscope but I don’t have one. Surely there’s a simpler answer.
