How to install arduino mega 2560 as isp programmer for atmel 644

Hey,
I don’t know how to use my arduino mega2560 as a programmer. I want to programm a atmel 644 via isp with my arduino.
Actually I did the following steps

  1. Open arduino ide and flash the arduino with the example programm arduino isp
  2. Open VSCode and platformio and select my atmel 644 for the project.
  3. Connecting arduino and 644 via isp.
  4. Now I want to upload a simple blinky programm. Led is connected to pin 5.
    But I don’t get any response. The terminals response is that the get_synck() 1 of 10.
    Can I programm the ardunio as programmer via the platformio and flash the atmel644 by one platform.ini ? When yes how should my platform.ini should look like ? Or have to do it in two steps and different projects ? Thanks for help and for a detailed instructions i would be great full

Full platformio.ini and wireup between the Mega and the ATTIny?

My platform.ini looks like a normal ini ehen you generate a new project for atmega644.
Wirering is via a isp wire. So i use the isp chanel over the 2 big port lines at the mega and connect it to an isp that is connected to the 644.

My major problem is I don’t even know how to flash my arduino that it is a programmer via isp for my 644. What are the first steps how should my initial look like. Have to start with an ini that my arduino knows he is a programmer. Or I only have to use a ini like that one :
[env:megaatmega2560] platform = atmelavr framework = arduino board = megaatmega2560 upload_protocol = arduinoisp
And when yes what option in vscode i have to choose uploading or uploading with programmer ?

Please see the documentation.

This is unclear. There are Atmel ATMega644P/PA and Atmel ATMega644A chips. Which one is it?

Assuming you want to flash a ATMega644A, your platformio.ini should look something like this

[env:ATmega644A]
platform = atmelavr
board = ATmega644A
framework = arduino
upload_protocol = custom
upload_port = SERIAL_PORT_HERE
upload_speed = 19200
upload_flags =
    -C
    ; use "tool-avrdude-megaavr" for the atmelmegaavr platform
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -P
    $UPLOAD_PORT
    -b
    $UPLOAD_SPEED
    -c
    stk500v1
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

where you must replace SERIAL_PORT_HERE with the serial port that your Arduino Mega “Arduino as ISP” device is connected to, e.g. COM4.

To PlatformIO it doesn’t matter whether you flash an Arduino Mega or Arduino Uno or Arduino whatever with the Arduino as ISP firmware (you also don’t reference a “Arduino Mega” in the platformio.ini), it just has the commands to interact with a STK500V1 style programmer that is implemented by the board when it’s running the Arduino as ISP sketch.

Thanks i would try your ini. I use the normal atmega 644 without any p or a behind.
So first i have to upload the arduinoisp sketch at arduino ide. Then go to vscode and copy your ini with some differences in my ini and then flash it via upload with programmer or normal upload ?

Oh okay so it’s this outdated version? https://www.microchip.com/wwwproducts/en/ATmega644? Absolutely sure?

Mature product; not recommended for new designs. Replaced by ATmega644PA.

Please try the above platformio.ini anyways.

If the chip turns out to be wrong, please change the config to board = sanguino_atmega644_8m from docs, “Sanguino ATmega644 or ATmega644A (8 MHz)”. It’s an 8MHz configuration for the ATMega644.

(Previous state of the post with a custom board JSON file was not needed: PlatformIO already knows about such a pure ATMega644 config)

Correct. Upload or upload with programmer shouldn’t make a difference, try normal upload first. As the project’s source code either try empty loop and setup or directly some blinky code if you have the hardware for it.

Just as an additional sanity check, did you build your own board or have the raw chip on breadboard / breakout board and you want to program it? Or are you using a premade board that might already be supported directly and has a different chip after all?

Hello, I’m working with @miros.407 on the project. I tried to use the ini file @maxgerhardt posted. My Serial Port is COM5 and I replaced the SERIAL_PORT_HERE with COM5.

Now I’m getting the Error Code:

avrdude: can’t open config file “C:\Users\HP”: Permission denied
avrdude: error reading system wide configuration file “C:\Users\HP”
*** [upload] Error 1

