Masking interrupts

I wonder, could somebody point me toward a sketch which has an interrupt routine which is masked for a period, interrupts which would occur if enabled are NOT queued while the interrupt is masked. Then the interrupt routine is unmasked and the next interrupt is caught and processed before the interrupts are masked once again.

what the interrupt does isn't important, just the mechanical function of the software.

I've  tried various methods but whatever I have done has resulted in the interrupt either being permanently active or never occurring.

what I want to do is to periodically read the ir port of my Elster AC100.... But only when I want to do it rather than when an ir stream is detected on the pulse port. Interrupts occurring all of the time would upset my measurement loop.




stuart's picture

Re: Masking interrupts

Can you not simply use the cli(); command?

More info here..,45239.0.html


Series530's picture

Re: Masking interrupts

Thanks Stuart,

I had seen that link but but had also read that it isn't a good idea to leave interrupts disabled for any length of time as much of the arduino code relies upon interrupts to operate.  As my code would need to specifically ignore pulse interrupts for 99% of the time, I could end up in a mess if I tried to use cli or sei. Well, that was my thought anyway.
My idea thus was to bind the interrupt routine to the interrupt handler at the time that I wanted to act upon the pulses and then unbind it again once I had read the meter. The problem was that I couldn't  get it to work : it simply didn't service the interrupts when I turned on the bind. I tried putting loops with volatile variables  inside the interrupt just to pad the time (can't use delay) but still nothing worked.
Hence my request on here.
MartinR's picture

Re: Masking interrupts

you should be able to mask the pulse interrupt with bitClear(EIMSK,INT1) and re-enable it with bitSet(EIMSK,INT1)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.