Have a working prototype using a ATMEGA328P uploading the program via Sketch “Upload using programmer” with STK500 selected. Put a blank ATMEGA328P into the STK500 board socket and program it. Works fine on my custom prototype board.
Now the production version is using a ATMEGA328-AU. Pin numbers were reassigned in the code as needed. I am using an AVRISP MKII to program the chip.
If I try to program via Sketch I get an error “exit status 1”.
If I output a .hex file and use Microchip Studio, the chip programs and verifies fine. But no program execution from the chip.
I'm not sure I understood correctly what you mean by "program via Sketch". Are you using Arduino IDE to do this, or are you using Microchip Studio, or something else?
I also tried using Microchip Studio with a .hex file generated by the Arduino IDE.
Trying to program the chip via the Arduino IDE using an AVRISP MKII programmer generates an error.
If I program the chip via Microchip Studio with the AVRISP MKII and the ARduino generated .hex file, it programs and verifies fine. But does not execute.
The process here was to develop the device using the Arduino libraries but directly to a ATMEGA328P chip not using the UNO board. That worked fine.
But the production hardware uses a ATMEGA328-AU as it needs to be an SMT device. Of course I changed the pin assignments in the code for the 328-AU
I'm going to ask you to provide the full verbose output from an upload attempt.
This procedure is not intended to solve the problem. The purpose is to gather more information.
Please do this:
Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open.
Uncheck the box next to Show verbose output during: ☑ compile in the "Preferences" dialog.
Check the box next to Show verbose output during: ☐ upload.
Click the "OK" button.
The "Preferences" dialog will close.
Attempt program the chip via Arduino IDE using the AVRISP MKII, just as you did before when you encountered the error.
Wait for the upload to fail.
You will see an "Upload error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
Open a reply here on this forum topic by clicking the "Reply" button.
Click the <CODE/> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Sketch uses 1736 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 13 bytes (0%) of dynamic memory, leaving 2035 bytes for local variables. Maximum is 2048 bytes.
"C:\Users\adelle\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\adelle\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -cstk500v2 -Pusb "-Uflash:w:C:\Users\adelle\AppData\Local\Temp\1\arduino\sketches\628088B9B5F1C6DD5D2426FA7F28066E/candle.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 "C:\Users\adelle\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : usb
Using Programmer : stk500v2
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2104)
avrdude done. Thank you.
Failed programming: uploading error: exit status 1
I noted it says “using programmer stk500v2”
But I have AVRISP MKII selected as the programmer in the TOOLS menu.
Also remember the AVRISP MKII programs using Microchip Studio so it is OK and so is the USB connection. Otherwise I would expect Microchip Studio to fail as well.
This error is caused by using a Windows driver for the AVRISP mkII that is not compatible with the "AVRDUDE" tool used by Arduino IDE for this operation. An incompatible "Jungo" driver is installed by Microchip Studio, setting you up for pain when you switch to using AVRDUDE.
My recommendation is to install the "libusbK" driver for the AVRISP mkII. That should solve the problem.
You can install the driver easily by using a tool named "Zadig". I'll provide instructions you can follow to do that:
Connect the AVRISP mkII programmer to your computer with a USB cable.
Download the Zadig driver installation tool from this website: http://zadig.akeo.ie/
Run the downloaded file to start Zadig.
The "Zadig" window will open.
Select "AVRISP mkII" from the drop-down menu in the "Zadig" window. If it doesn't show up on the menu, then select Options > List all devices from the Zadig menus and check again.
Click the ▴ button to the right of the "Driver" selection field until you see "libusbK".
Click the "Replace Driver" button.
An "Installing Driver..." dialog will now appear.
Wait for the driver installation process to finish.
Click the "Close" button in the "Driver Installation" dialog.
Close the "Zadig" window.
Now try using the AVRISP mkII again with Arduino IDE, just as you did before. Hopefully this time the "avrdude: usbdev_open(): did not find any USB device "usb"" error will not occur and everything will work as expected.
In case you for some reason want to continue using Microchip Studio in addition to AVRDUDE/Arduino IDE, you might be interested in the technique described here for the coexistence of both drivers:
I use Microchip Studio for another embedded C compiler quite extensively. So will Zadig break this?
Is there a way to just use Microchip Studio to program the Arduino IDE developed code into a raw ATMEGA328-AU? I though this is what the .hex output does?
The reason for this is that source code is not permitted to leave the engineering dept. Using a .hex file satisfies that. But if I need to use the Arduino IDE, I expose the source code to production.
I don't use Microchip Studio, so I can't say for sure, but I do suspect it will cause the AVRISP mkII to no longer work with Microchip Studio.
If you want to be able to use the AVRISP mkII with both AVRDUDE and Microchip Studio, check the information at the AVR Freaks forum link I shared in my previous reply.
Unfortunately I don't have any meaningful experience with Microchip Studio so I can't answer that. Hopefully one of the other forum helpers will be able to advise.
Perhaps you are already aware, but you can easily generate a .hex file from the sketch using Arduino IDE, by selecting Sketch > Export Compiled Binary from the Arduino IDE menus. This will save the .hex file under a build subfolder in the sketch folder.
The question I can't answer is whether Microchip Studio has the ability to flash arbitrary .hex files.
I am familiar with them. I mean the board has a 16mhz crystal installed. If I select what I normally select on other ATMELS, it won’t let me do it here.
I use Microchip Studio (formerly AVR Studio) a lot, with the AVRISP MK II (better, with the Pololu AVRISP Programmer V2.1).
The combination works very well, if you take care to learn about and understand the differences between the Arduino IDE and Microchip Studio, and the details of the different chip programming techniques.