Ard-MEGA - ISP programming to custom PCB with ATMEGA328P

Was previously using a Pololu AVR programmer V2.1 and it went on the blink and stopped working, and recently learned that I could use the old arduino mega I have lying around as a programmer for the custom PCB I have with a ATMEGA328P-AUR chip on board.

I have a ISP header on it, I'm assuming I just connect the ISP header on the mega to the ISP header on the PCB; however after this I'm rather lost as to what I do with the arduino IDE.

From what I gather, I just setup in the Tools menu that the board is the Arduino Mega, Processor to ATMEGA2560, Port: Com3 & Programmer as Arduino as ISP.

After this I don't know what I'm doing when it comes to uploading the sketch to the board.

I thought I might have my cable in wrong, so I reversed it in and I now get a "COM3: Access is denied" Wondering what that is all about, if anyone can explain to me, would be greatly appreciated.

As when I try to upload or try to burn bootloader I get the following error:

avrdude: stk500_getsync() attempt # of 10: not in sync : resp=0x03

Did you upload the "arduino as isp" sketch from the examples to your mega ?

I didn't, have now done that and now using the "Upload using programmer option" to upload the sketch I was working on through the mega and into the custom PCB.

Now getting the following error message:

Arduino: 1.8.12 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Sketch uses 1536 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.
B:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CB:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cstk500v1 -PCOM3 -b19200 -Uflash:w:C:\Users\Marc\AppData\Local\Temp\arduino_build_693976/Sensivision_Business_Card.ino.hex:i

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 "B:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM3
Using Programmer : stk500v1
Overriding Baud Rate : 19200
AVR Part : ATmega2560
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
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 10 8 0 no 4096 8 0 9000 9000 0x00 0x00
flash 65 10 256 0 yes 262144 256 1024 4500 4500 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 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)

An error occurred while uploading the sketch
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.

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

do you have a external clock or using the internal 8MHz clock ? could you consider posting your circuit diagram and giving us more detail about the circuit so we could help you in depth.

I have a ISP header on it, I'm assuming I just connect the ISP header on the mega to the ISP header on the PCB; however after this I'm rather lost as to what I do with the arduino IDE.

I'm assuming you still have the ISP header on the mega to the ISP header on the PCB.

m_k_akash:
do you have a external clock or using the internal 8MHz clock ? could you consider posting your circuit diagram and giving us more detail about the circuit so we could help you in depth.

Sure here is the schematic of the circuit design.

Its an ATMEGA328P using 7 LEDS, 2 capacitive sensor sensors, an OLED display & a CR2032 battery and currently using a shrouded 2x3 header for ISP.

Please note: I no longer have the schematic that includes the header in it as I had to get the later version designed which will have the code preprogrammed onto the ATMEGA328P when I get them assembled at a later point

kprims:
I'm assuming you still have the ISP header on the mega to the ISP header on the PCB.

https://www.arduino.cc/en/tutorial/arduinoISP

I'm currently using a ISCP header on the mega with a 6 pin jumper wire connecting to the 2x3 ISP header on the PCB board.

InsertTitle:
I'm currently using a ISCP header on the mega with a 6 pin jumper wire connecting to the 2x3 ISP header on the PCB board.

please note that the reset of the arduino mega should not be connected to the reset of the atmega328p. you should not connect the reset from the mega's icsp to the atmega328p's icsp instead pin D10 of the arduino mega should be connected to the reset pin of the atmega328p's icsp

m_k_akash:
please note that the reset of the arduino mega should not be connected to the reset of the atmega328p. you should not connect the reset from the mega's icsp to the atmega328p's icsp instead pin D10 of the arduino mega should be connected to the reset pin of the atmega328p's icsp

So realistically then I should ignore the ISCP header on the mega and instead connect everything via the separate pins as dictated in the Arduino ISP tutorial?

MOSI = 51 or ICSP-4
MISO = 50 or ICSP-1
SCK = 52 or ICSP-3
Level = 3.3V
RESET = D10
GND = GND
Do I require the use of that 10uF Electrolytic capacitor for RESET and GND on the Mega as the programming board or can that be ignored?

I think the 10uF cap is not mandatory, if its not working then try adding the cap. And please note that atmega328p may not work properly with 3.3v I suggest using the internal 8MHz oscillator and excluding the external oscillator completely

Why are you connecting to 3.3V? That could lead to problems with logic level differences between the 5V mega and your board. The only reason to run the programming at 3.3V is if your custom board cannot tolerate 5V, but if you had it connected to the ICSP header on the mega you have already exposed the board to 5V.

david_2018:
Why are you connecting to 3.3V? That could lead to problems with logic level differences between the 5V mega and your board. The only reason to run the programming at 3.3V is if your custom board cannot tolerate 5V, but if you had it connected to the ICSP header on the mega you have already exposed the board to 5V.

Well if you look at the schematic I only use 3.3V for powering the entire thing from the CR2032 battery, that's why I'm wondering if the 5V would be fine or whether it would be better working with the 3.3V instead for the programming.

as per the datasheet 16MHz can be used at 4.5 to 5.5V. so I strongly recommend using the 8MHz internal oscillator. Also you could use Sleep modes for a longer run using the battery, turn off the unnecessary components like ADC etc

Okay I've fixed the problem, so I had the wrong board selected in the IDE, I thought having the mega2560 select meant I was using the Ard mega for the programming.

Didn't realise I had to set the board in the IDE as the target board that the ard mega was programming to.

Changed the board to arduino nano and it works perfectly fine, the leds light up which is what I needed.