Any ideas on how to give the permission?
I have found the path: -C
C:\Program Files (x86)\Arduino\hardware\tools\avr\etc
is read-only.

EDIT: now this is strange:

avrdude: can’t open config file “C:\Users\HP Gaming Rechner\Desktop”: Permission denied
avrdude: error reading system wide configuration file “C:\Users\HP Gaming Rechner\Desktop”
*** [upload] Error 1

We use https://ww1.microchip.com/downloads/en/DeviceDoc/doc2593.pdf page 2 figure 1.1 and we install that on a breadboard and connect it with a isp


at the middle is the 644 and at the bottom middle is our isp connection

1 Like

Do you have a space in your Windows username?

In the platformio.ini, can you replace $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf with "$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf" please (quoting should escape the path properly)

I’m afraid I do have a space in the username.

Adding the quotation marks worked. now we have an Invalid device Signature Error

Executing task in folder BlinkyTest: C:\Users\HP Gaming Rechner.platformio\penv\Scripts\pio.exe run --target upload <

Processing ATmega644 (platform: atmelavr; board: sanguino_atmega644_8m; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel AVR (3.0.0) > Sanguino ATmega644 or ATmega644A (8 MHz)
HARDWARE: ATMEGA644 8MHz, 4KB RAM, 63KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES:

  • framework-arduino-avr 5.1.0
  • tool-avrdude 1.60300.200527 (6.3.0)
  • toolchain-atmelavr 1.50400.190710 (5.4.0)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 5 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Checking size .pio\build\ATmega644\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 0.2% (used 9 bytes from 4096 bytes)
    Flash: [ ] 1.5% (used 984 bytes from 64512 bytes)
    Configuring upload protocol…
    AVAILABLE: custom
    CURRENT: upload_protocol = custom
    Uploading .pio\build\ATmega644\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

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.

*** [upload] Error 1
================================================================================================== [FAILED] Took 2.09 seconds ==================================================================================================
The terminal process “C:\Users\HP Gaming Rechner.platformio\penv\Scripts\pio.exe ‘run’, ‘–target’, ‘upload’” terminated with exit code: 1.

No problem then quoting solves it.

Welp. There are 3 possibilities here:

  1. The wireup between the Arduino Mega programmer and the ATMega644 is wrong
  2. The target board is not powered (?)
  3. You have a fake chip and it really does report 0x0000 as its ID o_O

Are you following the wireup as shown in https://www.instructables.com/How-to-use-Arduino-Mega-2560-as-Arduino-isp/ for the SPI lines and a capacitor between RESET and VCC on the Arduino Mega? Do you maybe have a picture of the setup or a wireup diagram available that you’re following?

I will check the wireup. The Board is powered. I hope the chip isn’t the problem. This would be unsolveable.

The wireup is following the one in the link you posted.
We still get the Yikes! Error.

The picture is cutoff at the left so I can’t see if you have a capacitor installed between RST and VCC, further the breadboard at the bottom is cut off.

A thing I find weird in the target board is the RESET line. Am I blind or does the bottom right pin of the ISP header, which is supposed to be RESET, go nowhere, just between the two headers themselves, but not to the actual RESET pin of the chip, which is just connected to one pin of the button? Hardware error? The SPI SlaveSelect (SS) line must definitely go the RESET of the target.

You can check whether it makes a difference if you connect the the SS pin of the Mega to the bottem left pin of the reset button (in regards to the above posted picture) (or touch it while programming with a male-male cable). The RESET button is an input connected to nothing else (if you don’t press the button) so nothing bad should happen.

Edit: Also, the page https://www.arduino.cc/en/Tutorial/BuiltInExamples/ArduinoISP should be the main source of information for the wireup. There are different wireups in there, e.g. RESET <-> RESET or SS <–>RESET with caps and not. Just glossed over it, maybe you can extract some more information from this and try a few different things.

We don’t have a capacitor installed. Is this crucial?

Reset is connected to pin 53 of the Arduino Mega. Should be SS.

I have to attend to an appointment now. Thanks for helping, I will reply again tomorrow.

Alternative we can use a cable like this intead of 10 pins we have a Cable with 6 Pins so it is an isp Cable. IDC Flachbandkabel Pfostenbuchsen 10-polig 1,0m für ISP: Amazon.de: Elektronik

We test it with these but it dosen’t work for us. We flip the End of the cable around but nothing change.

Yes

This is the suggested wiring for using a Mega as a ISP programmer… although it’s for a Uno, same principle applies, and you can read between the lines as to which pins on the target match the 644 :wink:

The Arduino MEGA above is programming an Arduino UNO connecting D51-D11, D50-D12, D52-D13, GND-GND, 5V-5V and D10 to RESET. This type of board needs a 10µF electrolytic capacitor connected to RESET and GND with the positive (long leg) connected to RESET. The capacitor has to be placed after the programmer board has been loaded with the ISP sketch.

The 10µF electrolytic capacitor connected to RESET and GND of the programming board is needed only for the boards that have an interface between the microcontroller and the computer’s USB, like Mega, Uno, Mini, Nano. Boards like Leonardo, Esplora and Micro, with the USB directly managed by the microcontroller, don’t need the capacitor.

Basically, if you don’t put it on the Mega after loading the ArduinoISP sketch, your Mega will reset instead of the target board, which isn’t very helpful! :laughing: Or at least, that’s what I think it prevents! :open_mouth:

Looks like the 644 RST should be connected to D10 on the Mega, not SS…

Longer answer: Yes absolutely because the capacitor suppresses a voltage drop of the RESET line from high to low when programmer tool initializes the device and does an eventual auto-reset, like @pfeerick said.

Some thoughts of mine:

  • double check with a multimeter that the reset pin of the ISP header goes through to the actual reset pin of the ATMega644. If it’s not, then the programmer can impossibly reset the chip, and then you need to make direct connection to that pins, somehow, either by soldering it or tapping that pin with the needed wire
  • double check that you’re NOT feeding 5V from the Arduino Mega into the target board when the target board is connected to its power supply at the same time! You’ll have two power supplies fighting each other and there’ll be a current between them. Either disconnect VCC between the two boards or disconnect the power supply from the target board (5V from the Mega should be plenty to power your target board which only has like the MCU and 3 other chips…)
  • double check voltages on the board to see if between GND and VCC of the board there really is a good 5V supply
  • double check the wiring as proposed by @pfeerick
  • note that I’ve seen that the ISP sketches / resources talk about “old school wiring” and new wiring. So there might be conflicting information around. Look into the source code of the exact (and hopefully recent) version of the Arduino as ISP sketch that you’re putting on your Arduino Mega, it should already tell you exactly how the wireup is supposed to be
  • you can sanity check that the “Arduino as ISP” Mega board is generally working by e.g. flashing a known-good Arduino Uno with the exact wireup as shown above. This would instantly eliminate the programmer from being the problem
  • if you’ve tried all wiring methods, all the voltages seem good and the programmer works in general on another chip then you can
    1. Add -F on a new line in the list of upload_flags of the platformio.ini, to try a “force”
    2. If this very likely makes no difference replace the ATMega644 of your target board, as it might by truely dead by “something”. From your pictures I do see that the chip is socketed so you can just pull it out and put a new one in, if you have a replacement part (that can also still be ordered today)
  • if you think PlatformIO is the problem (which it should be not, seems like a wiring or chip problem to me), you can still sanity-check that by doing it only within the Arduino IDE. The core you should be using is GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535 with the “ATmega644” board selected. Then do a “burn bootloader” with the Arduino as ISP programmer selected and check if that works.
  • as another caveat: your microcontroller has no crystall oscillator attached to its XTAL1 and XTAL2 pins, it’s just an empty hole. The microcontroller should recognize that and start up on its internal RC oscillator (8MHz) though, I hope. Otherwise the chip will just do nothing without a clock. Possible clock settings are listed in the core