[SOLVED] Problems Programming ATMEGA328P With PICkit4

Thread Starter

enbyhacker

Joined Apr 9, 2023
5
This is likely a very noob question so I apologize in advance.

I have connected the PICkit 4 to the ATMEGA328P in the way this blog post, https://www.yorku.ca/professor/drsmith/2021/07/23/debuggers-mplab-x-and-the-arduino/, which is a post by a york university prof so I think its right.

The error message I am getting is:
'
Data transmission failed. Error code -112 returned while trying to send USB data.

A communication error with the debug tool has occurred. The tool will be reset and should re-enumerate shortly.
Connection Failed.
'
And then in the debugger console:
'
Launching
Could not connect to tool hardware: pk4hybrid, com.microchip.mplab.mdbcore.pk4hybrid.Pk4HybridTooImpl
The debugger could not be started. Terminating debug session.
User program finished
'
I am guessing that the problem is arising with communication between the PICkit4 and the ATMEGA328p.

Of note is that the ATMEGA chips I am using are old but I tried 4 of them. I bought them from digikey about 6 years ago. I do have some ATtinys on the way for a project so I will be retrying with them.

What could be the problem? Where can I find information about the error code?
 

Thread Starter

enbyhacker

Joined Apr 9, 2023
5
Do you have a PIC dev board to test it on?
I only have a curiosity board. I have connected it to my computer with a usb, but it does not have a connected for the pickit.

Is there a way to test the pickit without connecting it to something?

Which dev board would you recommend?
 

trebla

Joined Jun 29, 2019
541
Is there a way to test the pickit without connecting it to something?
You can only test if MPLAB X recognizes it:
run MPLAB X,
if MPLAB is up, connect PICkit to PC,
wait for PC recognizes new device,
create a standalone project with some PIC device and see if MPLAB shows the PICkit as avalilable tool.

To test PICkit programming capabilites you need actual PIC device on breadboard with decoupling capacitor (at least).
 

Thread Starter

enbyhacker

Joined Apr 9, 2023
5
MPLAB X recognizes the programmer. It is when I try to use the programmer that it complains about the USB connection (I think that is what it is saying).

I am using an ATMEGA right now, and currently am trying to program it with it on an Arduino (I cut the reset line as shown in this video
).

I am wondering if the USB cable is bad, so I tried it with a different one but got the same result.

I am using a System76 Galago to try and program it (and the usb ports on said device). Maybe the programmer isn't getting enough current?

I have also reached out to Microchip, so maybe someone there will get back to me.

Thanks!
 

Thread Starter

enbyhacker

Joined Apr 9, 2023
5
I was able to get this problem solved!

Turns out new PICkits sometimes needs to have a PIC project before an AVR project (or something like that).

Here are the steps Microchip shared with me to fix the problem:

  1. Open a project for a PIC device that supports PICKIT4 (for ex: PIC16F1947) in MPLAB X IDE 6.05. (You don't have to connect the target PIC16F1947 MCU to the PC)
  2. Choose newly created project as the main project: Right-click on the project --> Set as the main project.
  3. Connect PICKIT4 to PC and choose this as hardware tool to program.
  4. Click the Program button (Target device need not to be connected). Ignore the error 'hardware not connected'.
  5. Now disconnect the PICKIT4 and connect again.
  6. Now set the project created for ATmega328p as main project and program the ATmega328p device.
 
Top