ds3231 SQW enable 1hz practicing

Hello, i am learning how to use I2C, speccially with ds3231 for starting, there are a lot of libraries to make ds3231 work but i want to learn from scratch, i´ve been readiing some pdf files and for my first attempt i tried to enable SQW function at 1hz here is the code

#include <Wire.h>
int ds3231_address = 0x68; //ds3231 address
void setup()


void loop()
Wire.write(0x0E); //Control Register for SQW (0Eh)
Wire.write(0xc0); // 11000000 SQUARE-WAVE OUTPUT FREQUENCY but it hsould be 0000000 for 1 hz :


My doubt is that for enable 1hz datasheet says it should be 0000000 (00h) instead of 11000000 (c0h) but it works for 1hz also c0hi tested it on pic making a clock using 1hz for seconds++ after 1 day clock fomr my cellphone and ds3231 were .synchronized

Ive been reading some pdf files

Are you reading the actual data sheet? https://datasheets.maximintegrated.com/en/ds/DS3231.pdf

Bit 7: Enable Oscillator (EOSC). When set to logic 0,
the oscillator is started. When set to logic 1, the oscillator
is stopped when the DS3231 switches to VBAT. This bit
is clear (logic 0) when power is first applied. When the
DS3231 is powered by VCC, the oscillator is always on
regardless of the status of the EOSC bit. When EOSC is
disabled, all register data is static.
Bit 6: Battery-Backed Square-Wave Enable (BBSQW).
When set to logic 1 with INTCN = 0 and VCC < VPF, this
bit enables the square wave. When BBSQW is logic 0,
the INT/SQW pin goes high impedance when VCC < VPF.
This bit is disabled (logic 0) when power is first applied.

Setting bit7 will prevent the RTC from advancing the time under battery power. I doubt you want this.
Setting bit6 lets the SQW run under battery power.

The fundamental control of the SQW and the frequency are in bits 4,3 and 2 (RS2,RS1,INTCN) which as you say should be 0’s for a 1 HZ square wave.

With the top two bits set, the SQW and RTC will work as set when the RTC is powered from Vcc.

I recently wrote some code for the DS3231 to use the SQW output to keep a MOSFET switch powered on.

I just used the data sheet to work out what was needed, it was clear, and the code worked first time.

Dangerous teritory to doubt the accuracy of data sheets, if you have problems, 99.9.........% of the time it will be a 'missunderstanding' on the programmers side.

Hello Mr. Srnet, could you please share your code to analize it.

Generation of 1 Hz Square Wave Signal at Pin-3 of the RTC Chip
(1) Connect the RTC Module with Arduino UNO as per following diagram of Fig-1. Let us also connect the R1-LED1 circuit and the pull-up resistors with the TWI/I2C Bus. The SQW-pin of J1 is internally shorted with Pin-3 of the DS3231 Clock Chip.

Figure-1: Connection diagram of DS3231 RTC Module with Arduino UNO’s TWI Bus

Figure-2: Register map of DS3231 RTC Chip

(2) To generate 1 Hz signal at the SQW-pin, we need to carry out the following initialization tasks:
(a) INTCN (Interrupt Control) bit of the Control Register (Fig-2) must be cleared.
(b) RS1 and RS0 bits (Rate Select) of the Control Register (Fig-2) must be loaded with 00.

(3) Let us upload the following sketch into the UNO Kit which will drive the RTC Module. Let us save sketch as ds3231rtc-3.ino.

#define deviceAddress 0b1101000   //0x68
void setup() 
  Wire.begin();   //TWI Bus is formed  
  Wire.beginTransmission(deviceAddress); //device address and STSRT command are queued
  Wire.write(0x0E); //Control Register Address is queued
  Wire.write(0x00); //Data for Control Register is queued
  Wire.endTransmission(); //queued information are transferred under ACK; STOP

void loop() 

(4) Compile and upload the sketch.

(5) Check that LED1 is blinking at 1-sec (1 Hz frequency) interval.

(6) Change the content of the Control Register at 0x84 to put LH at the INTCN bit which will disable the generation of the SQW signal. Save the new program as DS3231-2.ino.

(7) Upload the modified sketch and check that the LED1 is not blinking.

(8) Re-run the program with EOSC/ bit at LH state. Check that the LED1 is blinking. This proves that the oscillator circuit is always ON whenever there is voltage supply at the Vcc pin.


Thanks a lot Mr. GolamMostafa for your help, i really aprecciate this, i wil print your tutorial :slight_smile: .