chipKIT® Development Platform

Inspired by Arduino™

Problem Using Interrupt

Created Tue, 16 Aug 2011 15:12:07 +0000 by python


python

Tue, 16 Aug 2011 15:12:07 +0000

Hi,

I am developing an application and was using an external interrupt on one of the IO pin (pin35).

  • I configured it to trigger an external interrupt on a falling edge at the setup state of my program.
  • Then it was disable using this function call "DisableINT0" when it was not needed
  • Some point in the program it was re-enable back using "EnableINT0".

The problem i face is that when i disable and then re-enable back the external interrupt. I found that the interrupt service routine was called immediately without any sign of a falling edge on the pin.

I was troubleshooting but still cannot find a reason for it. Is there any issue using "DisableINT0" and "EnableINT0"? Or is there any missing steps that i need to do when i am enabling and disabling of the interrupt?


hairymnstr

Tue, 16 Aug 2011 15:55:24 +0000

In a PIC processor the interrupt flags are affected whether or not the interrupt is enabled. Therefore an edge will set the interrupt flag any time before the EnableINT0 is called, once enabled it will immediately generate an interrupt because the interrupt flag is set. To make sure this doesn't happen you must manually clear the flag before you enable the interrupt. I can't remember where the flag is off the top of my head.


python

Wed, 17 Aug 2011 01:54:26 +0000

Hi,

This is what i did before re-enabling back the external interrupt

INTClearFlag(INT_INT0); EnableINT0;

But i still get the same problem. Did i call the wrong macro code?


hairymnstr

Wed, 17 Aug 2011 12:08:31 +0000

I'm not sure, I don't know where that macro is defined, you could try:

IFS0CLR = _IFS0_INT0IF_MASK;