Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 8 months ago.
InteruptIn (enabled? disabled?)
Hello I have a question regarding interruptions (InterruptIn). See the code that is posted as an example
#include "mbed.h" InterruptIn button(p5); DigitalOut led(LED1); DigitalOut flash(LED4); void flip() { led = !led; } int main() { button.rise(&flip); // attach the address of the flip function to the rising edge while(1) { // wait around, interrupts will interrupt this! flash = !flash; wait(0.25); } }
When the function flip is called (the interruption was triggered) what happens if I rise button again??
In other words, since the rising of button originates the interrupt, is this disabled when I am servicing that interrupt? or should I explicitly put something like
void flip() { button.disable_irq(); led = !led; // Here I use p5 (ergo button) signal for different purposes) button.enable_irq(); }
My question comes becomes because I have a code that does not use interruptions and I want to reimplement it with interrupts but the pin that generates the interrupt is also used for some processing. ANd a endless loop is not something I want
Thanks
1 Answer
8 years, 8 months ago.
An interrupt will not interrupt itself, so thats not a problem (and using default settings it also won't interrupt any other interrupts, since they all start at maximum priority).
What will happen is that if the pins rises again, the interrupt flag is set again (the interrupt handler clears it before the user function is called). So after your interrupt, it will be called again. So you either need to detect if this happened (for example using a timer), or clear the pending interrupt at the end of your interrupt handler.