I have a DS3231 Real Time Clock module and I'd like to use the Square Wave output.
I wonder how can I set the frequency of the pulse?
How long is the (time) length of the pulse?
UPDATED QUESTION
In order to use the DS3231 as an 1PPS interrupt, I want to use the Square Wave output. Here's how I connected it to an Arduino.
I connected to the SQW output a 10kΩ pull-up resistor and an LED. After that I tested the code which shows the time and worked fine.
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup () {
Serial.begin(9600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin();
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
// etc
}
(The DS3231 works fine with the DS1307 library)
In this case the LED was just flickering, so I thought that the default frequency of the SQW should be grater than 1Hz. I googled a bit and realized that I had to change some registers. So I found this piece of code which I called from the setup() function, but with no success, the LED is still flickering.
void set1Hz() {
// Frequency is stored in register 0x0e in bit 3 and 4
Wire.beginTransmission(0x68);
Wire.write(0x0e);
Wire.endTransmission();
Wire.requestFrom(0x68, 1);
uint8_t register0E = Wire.read();
// clear bits 3 and 4 for 1Hz
register0E &= ~(1 << 3);
register0E &= ~(1 << 4);
// put the value of the register back
Wire.beginTransmission(0x68);
Wire.write(0x0e);
Wire.write(register0E);
Wire.endTransmission();
}
Since I'm now qualified for low level programming, any suggestions on how to change the registers would be appreciated.