chipKIT® Development Platform

Inspired by Arduino™

ChipKIT Uno32 interrupt service routine.

Created Fri, 13 Jun 2014 04:45:06 +0000 by simon


simon

Fri, 13 Jun 2014 04:45:06 +0000

Hello, I recently bought a Chipkit Uno32, and I am new to this device and microchips in general. Previously, I have some small experience programming a PIC24.

I am trying to get a interrupt service routine to run, and the interrupt flag gets set, but the ISR never runs. I'm guessing there is something wrong with the way I declared the ISR function, but I can't find any documentation on how to write the ISR function.

Here is my code:

[color=#FF0000]void[/color] [color=#FF8000]setup/color [color=#FF0000]int[/color] on=0; [color=#FF0000]void[/color] [color=#FF8000]loop/color { [color=#8B308B]Serial[/color].[color=#FF8000]println/color; [color=#8B308B]Serial[/color].[color=#FF8000]println/color; [color=#FF8000]delay/color; } [color=#FF0000]void[/color] attribute((interrupt, auto_psv)) _T1Interrupt([color=#FF0000]void[/color])

Basically, I just want the timer to run the ISR after it gets to 1000 counts. When the ISR runs, it sets "on" to 1, and that shows me that the ISR ran.


majenko

Fri, 13 Jun 2014 08:24:10 +0000

There's two thing to note there...

Firstly you're programming in C++, not C, so functions suffer from name mangling. You can avoid that by wrapping your ISR function in a C extern block:

extern "C" {
  void __attribute__((__interrupt__, __auto_psv__)) _T1Interrupt(void)
  {
    on=1;
    IFS0bits.T1IF=0;
    Serial.println("in ISR");
  }
}

Another important factor is that the chipKIT core has its own set of ISR handling routines, and ISR dispatch table, which you should be using. Check out the source code to the SoftPWMServo (in hardware/pic32/libraries) to see how it attaches an ISR to an interrupt vector and configures the IPL etc.