How debug atmega2560 with pickit 4? (Arduino mega board)

Go To Last Post
2 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys.

I owned 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 cutted off to isolate the USB-UART programmer and only use the reset pin from headers.
Click to see the image.


2.Connect pickit 4 to Arduino Mega board. I connected it according the following table with the JTAG pins of the board. Also I connected reset pin, VCC and GND pins.

Pickit4 connections table image.

Mega pins image.


3. I did a new project in MPLAB X IDE v5.50, just a new main.c with classic blink led program.

    #define F_CPU 16000000UL 
    #include <xc.h>
    #include <util/delay.h>
    int main(void) {
        DDRB = 0x00;
            PORTB |= (0x80);
            PORTB &= ~(0x80);
        return 0;

4. Connect pickit 4 to PC and power up Mega board. With this I had a beautiful cyan light on the pickit4.

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
Configuration bits image.

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.
    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


If I clear OCDEN fuse I got the same. I'm actually very surprised that I can flash the program, read/write fuses but I can't start debug session.

Also, I've tried with Microchip studio, with no luck. Any ideas?

Thanks in advance!


  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I doubt if the 16MHz XTAL will oscillate with 0.4-0.9MHz setting.


Run AS7.0


Tools->Device Programming : PK4->JTAG


Set LFUSE to 0xFF i.e. EXTXOSC 8MHZ-20MHz


Debug session should work.

But you need DDRB = 0xFF to see anything on an LED.




Edit.   I just set LFUSE to 0xD8 on a mega644 project (that has a 8MHz XTAL).

It still "ran" but I would not be happy.   Especially with a 16MHz XTAL.


Note that JTAG can read or write Flash, EEPROM, Fuses, ... without a running clock.

But the AVR application will not "run" if the clock is not working.

Last Edited: Sat. Oct 16, 2021 - 07:04 AM