Buenos días,
Tengo un RTC DS3234 configurado para hacer saltar una alarma cada 5 minutos y que despierte el arduino, el problema es que la interrupcion en el pin 2 parece que bloquea totalmente el arduino, de hecho si no lo duermo se bloquea totalmente cuando se activa,alguien puede ayudarme?
El código es:
// during an alarm the INT pin of the RTC is pulled low
#include <SPI.h>
#include "ds3234.h"
#include "Enerlib.h"
#define BUFF_MAX 256
const int cs = 8; // chip select pin
uint8_t sleep_period = 5; // the sleep interval in minutes between 2 consecutive alarms
Energy energy;
// how often to refresh the info on stdout (ms)
//unsigned long prev = 5000, interval = 5000;
void set_next_alarm(void)
{
struct ts t;
unsigned char wakeup_min;
DS3234_get(cs, &t);
// calculate the minute when the next alarm will be triggered
wakeup_min = (t.min / sleep_period + 1) * sleep_period;
if (wakeup_min > 59) {
wakeup_min -= 60;
}
// flags define what calendar component to be checked against the current time in order
// to trigger the alarm
// A2M2 (minutes) (0 to enable, 1 to disable)
// A2M3 (hour) (0 to enable, 1 to disable)
// A2M4 (day) (0 to enable, 1 to disable)
// DY/DT (dayofweek == 1/dayofmonth == 0)
boolean flags[4] = { 0, 1, 1, 1 };
// set Alarm2. only the minute is set since we ignore the hour and day component
DS3234_set_a2(cs, wakeup_min, 0, 0, flags);
// activate Alarm2
DS3234_set_creg(cs, DS3234_INTCN | DS3234_A2IE);
}
void INT0_ISR(void)
{
/*
The WasSleeping function will return true if Arduino
was sleeping before the IRQ. Subsequent calls to
WasSleeping will return false until Arduino reenters
in a low power state. The WasSleeping function should
only be called in the ISR.
*/
detachInterrupt(0);
/*
set_next_alarm();
// clear a2 alarm flag and let INT go into hi-z
DS3234_clear_a2f(cs);
*/
Serial.println(" Entering interrupt 0");
if (energy.WasSleeping())
{
/*
Arduino was waked up by IRQ.
If you shut down external peripherals before sleeping, you
can reinitialize them here. Look on ATMega's datasheet for
hardware limitations in the ISR when microcontroller just
leave any low power state.
*/
Serial.println(" Interrupt and was sleeping");
}
else
{
/*
The IRQ happened in awake state.
This code is for the "normal" ISR.
*/
Serial.println(" Interrupt and was NOT sleeping");
}
Serial.println(" Exiting interrupt 0");
}
void setup()
{
Serial.begin(9600);
Serial.println("Entering setup");
pinMode(2, INPUT);
delay(5000);
DS3234_init(cs, DS3234_INTCN);
DS3234_clear_a2f(cs);
set_next_alarm();
attachInterrupt(0, INT0_ISR, LOW);
}
void loop()
{
Serial.println("Entering loop");
delay(5000);
Serial.println("Powering down");
energy.PowerDown();
/*
char buff[BUFF_MAX];
struct ts t;
DS3234_get(cs, &t);
// display current time
snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year, t.mon, t.mday, t.hour, t.min, t.sec);
Serial.println(buff);
*/
}
Un saludo.