I got the SQW output to blink an LED at 1 Hz by setting the INTCN to 0. So it seems my pullup resistor works.
But if I now set the INTCN to 1 , A1lE to 1 and the alarm mask bits A1m1thru 4 to 1. The LED should also be blinking at 1 Hz. But it does not. In fact the output "bar(INT)/SQW" is active low, the LED should stay on except when asserted (at 1 Hz interval), but the LED is always dark. What did I do wrong?
chronodot alarm
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: chronodot alarm
What product are you referring to?
If this is the Evil Mad Science Alpha Five alarm clock, support is available on the EMSL forums
If this is the Evil Mad Science Alpha Five alarm clock, support is available on the EMSL forums
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: chronodot alarm
Macetech provides support for the Chronodot.
You might also visit their Chronodot docs page for sample code and tips
You might also visit their Chronodot docs page for sample code and tips
- macegr
- Posts: 293
- Joined: Fri Apr 04, 2008 4:46 pm
Re: chronodot alarm
I'll copy the relevant portion of the DS3231 datasheet:
If you set INTCN to 1, then the square wave output is disabled. Which makes sense...if you were using that pin as an alarm output, how would you tell the difference between an alarm and the square wave signal?Active-Low Interrupt or Square-Wave Output. This open-drain pin requires an external pullup resistor
connected to a supply at 5.5V or less. This multifunction pin is determined by the state of the INTCN bit in
the Control Register (0Eh). When INTCN is set to logic 0, this pin outputs a square wave and its frequency
is determined by RS2 and RS1 bits. When INTCN is set to logic 1, then a match between the timekeeping
registers and either of the alarm registers activates the INT/SQW pin (if the alarm is enabled). Because the
INTCN bit is set to logic 1 when power is first applied, the pin defaults to an interrupt output with alarms
disabled. The pullup voltage can be up to 5.5V, regardless of the voltage on VCC. If not used, this pin can
be left unconnected.
-
- Posts: 6
- Joined: Tue Jun 26, 2012 11:53 am
Re: chronodot alarm
You can set the alarm to trigger other than 1 Hz.
For example I enable alarm 1, set the three mask bits for alarm 1 to 1110. According to the specs, the sqw pin should change state every min. This is because the chronodot compares the alarm "seconds" register to the time keeping "seconds" register, when they match, the sqw pin will switch state. This can only happen once every minute. I do not see that.
For example I enable alarm 1, set the three mask bits for alarm 1 to 1110. According to the specs, the sqw pin should change state every min. This is because the chronodot compares the alarm "seconds" register to the time keeping "seconds" register, when they match, the sqw pin will switch state. This can only happen once every minute. I do not see that.
- macegr
- Posts: 293
- Joined: Fri Apr 04, 2008 4:46 pm
Re: chronodot alarm
Can you post the actual code that you're using?
- macegr
- Posts: 293
- Joined: Fri Apr 04, 2008 4:46 pm
Re: chronodot alarm
One more question...are you clearing the alarm flags when you detect an alarm interrupt? The flag and therefore the INTCN output will stay active until the flag is cleared. The output will not continuously toggle, because what if your microcontroller didn't get a chance to see that the alarm had occurred? It has to be cleared by the microcontroller because then the DS3231 knows the alarm event was captured.
-
- Posts: 6
- Joined: Tue Jun 26, 2012 11:53 am
Re: chronodot alarm
The INT/SQW is updated once per second. p. 12 of the data sheet:
When the RTC register values match alarm register settings,
the corresponding Alarm Flag ‘A1F’ or ‘A2F’ bit is
set to logic 1. If the corresponding Alarm Interrupt
Enable ‘A1IE’ or ‘A2IE’ is also set to logic 1 and the
INTCN bit is set to logic 1, the alarm condition will activate
the INT/SQW signal. The match is tested on the
once-per-second update of the time and date registers.
I do not believe in this case it needs to be clear.
My sketch is:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
// clear /EOSC bit
// Sometimes necessary to ensure that the clock
// keeps running on just battery power. Once set,
// it shouldn't need to be reset but it's a good
// idea to make sure.
// set initial time and date
Wire.beginTransmission(0x68); // address DS3231
Wire.write(0x01); // select register, change the minute register
Wire.write(0b01010101); // set to 55 min
Wire.write(0b00010001); // set to 11 hour
Wire.endTransmission();
Wire.beginTransmission(0x68); // address DS3231
Wire.write(0x07); // select alarm registers,
Wire.write(0b00000000); //Set mask bits to 1110, seconds register is set to zero
Wire.write(0b10000000);
Wire.write(0b10000000);
Wire.write(0b10000000);
Wire.endTransmission();
Wire.beginTransmission(0x68); // address DS3231
Wire.write(0x0E); // select the control register
Wire.write(0b00000111); // set bit 7 (EOSC) = 0, start counter.
// INTCN, A2IE, and A1IE all set to 1 (enable)
Wire.endTransmission();
}
void loop()
{
// write request to read data starting at register 0
Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
Wire.write(0); // start at register 0
Wire.endTransmission();
Wire.requestFrom(0x68, 3); // request three bytes (seconds, minutes, hours)
while(Wire.available())
{
int seconds = Wire.read(); // get seconds
int minutes = Wire.read(); // get minutes
int hours = Wire.read(); // get hours
seconds = (((seconds & 0b11110000)>>4)*10 + (seconds & 0b00001111)); // convert BCD to decimal
minutes = (((minutes & 0b11110000)>>4)*10 + (minutes & 0b00001111)); // convert BCD to decimal
hours = (((hours & 0b00110000)>>4)*10 + (hours & 0b00001111)); // convert BCD to decimal (assume 24 hour mode)
Serial.print(hours); Serial.print(":"); Serial.print(minutes); Serial.print(":"); Serial.println(seconds);
}
delay(1000);
}
When the RTC register values match alarm register settings,
the corresponding Alarm Flag ‘A1F’ or ‘A2F’ bit is
set to logic 1. If the corresponding Alarm Interrupt
Enable ‘A1IE’ or ‘A2IE’ is also set to logic 1 and the
INTCN bit is set to logic 1, the alarm condition will activate
the INT/SQW signal. The match is tested on the
once-per-second update of the time and date registers.
I do not believe in this case it needs to be clear.
My sketch is:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
// clear /EOSC bit
// Sometimes necessary to ensure that the clock
// keeps running on just battery power. Once set,
// it shouldn't need to be reset but it's a good
// idea to make sure.
// set initial time and date
Wire.beginTransmission(0x68); // address DS3231
Wire.write(0x01); // select register, change the minute register
Wire.write(0b01010101); // set to 55 min
Wire.write(0b00010001); // set to 11 hour
Wire.endTransmission();
Wire.beginTransmission(0x68); // address DS3231
Wire.write(0x07); // select alarm registers,
Wire.write(0b00000000); //Set mask bits to 1110, seconds register is set to zero
Wire.write(0b10000000);
Wire.write(0b10000000);
Wire.write(0b10000000);
Wire.endTransmission();
Wire.beginTransmission(0x68); // address DS3231
Wire.write(0x0E); // select the control register
Wire.write(0b00000111); // set bit 7 (EOSC) = 0, start counter.
// INTCN, A2IE, and A1IE all set to 1 (enable)
Wire.endTransmission();
}
void loop()
{
// write request to read data starting at register 0
Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
Wire.write(0); // start at register 0
Wire.endTransmission();
Wire.requestFrom(0x68, 3); // request three bytes (seconds, minutes, hours)
while(Wire.available())
{
int seconds = Wire.read(); // get seconds
int minutes = Wire.read(); // get minutes
int hours = Wire.read(); // get hours
seconds = (((seconds & 0b11110000)>>4)*10 + (seconds & 0b00001111)); // convert BCD to decimal
minutes = (((minutes & 0b11110000)>>4)*10 + (minutes & 0b00001111)); // convert BCD to decimal
hours = (((hours & 0b00110000)>>4)*10 + (hours & 0b00001111)); // convert BCD to decimal (assume 24 hour mode)
Serial.print(hours); Serial.print(":"); Serial.print(minutes); Serial.print(":"); Serial.println(seconds);
}
delay(1000);
}
- macegr
- Posts: 293
- Joined: Fri Apr 04, 2008 4:46 pm
Re: chronodot alarm
Sorry, I know how you want it to work, but the datasheet never mentions DE-activating the INTCN pin. You need to clear the alarm flag because it works like all other status flags: it stays active until you clear it so that you don't risk missing it. Here's someone else who ran into the same misunderstanding: http://schazamp.BANNED.com/2010/11/1 ... stigation/
Please be positive and constructive with your questions and comments.