3
\$\begingroup\$

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.

Where is the reset pad

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.

enter image description here

enter image description here

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

enter image description here

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?

\$\endgroup\$
3
  • \$\begingroup\$ DDRB = 0x80; //set led pin as output \$\endgroup\$ Sep 9, 2022 at 8:22
  • \$\begingroup\$ Please be a bit more verbose in your answer. What part of the problem are you addressing with yout anwer and how does it solve it? \$\endgroup\$
    – kruemi
    Sep 9, 2022 at 8:49
  • \$\begingroup\$ Andy - this does not address the question, and the OP has told us what the issue was. I'll make this a comment, but it seems to have minimal value - ubless you can explain further. \$\endgroup\$
    – Russell McMahon
    Sep 9, 2022 at 10:23

2 Answers 2

2
\$\begingroup\$

When connecting the debugger make sure the power supply you're using to power the Mega has stable voltage. That was the problem.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Can you elaborate on that? Was the Supply inherently unstable or did you "just" get the timing for the power up sequence wrong? Or did you swith on in the wrong order? \$\endgroup\$
    – kruemi
    Jul 19, 2022 at 12:17
  • \$\begingroup\$ I was using the USB cable included with the pickit4, and I realized that the frontal USB port of my desktop pc had a 4.0V and was unstable, so I used one port on the back which had 5V stable, then just start a debug session and voilà \$\endgroup\$ Aug 4 at 15:29
  • \$\begingroup\$ Also I used my 100w power supply with stable 5V to power my chip, even using a good phone power adapter is not 5V stable enough \$\endgroup\$ Aug 4 at 15:34
0
\$\begingroup\$

Sorry my reply was too brief to be helpful...and I have been away for a long time! Anyway, in case it helps someone else:

The Atmel chips have Data Direction Ports as input if 0, and output if 1. This is opposite to Microchip PICs, where 1 is input and 0 is output.

To blink the LED on PORT B bit 7 on an Atmel chip, you need to set DDRB to 0x80, so the LED pin is an output.

(If you use DDRB |= 0x80; then you only set the one bit and don't affect any other bits of the DDRB register.)

The fuses SPIEN and JTAGEN are set, so that you can program the chip either with JTAG as you have it connected, or through SPI.

You get a suggestion to read the fuses before programming from the MPLABX IDE, because clearing both of these bits will brick your chip, as you will have disabled both programming methods.

And, you can program but not debug if the OCDEN fuse is not set.

Andy

\$\endgroup\$
1
  • \$\begingroup\$ More than code issues the main reason posting this was why I wasn't able to have a debug session if the chip were responding normally. Check my answer above \$\endgroup\$ Aug 4 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.