chipKIT® Development Platform

Inspired by Arduino™

Trouble creating interrupt handlers

Created Tue, 21 Jun 2011 15:03:26 +0000 by raphael


raphael

Tue, 21 Jun 2011 15:03:26 +0000

Hi folks!

I'm unable to get a simple interrupt handler to compile. Here's the relevant code, and below that is the error:

void setup() {
........
OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0xFFFF);
ConfigIntTimer2((T2_INT_ON | T2_INT_PRIOR_3)); 
INTEnableSystemMultiVectoredInt();
........
}

void __ISR(_TIMER_2_VECTOR,ipl3) comms_handler(void)
{
  mT2ClearIntFlag();  // Clear interrupt flag
digitalWrite(LED, HIGH);
}

And the error:

FURY_II.cpp.o: In function __vector_dispatch_8': FURY_II.cpp:(.vector_8+0x0): undefined reference to comms_handler' collect2: ld returned 1 exit status

Anyone have any idea what I'm forgetting?

Thanks!


jumpin_jack

Tue, 21 Jun 2011 17:04:30 +0000

Try

void setup() {
........
OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0xFFFF);
ConfigIntTimer2((T2_INT_ON | T2_INT_PRIOR_3)); 
INTEnableSystemMultiVectoredInt();
........
}

#ifdef __cplusplus
extern "C" {
#endif

void __ISR(_TIMER_2_VECTOR,IPL3AUTO) comms_handler(void)
{
  mT2ClearIntFlag();  // Clear interrupt flag
digitalWrite(LED, HIGH);
}
#ifdef __cplusplus
}
#endif

I believe that ISRs must be C functions.


raphael

Tue, 21 Jun 2011 19:16:31 +0000

Solved!

Thanks very much!


Mark

Tue, 21 Jun 2011 22:08:36 +0000

Dont put INTEnableSystemMultiVectoredInt in your setup code or anyplace else, it is already called BEFORE your setup code gets called

look at wiring.c for details

Mark


whoover

Fri, 29 Jul 2011 00:44:21 +0000

How do you create an external interrupt for a falling edge? Is there any reference material that we can refer to? I want to simulate attachInterrupt (until it's fixed) and I'm note sure how to set INTEDG to zero in ConfigIntTimer1 for Pin 2.


bshapiro

Fri, 29 Jul 2011 20:52:54 +0000

In setup(), add: ConfigINT3(EXT_INT_PRI_6 | FALLING_EDGE_INT | EXT_INT_ENABLE);

and your ISR: extern "C" { //falling edge: void __ISR(_EXTERNAL_3_VECTOR, ipl6) INT_3Interrupt() { <your code>

mINT3ClearIntFlag();
} }

Documentation in Microchip data sheets: sorry, link "too spamy" <sigh>

There are five ext interrupts (0-4) and the example uses #3. You can choose a different intrpt priority level, (0-7), but make sure they agree (between the config and ISR).

The pins: //EXT MAX UNO //INT --- --- //0 RD0(3) RF6(38) //1 RE8(2) RD8(2) //2 RE9(7) RD9(7)
//3 RA14(21) RD10(8) //4 RA15(20) RD11(35)

Bruce


whoover

Fri, 29 Jul 2011 23:35:38 +0000

Thanks bshapiro. I had it working with

...
// setup
mINT1SetIntPriority(1);
mINT1IntEnable(1);
...
#ifdef __cplusplus
extern "C" {
#endif
void __ISR(_EXTERNAL_1_VECTOR, ipl1) int1Handler(void) {
  // Clear interrupt flag
  mINT1ClearIntFlag();
}
#ifdef __cplusplus
}
#endif

... but "ConfigINT1" seems much cleaner

[color=#FF0000]NOTE: At the time of this post, if you use any other priority level other than one, and have a longer than normal operation within an external interrupt, the interrupt will not return to your main loop for well over a minute![/color] Tested on an uno32. It's not a good idea to have long instructions inside an interrupt in the first place, but sometimes it's difficult to avoid (like a pulseIn you don't want to miss).

Only one issue though. I have an IR receiver attached to pin 2, but with a falling edge or rising edge it looks like "pulseIn(2, LOW)" is always returning zero. Update: I seen [color=#000080]this link[/color] where I will continue the thread (seeing it's unrelated to interrupts)


Demolishun

Fri, 03 May 2013 07:27:47 +0000

@jumpin_jack Thank you for your C function fix. I was tearing my hair out!