1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

MPLAB and debug mode error PK2Error0028

Discussion in 'Microcontrollers' started by edeca, Mar 8, 2009.

  1. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    I've just spent 30 minutes wondering why debug mode didn't work on a 16F88. Everything seemed to compile and program fine but I constantly got the error "PK2Error0028: Unable to enter debug mode".

    It was all because I had:

    Code (text):
    #include "p16f88.inc"
    Instead of:

    Code (text):
    #include <p16f88.inc>
    So this is mainly here for my memory, but perhaps it will help somebody else in the long run.
     
    Last edited: Mar 8, 2009
  2. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Actually that hasn't helped at all. I'm now getting the same error again. The 16F88 is wired the same way as the 18F1320 I just took off the board. Pull-up resistor and diode to MCLR.

    My program is as simple as they get:

    Code (text):
            errorlevel -302     ; Disable bank warnings
            #include <p16f88.inc>
            list p=16f88

            __CONFIG    _CONFIG1, _CPD_OFF & _CP_OFF & _DEBUG_ON & _LVP_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _WRT_PROTECT_OFF & _INTRC_IO & _BODEN_OFF

            ;cblock 0x20        ; Variables
            ;   test
            ;endc

            org 0
            nop
            goto Start

    Start   clrf    STATUS
            clrf    PORTA
            clrf    PORTB

            bsf     STATUS, RP0     ; Bank 1
            clrf    TRISA           ; All PORTA output
            clrf    TRISB           ; All PORTB output
       
            ; Disable A/D, all ports digital
            clrf    ANSEL
       
            ; Disable comparators
            movlw   0x07
            movwf   CMCON
       
            ; Set 4 MHz clock
            ;banksel OSCCON
            bsf     OSCCON, IRCF2
            bsf     OSCCON, IRCF1
            bcf     OSCCON, IRCF0
       
            bcf     STATUS, RP0     ; Bank 0
            movlw   0xFF
            movwf   PORTA

    Loop    goto    Loop

            end
    Do I need to do anything special with the Junebug to make ICD work? Programming/verifying is fine even when I'm getting the error.
     
  3. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Remove
    _MCLR_ON & _PWRTE_ON & _DEBUG_ON
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England

    Thanks Bill, another stupid error! Do I need to put them back if compiling for release? Or will changing profiles in MPLAB do that for me.
     
  6. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Hm. I still get the error sporadically. Here's the output, which I think is fine except the last error.

    Code (text):
    Initializing PICkit 2 version 0.0.3.61
    Found PICkit 2 - Operating System Version 2.32.0
    Target power detected ( 4.99V)
    PIC16F88 found (Rev 0x8)
    PICkit 2 Ready

    PKWarn0006:  The local copy of program memory has been changed since the last program operation.  Should PICkit 2 program the target (fix) before proceeding?
    Programming Target (08/03/2009  21:53:46)
    PIC16F88 found (Rev 0x8)
    Erasing Target
    Programming Program Memory (0x0 - 0x13)
    Programming Program Memory (0x800 - 0x803)
    Verifying Program Memory (0x0 - 0x13)
    Verifying Program Memory (0x800 - 0x803)
    Programming Debug Executive (0x-F00 - 0xFFF)
    Verifying Debug Executive (0xF00 - 0xFFF)
    Programming Debug Vector
    Verifying Debug Vector
    Programming Configuration Memory
    Verifying Configuration Memory
    Running Target
    PK2Error0028:  Unable to enter debug mode
    Debug mode entered, DE Version = 0.0.0
    PICkit 2 Ready
    My program hasn't changed, except your recommended removal which makes config:

    Code (text):
    __CONFIG    _CONFIG1, _CPD_OFF & _CP_OFF & _LVP_OFF & _WDT_OFF & _WRT_PROTECT_OFF & _INTRC_IO & _BODEN_OFF
    This is driving me nuts now. I thought I'd be able to sit down and write out "my first ASM program" but I haven't got past flashing the status LED because I can't debug. How infuriating :)
     
  7. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    It looks ok, what version of MPLAB are you running?
     
  8. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    MPLAB 8.2. I've just switched from the ICD header to the pins along the top of the Junebug and get the same results. I have also tried powering from the Junebug rather than external power.

    MPLAB also constantly tells me that the project is out of date, even if I don't change anything. I'm unsure what causes that either.

    In any case, I'm not sure my Junebug has ever been right since I had to separate the tracks with a knife! I sit down for a day to play and never seem to get past ICD errors when I start trying hardware instead of simulation.

    I'm tempted to pick up a PICkit2 for £30.. if only there weren't so many cheap Chinese knock offs!
     
  9. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I've tried your program with both a genuine PK2 and my Junebug. Both give the error with MPLAB 8.20a but you can still single step.
    I've modified the program for a 18F1320 and it works fine. Seems like an MPLAB 8.20a bug...
     
  10. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Weird. Sorry to sound negative about the Junebug, my frustration got the better of me!

    I'll bug it at Microchip if I can find the right place. I need the A/D on the 16F88 or I'd swap it out for another part.
     
  11. UTMonkey

    UTMonkey New Member

    Joined:
    Oct 16, 2007
    Messages:
    450
    Likes:
    3
    Location:
    Chesterfield, Derbyshire - UK
    I have had this with the PICKIT2 - unplugging the USB and closing down MPBLAB seems to get me back on track. Doesn't really happen that often though.
     
  12. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    I've tried that a few times. The only thing I haven't tried is another machine, I'll see if I have time tonight to install the software and try it on my laptop.
     
  13. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    I wonder if it's the new absolute vs relocate mode in 8.20?

    PS the 18F1320 has an improved AD vs the 16F88. It doesn't have the comparitors though.
     
    Last edited: Mar 9, 2009
  14. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    An interesting thought. I'll try an older MPLAB tonight and also try both of the modes (I don't remember which I chose). I haven't raised a support ticket yet so I will wait until I've tested.

    I'm flying to Canada for a week (hi Bill and anybody else there :D) so wont have much time to play.
     
  15. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Enjoy your stay here eh.
     
  16. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
  17. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    Make sure you check program after succesful build.
     
  18. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Bill, a quick look at the Junebug circuit suggests the two 4.7K pull-down resistors are included, so there's no chance I need those?
     
  19. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    It's the same as the red button PICkit2. Try your program with the 18F1320 and see if the problem goes away. Any reason the A/D in the 18F1320 is not good for your application?
     
  20. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    Actually I was just thinking I'd try a 16F part as I've never used them. Perhaps I'll stick to the 18F for now, that's not a bad idea.

    Thanks for the clarification on the Junebug. I'll target my application at the 18F1320 and perhaps try another project on the 16F88 later.
     
  21. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    The 18F are so much nicer to use than the 16F and cost about the same. The A/D also includes a programmable acquisition timer so it's really easy to use.

    PS set the OSCCON as early as possible to because the debugger will run so much faster...

    movlw 0x62 ; 4MHz
    movwf OSCCON
     

Share This Page