chipKIT® Development Platform

Inspired by Arduino™

My first PIC32MX ISR not firing, code is hanging

Created Mon, 06 Mar 2017 21:45:56 +0000 by riceman0


riceman0

Mon, 06 Mar 2017 21:45:56 +0000

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!

#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

Mon, 06 Mar 2017 22:53:32 +0000

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

[url]http://www.microchip.com/forums/Forums[/url]


riceman0

Mon, 06 Mar 2017 22:56:03 +0000

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


riceman0

Mon, 06 Mar 2017 22:58:57 +0000

I mean I am using a chipkit uc32...


EmbeddedMan

Tue, 07 Mar 2017 01:05:34 +0000

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

Tue, 07 Mar 2017 08:49:40 +0000

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! :)