EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: Volta500 on April 09, 2013, 01:27:39 pm

Title: MPLABX: Unable to debug project
Post by: Volta500 on April 09, 2013, 01:27:39 pm
Hello All,

I am trying to get the debugger working on a simple test program but not having much luck.  :--
When I program it directly it works fine.
Is there some config bit I'm missing or some other setting screwed?

I have also noticed that MPLAB X says that "The requested operation cannot continue with the following configuration bit setting(s):
Flash Program Memory Code Protection bit = All program memory code-protected.
Would you like MPLAB to change the config setting(s) and continue? "
While in my code the CP bit is OFF. If I continue I get the error Failed to program device.

Compiler: Microchip MPLAB XC8 C Compiler V1.12
Chip: PIC16F877A
Programmer: PICKit 3
IDE: MPLAB X V1.70
OS: Windows 7

Code:
Code: [Select]
#include <xc.h>       // Main PIC header file
#include <stdio.h>    // Standwerererdard IO
#include <stdlib.h>   // Standard utility functions
#include <stdint.h>   // Contains standard int definitions
#include <stdbool.h>  // Contains standard Boolean definitions
#include "bk300.h"    // BK300 specific functions and definitions

#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)


void main (void){
    initBoard();
    initUART();

    printf("Blinking LED 1! \n\r");
   
    while (1){
        setLed(1, 1);
        delayMs(100);
        setLed(1, 0);
        delayMs(100);
    }
}

The bk300 header just contains some initialization routines, defines and some functions like setLed(). I doubt it has anything to do with the problem but if you need the content of the file just ask.

Thank you
Title: Re: MPLABX: Unable to debug project
Post by: TheDirty on April 09, 2013, 03:36:10 pm
Just a guess.
I'm pretty new to PIC's and XC8, but I don't recognize your config bit setting, so I'm assuming it's for the old compiler and possible does not work anymore?

The config bit setting I use in XC8 is:
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
__CONFIG(WRT_OFF & PLLEN_OFF & STVREN_ON & LVP_OFF);
__IDLOC(0000);


If you go to Window -> PIC Memory Views -> Configuration Bits there's a little utility there that can help you create the correct compiler directive specific to your processor.
Title: Re: MPLABX: Unable to debug project
Post by: Ax_6 on April 09, 2013, 04:15:45 pm
Try just to delete the last 3 voices: cp, wrt, cpd and let the compiler use the default ones, it could work, also i don't think that there is any problem in the way you wrote the config bit settings (I don't know if I'm using the same version of xc8 as your but I use to write configs as that).
Title: Re: MPLABX: Unable to debug project
Post by: Volta500 on April 09, 2013, 05:33:25 pm
This is the preferred way of writing config bit settings, but xc8 still has legacy support for __CONFIG() but it is deprecated.

DERP- The removal of the last thee config settings solved the issue! Does anyone know why this would give a problem?
Well, at least it it solved. The debugger finally works, although it is quite slow, it is better than nothing. Thank you!