Created
November 1, 2015 23:15
-
-
Save Hermann-SW/5b487ece9d62cf669caf to your computer and use it in GitHub Desktop.
Measuring >40k interrupts per second by DS3231 32K and 8kHz enabled SQW lines on pins 2+3 of Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// needed for RTC.set(_, _), see bottom as well | |
#include <Wire.h> | |
#include <Time.h> | |
#include <DS1307RTC.h> | |
// from http://www.pjrc.com/teensy/td_libs_DS1307RTC.html | |
long lcnt=0; | |
void fcnt(void) { ++lcnt; } | |
void setup(void) { | |
Serial.begin(57600); | |
/* | |
enable 8kHz SQW square wave (is disabled on DSC3231 powerup) | |
http://datasheets.maximintegrated.com/en/ds/DS3231.pdf#page=13 | |
*/ | |
RTC.set(0x0E, 0x18); | |
// do count interrupts from DS3231 pin 32K | |
attachInterrupt(digitalPinToInterrupt(2), fcnt, FALLING); | |
// and count interrupts from DS3231 pin SQW | |
attachInterrupt(digitalPinToInterrupt(3), fcnt, FALLING); | |
} | |
void loop(void) { | |
// output interrupts per second | |
Serial.println(1000000.0*lcnt/micros()); | |
delay(500); | |
} | |
/* | |
added to DS1307RTC.h: | |
static bool set(uint8_t reg, uint8_t val); | |
and to DS1307RTC.cpp: | |
bool DS1307RTC::set(uint8_t reg, uint8_t val) | |
{ | |
Wire.beginTransmission(DS1307_CTRL_ID); | |
Wire.write(reg); // reset register pointer | |
Wire.write(val) ; | |
if (Wire.endTransmission() != 0) { | |
return false; | |
} | |
return true; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Photo showing wiring:
https://pbs.twimg.com/media/CSw0bFuWEAAza9D.jpg:large
from this tweet:
https://twitter.com/HermannSW/status/660960886597820416