title: Arduino Interuppt and sleeping is freezing
body: <p>Ok</p>
  
  <p>I am using an Atmel 1284P with the Mighty Optiboot bootloader if that information is needed.</p>
  
  <p>So I can get each of these things working individually but the moment I put them together I get a very weird result.</p>
  
  <p>I am trying to use an RTC DS3231 with the Arduino sleep function and woken up with an interrupt from the RTC. (Real time clock) with the SQW pin of the RTC attached to my micros interrupt pin.</p>
  
  <p>Each of these things work fine when done alone but once put together the code freezes and does not continue.</p>
  
  <p>Here is my code as of now.
  I’m trying to wake the micro every minute, the global var T being the interval for the waiting time.</p>
  
  <pre><code>#include &lt;avr/sleep.h&gt;
  #include &lt;avr/power.h&gt;
  #include &lt;Wire.h&gt;
  #include "ds3231.h"
  struct ts t;                 // The Time structure
  int T = 1;                   // The sleeping time in minutes
  
  void setup()                    
  {
    pinMode(2,INPUT);                 // my interuppt is on pin 2
    Serial.begin(9600);
    Wire.begin();
    DS3231_init(DS3231_INTCN);         // Start the RTC interface
  }
  
  void loop()
  {
    Serial.println("Running");  // something to see that the micro is wake for a bit and not frozen
    delay(5000);                // a delay in my main code I will be loggin data
  
  
    set_next_alarm();  /// set the next RTC alarm 
  
    DS3231_clear_a2f();   // clear a2 alarm flag and let INT go into high ,,, disabling the interrupt       
  
  
    sleep_enable();                   // get sleep ready
    attachInterrupt(2,wakeUp, LOW);   // set the interrupt things
  
  
  
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is power down for most power savings
    cli();
    sei();
    sleep_cpu();                           // Sleeps here
  
    sleep_disable();                     // Wakes up here
                       // I have ccopied this bit of the sleeping code from the arduino fourums
  }
  
  void wakeUp()                // run when interrupt is called
  {
   detachInterrupt(2);         // detach the interrupt 
    sleep_disable();   
  }
  
  void set_next_alarm(void)              // Set the next alarm here
  {
      unsigned char wakeup_min;
  
      DS3231_get(&amp;t);                    // get the current time
  
                                   // calculate the minute when the next alarm will be triggered
      wakeup_min = (t.min / T + 1) * T;
      if (wakeup_min &gt; 59) {
          wakeup_min -= 60;
      }
  
      boolean flags[4] = { 0, 1, 1, 1 };
  
      DS3231_set_a2(wakeup_min, 0, 0, flags);   // set the alarm 2
  
      // activate Alarm2
      DS3231_set_creg(DS3231_INTCN | DS3231_A2IE);
  }
  </code></pre>
  
  <p>But I get a frozen program when the code runs it sleeps and the alarm is triggered on the RTC.
  I know the RTC is triggering because I have put an LED on the SQW pin and see it go LOW but the RTC keeps the pin LOW and nothing else happens.</p>
  
  <p>Any ideas or help would be appreciated I have been at this for a good 3 weeks but don’t have a clue here.</p>