My first PIC32MX ISR not firing, code is hanging

Post Reply
riceman0
Posts: 9
Joined: Mon Mar 06, 2017 10:42 pm

My first PIC32MX ISR not firing, code is hanging

Post by riceman0 » Mon Mar 06, 2017 10:45 pm

I'm just getting started with a PIC32MX340F12, and MPLABX. My first attempt was to write a timer interrupt, so I worked with the datasheet, compiler manual, and examples and came up with the below. But it doesn't work... the interrupt never fires, and in fact if I leave both the timer interrupt enable (T1IE=1) and the general interrupt enable active ("ei"), it runs for a few seconds then hangs (says "target halted" in debug mode). If I remove either of those, it just runs indefinitely but still no timer interrupt. So I appear to have a pretty bad problem somewhere in my ISR syntax. Does it jump out at anyone?

Like I said I'm just getting started so I'm sure it's a pretty dumb oversight. And as you may notice I like to work as directly as possible with registers and compiler directives (rather than manufacturer supplied functions), I feel like I learn the most that way.

Thanks!

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include "p32mx340f512h.h"
#include <stdint.h>

int x = 0;

int main(int argc, char** argv) 
{
    INTCONbits.MVEC = 1;  // turn on multi-vector interrupts
    T1CON = 0;            // set timer control to 0
    T1CONbits.TCKPS = 1;  // set T1 prescaler to 8
    PR1 = 62499;          // set t1 period
    TMR1 = 0;             // initialize the timer
    T1CONbits.ON = 1;     // activate the timer

    IPC1bits.T1IP = 5;    // T1 priority to 5
    IPC1bits.T1IS = 0;    // T1 secondary priority to 
    IFS0bits.T1IF = 0;    // clear the T1 flag
    IEC0bits.T1IE = 1;    // enable the T1 interrupts

    asm volatile("ei");   // enable interrupts

    while (1)
    {
         x++;   

         if (x > 10000)
         {
             x = 0;
         }
    }
    return (EXIT_SUCCESS);
}

bool zzz = false;

void __attribute__((interrupt(IPL5AUTO))) T1Handler(void)
{
    IFS0bits.T1IF = 0;
    zzz = true;
}

rasmadrak
Posts: 219
Joined: Mon Aug 15, 2011 9:21 pm
Location: Sweden
Contact:

Re: My first PIC32MX ISR not firing, code is hanging

Post by rasmadrak » Mon Mar 06, 2017 11:53 pm

Sorry for not being more helpful, but I suspect you'd get better answers over at the MPLABX forum. :)

http://www.microchip.com/forums/Forums

riceman0
Posts: 9
Joined: Mon Mar 06, 2017 10:42 pm

Re: My first PIC32MX ISR not firing, code is hanging

Post by riceman0 » Mon Mar 06, 2017 11:56 pm

Really? People on this forum aren't programming their chipkits this way?

riceman0
Posts: 9
Joined: Mon Mar 06, 2017 10:42 pm

Re: My first PIC32MX ISR not firing, code is hanging

Post by riceman0 » Mon Mar 06, 2017 11:58 pm

I mean I am using a chipkit uc32...

EmbeddedMan
Posts: 605
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: My first PIC32MX ISR not firing, code is hanging

Post by EmbeddedMan » Tue Mar 07, 2017 2:05 am

riceman0,

I think it's not too common for people to use MPLAB X to program their chipKIT boards at this point. This is primarily because in order to do so, you'd need a hardware programmer, and you'd be operating outside of the 'chipKIT' software ecosystem - i.e. bare metal XC32. The real selling point of chipKIT (or Arduino) is ease of use, and that really appeals to beginners - thus no MPLAB X experience.

Now, we're hoping to change all of that - Just this past Saturday Microchip announced a new MPLAB X chipKIT importer plugin, so that you can suck a chipKIT sketch into MPLAB X, and program/debug it like any other C project. This will make it very very easy for anyone to try out MPLAB X and all of its powerful features, which will be awesome for the chipKIT community.

*Brian

rasmadrak
Posts: 219
Joined: Mon Aug 15, 2011 9:21 pm
Location: Sweden
Contact:

Re: My first PIC32MX ISR not firing, code is hanging

Post by rasmadrak » Tue Mar 07, 2017 9:49 am

EmbeddedMan wrote: Now, we're hoping to change all of that - Just this past Saturday Microchip announced a new MPLAB X chipKIT importer plugin, so that you can suck a chipKIT sketch into MPLAB X, and program/debug it like any other C project. This will make it very very easy for anyone to try out MPLAB X and all of its powerful features, which will be awesome for the chipKIT community.
That sounds great - the lack of debugging is quite a struggle when doing more complex programs. Will definitely check this out! :)

Post Reply