Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupt Alarm Always Fires? #14

Open
davescherler opened this issue Aug 21, 2017 · 1 comment
Open

Interrupt Alarm Always Fires? #14

davescherler opened this issue Aug 21, 2017 · 1 comment

Comments

@davescherler
Copy link

Hi There,

This is a terrific library (thank you!) and yy apologies if this is not in the correct location but I can't for the life of me figure out what my issue is. I'm using your DS3231_intalarm example to detect an alarm is fired. I'm using an ESP8266 since i want to add Wifi to my project once I get this sorted out. My ultimate goal is to put the ESP8266 into light sleep and wake it up from a daily alarm triggered by the DS3231. So far, I've been able to use this library to read the time and set alarms.

Here's my issue: I'm able to set the alarm but it seems to fire every second. I've tried adding a pullup resistor (10k down to 220O) to VCC as I've read elsewhere the output pin of the DS3231 needs to be tied to VCC. However, when I do that, the alarm never fires. I've experimented with different size resistors but the result is either one of these two outcomes: 1) the alarm seems to fire every second or 2) it never fires.

Here is the output to my Monitor when it fires every second:

20-08-2017 23:17:03 - Unknown
20-08-2017 23:17:06 - Unknown
the 20 second alarm just went off!
20-08-2017 23:17:09 - Unknown
the 20 second alarm just went off!
20-08-2017 23:17:12 - Unknown
the 20 second alarm just went off!
20-08-2017 23:17:15 - Unknown
the 20 second alarm just went off!
20-08-2017 23:17:18 - Unknown
the 20 second alarm just went off!

And here is my code:

`#include <Wire.h>
#include <DS3231.h>

DS3231 clock;
RTCDateTime dt;
volatile boolean alarmFlag = false;

void alarmISR()
{
alarmFlag = true;
}

void setup()
{
Serial.begin(115200);

// Initialize DS3231
Serial.println("Initialize DS3231");
clock.begin();
clock.armAlarm1(false);
clock.armAlarm2(false);
clock.clearAlarm1();
clock.clearAlarm2();

//set a 20 second alarm
clock.setAlarm1(0, 0, 0, 20, DS3231_MATCH_S);

// SQW pin on DS3231 to attached to pin 14 on ESP8266.
pinMode(14, INPUT_);
attachInterrupt(14, alarmISR, FALLING);
}

void loop()
{
dt = clock.getDateTime();
Serial.println(clock.dateFormat("d-m-Y H:i:s - l", dt));

if (isAlarm == true) {
Serial.println("the 20 second alarm just went off!");
isAlarm = false;
clock.clearAlarm1();
}
delay(3000);
}
`

Any help or advice would be greatly appreciated!

@Eheran1
Copy link

Eheran1 commented Sep 23, 2017

Most likely adding this befor setting the alarm will solve ur problem, since the SQW was still turned on, in ur case at 1Hz. Mine was 8kHz... but after fixing that I found "another" (since this here is technically not one) problem with the library... gonna open it up now...

  // Select output as rate to 1Hz
  clock.setOutput(DS3231_1HZ);
  // Disable SQW-clock 
  clock.enable32kHz(false);
  // Enable output
  //clock.enableOutput(true);
  // Disable output
  clock.enableOutput(false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants