I own a brand new PICkit 4, and I'm trying to get a debug session working. This is what I did:
1. Cut reset pin from the USB-UART programmer. There is a Reset EN pad that can be cut off to isolate the USB-UART programmer and only use the reset pin from headers.
2.Connect PICkit 4 to Arduino Mega board. I connected it according to the following table with the JTAG pins of the board. Also I connected the reset, VCC and GND pins.
3. I did a new project in MPLAB X IDE v5.50, just a new main.c with the classic blink LED program.
#define F_CPU 16000000UL
#include <xc.h>
#include <util/delay.h>
int main(void) {
DDRB = 0x00;
while(1){
PORTB |= (0x80);
_delay_ms(500);
PORTB &= ~(0x80);
_delay_ms(500);
}
return 0;
}
4. Connect PICkit 4 to a PC and power up the Mega board. With this I had a beautiful cyan light on the PICkit 4.
5. Read and set configurations bits. Just going into Production>Set Configuration Bits I was able to read them and set them like this: According to this forum Arduino board has this SUT_CKSEL fuses
After all this, I'm able to program the device with the button "Make and Program Device Main Project".
First Issue: The program doesn't work, I mean the LED is not blinking. I'm really sure this is a fuse issue; which fuse is wrong?
Second Issue: Unable to begin debugging session. I've set OCDEN, JTAGEN and SPIEN bits and I got this:
Connecting to MPLAB PICkit 4...
Currently loaded versions:
Application version............1.13.236
Boot version...................01.00.00
Tool pack version .............1.9.1163
Target voltage detected
Calculating memory ranges for operation...
Configuration memory will not be programmed because no configuration bits settings have been defined in your code.
To program configuration memory, either define the settings in your code or use the Program Configuration Bits button on the configuration memory window.
Erasing...
The following memory area(s) will be programmed:
program memory: start address = 0x0, end address = 0xff
Unable to attach to target, OCDEN config bit is not set
Aborted
When I cleared the OCDEN fuse I got the same. I'm actually very surprised that I can flash the program and read/write fuses, but I can't start a debug session.
Also, I've tried with Microchip studio, with no luck. Any ideas?