The Arduino IDE "knows" the names of all the Atmega registers and they are all explained in the Atmel datasheet for the MCU in your Arduino. You have not told us what Arduino you are using.
I plan on using an Uno for now and then change to a Pro Mini board.
The main reason for the 2 interrupts is to wake up from sleep as shown below (this is stripped out version).
Would this way of using interrupts be very reliable?
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
void setup()
{
Serial.begin(9600);
Serial.println("starting...");
digitalWrite (2, HIGH); // pull-up on button
digitalWrite (3, HIGH); // pull-up on button
//enable watchdog to check for code lockups
wdt_enable(WDTO_8S);
}
// interrupt service routine in sleep mode
void wake1 ()
{
} // end of wake
// interrupt service routine in sleep mode
void wake2 ()
{
} // end of wake
void sleepNow ()
{
wdt_disable();
noInterrupts (); // make sure we don't get interrupted before we sleep
byte adcsra_save = ADCSRA;
ADCSRA = 0; // disable ADC
power_all_disable (); // turn off all modules
set_sleep_mode (SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
attachInterrupt (0, wake1, LOW); // allow grounding pin 2 to wake us
attachInterrupt (1, wake2, LOW); // allow grounding pin 2 to wake us
interrupts ();
sleep_cpu (); // now goes to Sleep and waits for the interrupt
detachInterrupt (0); // stop LOW interrupt
detachInterrupt (1); // stop LOW interrupt
ADCSRA = adcsra_save; // stop power reduction
power_all_enable (); // turn on all modules
} // end of sleepNow
void loop()
{
//reset watchdog timer
wdt_reset();
delay(1000);
Serial.println("1");
delay(1000);
Serial.println("2");
delay(1000);
Serial.println("3");
delay(1000);
sleepNow();
//while(1);
}
To raise the stability of your program you should do only what has to be done and nothing more.
Each line of code introduces an additional point of error/failure.
So if you want to disable an interrupt, it’s a good idea to use the bit that is designed to mask it (only).
Setting this bit is one function of detachInterrupt, so it is used by people who are too lazy to look up the register/bit name.
If you never wanted to use that interrupt again, detachInterrupt would be ok (IMHO), but that is not the case.
Fiddling with vectors that are used by interrupts should be restricted to a minumum, if you are into reliability.
The time spent with interrupts disabled should be minimized, if you are into reliability.
Are you shure that detatchInterrupt may be called with interrupts disabled?
Will it return with interrupts disabled?
You don’t have to have an answer to these questions if you just don’t use it in that context.