Created Mon, 18 Nov 2013 19:54:36 +0000 by 19filo83
Mon, 18 Nov 2013 19:54:36 +0000
Good evening to everyone. I'm trying to use external interrupts on chipkit max32 with mpide-0023-windows-20120903.zip — mpide-0023-windows-20120903-newlib release, but they don't work! I tried both to manipulate interrupt registers as specified in the pic32 manual and to use macro functions in the plib.h library, but nothing happened... This is my code:
unsigned long wIndex=0;
unsigned int buffer[4096]={'\0'};
void setup(void)
{
pinMode(20,INPUT); //external interrupt 4
pinMode(21,INPUT); //external interrupt 3
IEC0CLR=0x00088000; //disable both external interrupts 3 and 4
INTCONSET=0x00000008; //set rising edge for external interrupt 3 and falling edge for //external interrupt 4
IFS0CLR=0x00088000; //clear both external interrupt flags 3 and 4
IEC0SET=0x00088000; //enable both external interrupts 3 and 4
}
void loop()
{}
void __ISR(_EXTERNAL_3_VECTOR) ExtInt3Handler(void)
{
buffer[wIndex]=wIndex;
wIndex++;
IFS0CLR=0x00008000;
}
void __ISR(_EXTERNAL_4_VECTOR) ExtInt4Handler(void)
{
IFS0CLR=0x00080000;
}
Interrupts don't handle... Any suggestions? Many thanks
Mon, 18 Nov 2013 21:48:10 +0000
Make windex volatile:
volatile unsigned long wIndex=0;
Otherwise the compiler won't think it's used for anything much and will optimize it out.
Tue, 19 Nov 2013 07:14:09 +0000
Dear majenko, I'm sorry for the mistake. Effectively the wIndex variable is declared as volatile unsigned long in my code. Any suggestion about the external interrupts? Thanks
Tue, 19 Nov 2013 17:38:46 +0000
Why are you even trying to do it that way? Just use attachInterrupt() to do the job for you.
Tue, 19 Nov 2013 17:51:14 +0000
AttachInterrupt() is too slow so it doesn't match with my timing requirements.
Tue, 19 Nov 2013 17:53:37 +0000
Then you may need to modify the core files or the interrupt handlers in there may well be conflicting with yours.
Tue, 19 Nov 2013 18:11:28 +0000
Have you an idea about how to modify the core files? I tried several time with out any success.
Tue, 19 Nov 2013 18:32:22 +0000
Edit the file WInterrupts.c and comment out everything from "// INT0 ISR" downwards (best to wrap that lot in #if 0 ... #endif).
Copy that block into your sketch as well, and edit the ISR functions as needed.
Then I would also use attachInterrupt() pointing to a dummy (empty) function to enable the interrupts you want - that way you don't need to mess with the registers and you're working with known good code.
Wed, 20 Nov 2013 02:42:37 +0000
You need to wrap your ISR in
extern "C"
{
//stuff
}
To prevent name mangling
Wed, 20 Nov 2013 17:54:59 +0000
Dear mikes, interrupts work!!!!! Your suggestion was very useful!! Thank you very much.