-->
Page 2 of 3

Re: Setup the desired interrupt

PostPosted: Fri Aug 18, 2017 12:38 am
by DTrain123
Do you need to disable interrupts when your inside an interrupt handler?
I thought you could only have one interrupt happening at a time?

Re: Setup the desired interrupt

PostPosted: Fri Aug 18, 2017 6:23 am
by nimaaryamehr
DTrain123 wrote:Do you need to disable interrupts when your inside an interrupt handler?
I thought you could only have one interrupt happening at a time?



If I want to get pin0 for another interruption
How should I do this?

Re: Setup the desired interrupt

PostPosted: Fri Aug 18, 2017 10:02 am
by QuickFix
DTrain123 wrote:Do you need to disable interrupts when your inside an interrupt handler?
I thought you could only have one interrupt happening at a time?

It actually depends on what the interrupt needs to be doing.
When there are shared variables (for instance), you might not want to read/write their value at some points, since it may mess up your program flow.

You can have multiple interrupts at one time (each connected at a different GPIO), so you have to carefully consider whether you want to disable/re-enable interrupts inside an interrupt (but it's not compulsory).

Re: Setup the desired interrupt

PostPosted: Sat Aug 19, 2017 8:48 pm
by DTrain123
QuickFix wrote: you have to carefully consider whether you want to disable/re-enable interrupts inside an interrupt (but it's not compulsory).


I had a look at core_esp8266_wiring_digital.c where attachInterrupt is defined.
On line 127 it has the code which calls the interrupt handler method:
Code: Select all      // to make ISR compatible to Arduino AVR model where interrupts are disabled
      // we disable them before we call the client ISR
      uint32_t savedPS = xt_rsil(15); // stop other interrupts
      handler->fn();
      xt_wsr_ps(savedPS);

In Arduino.h noInterrupts() is defined:
Code: Select all#define noInterrupts() xt_rsil(15)

So interrupts have already been disabled before your method gets called. So no need to call noInterrupts() in your interrupt handler code.