Can we disble only one interrupt?

Dear All

Merry christmas!!!

I am using ArduinoLowPower library to make my board sleeping.

The borad can wakeup after a RTC schedule or with an interrupt
I defineed a pin to wakeup the board the a drop falls in the bunket.

LLowPower.attachInterruptWakeup(pin_wattering, triggeredDropWattering, RISING);

It works fine. That's an example because in the following case, the drop counting is not used.

Now I am using a Davis anemometer to calculate the wind speed. It also work with interrupts

See the liine

attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);

here: http://cactus.io/hookups/weather/anemometer/davis/hookup-arduino-to-davis-anemometer-wind-speed
My borad is sleeping 15mn, wake up, take the wind measure, wind direction, solar radiation, and sleep for 15min.
But after the board goes to sleep, and as the cups will still rotate, I am afraid the interrupt generate by the anemoeter, will wake up the board, and it should not

To be sure that there will be no malfunction when the board sleeps, I would like to unactive the interrupt when the cups rotate, and activate it only after the board wake up for the neat measure.

Can we inactivate/activate only this, between measures?

attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);

I found nointerrrupt(), but I beleive, it will disable ALL interrupt, which is not my goal. I only would like to disable interrupt from my anemometer.
I also beleive, it would not wake up the board without that:

LowPower.attachInterruptWakeup(pin_aneno, triggeredDropWind, RISING);

But I would feel me better :), if the interruots at 'WindSensorPin' will be ignore during the sleep process.

Many thanks

It looks as though the low power library needs you to specify a particular pin for wakeup. I can't see anything that implies that all interrupts would do it. Try it and see. If there is a problem, you can use detach interrupt for the anemometer interrupt.

OK, that's a good idea, but during this time, I read:

When writing an Interrupt Service Routine (ISR):

  • Keep it short
  • Don't use delay ()
  • Don't do serial prints
  • Make variables shared with the main code volatile
  • Variables shared with main code may need to be protected by "critical sections" (see below)
  • Don't try to turn interrupts off or on

I should then avoid to turn on/off, isn't?
I also forgot, I power my sensor with another pin. If I unpower my sensor during the sleep period, I should not be worried about interrupt generate by the cups of anemometer.

I see no reason why you can't detach an interrupt. I suspect what that advice is trying to say is that if you turn interrupts off for long, you may miss some and create a hard to find bug.

Note though that you have to turn them off if you want to get the value of something touched in an ISR that's bigger than a single byte.

Don't try to turn interrupts off or on

That refers to the code in the interrupt routine.

To access multibyte variables from the main program, you need to protect the value from corruption while it is being accessed. For example, you could write something like this:

// global variable shared with interrupt
volatile int steps=0;
...
// in loop()
noInterrupts();  //all interrupts off
int steps_copy = steps; //make a copy of the interrupt variable
interrupts(); //all on again
Serial.println(steps_copy); //use the copy in subsequent code

Which Arduino pin is this connected "WindSensorPin"? and this "pin_wattering"? You can disable the interrupt source by modifying some registers before going to sleep, and re-enable it after waking up

See: https://www.arduino.cc/reference/en/language/functions/external-interrupts/detachinterrupt/

Dear All,

Thanks for your eply
My only worrie is my anemometer wake up the board while it sleep. As my cups will turn at any time.
I am going to attach it as the following

attachInterrupt(digitalPinToInterrupt(pin_aneno), isr_rotation, FALLING);

I will not attach it with the following

LowPower.attachInterruptWakeup(pin_aneno, triggeredDropWind, RISING);

Otherwire, it will always wakeup the board, because of the ArduinoLowPower.
But I was afraid, that

attachInterrupt(digitalPinToInterrupt(pin_aneno), isr_rotation, FALLING);

will wake up the board.
Now, I have two option:

  1. I detach the pin
detachInterrupt(digitalPinToInterrupt(pin_aneno));
  1. Or I unpower the sensor by changing the state of the power pin from HIGH to LOW.

You can set/unset a single bit to enable/disable any specific interrupt. There is hardly ever a need to “detach” an interrupt.

For the Uno, interrupts on the INT0 and INT1 pins are controlled by the EIMSK register.

jremington:
You can set/unset a single bit to enable/disable any specific interrupt. There is hardly ever a need to "detach" an interrupt.

For the Uno, interrupts on the INT0 and INT1 pins are controlled by the EIMSK register.

I agree.

When working with interrupts it is essential to have a copy of the Atmega 328 datasheet (assuming you are using and Uno or nano) which contains all the details of the registers such as EIMSK and how to use them.

...R

There is hardly ever a need to “detach” an interrupt.
For the Uno, interrupts on the INT0 and INT1 pins are controlled by the EIMSK register.

A review of the source code in pins_Arduino.h and WInterrupts.c shows that the ide abstraction level command detachInterrupt(digitalPinToInterrupt(pin)) simply clears the correct EIMSK bit.

Interesting! That is not what I would expect a routine named "detach" to do, which would in addition reroute the interrupt vector to a suitable default.

You’ll probably find you don’t even need interrupts to count pulses from an anemometer. You can simply poll the pin it is connected to. You’d probably have to apply some debouncing if that is not already handled somewhere.
So the mcu would periodically wake up, you’d start counting pulses, or at least measure the period between two pulses. After sampling you’d then force the mcu into sleep mode.