Square wave on ds1307 RTC - Page 1
Forum section: electronics / general

author: catfish08
author_rank: Newbie
timestamp: September 26, 2013, 10:27:32 am
content: Hii All,This is first time i use Arduino Uno. Could anyone advise me how to enable the RTC 1Hz square wave?and how to connected led of the sqw out pin on ds1307,Code:void initChrono(){set_time();set_date();}//=======================================================void get_time(){Wire.beginTransmission(104);Wire.write(0);Wire.endTransmission();Wire.requestFrom(104,3);seconds = bcdToDec(Wire.read() & 0x7f);minutes = bcdToDec(Wire.read());hours = bcdToDec(Wire.read() & 0x3f);}//=======================================================void get_date(){Wire.beginTransmission(104);Wire.write(3);Wire.endTransmission();Wire.requestFrom(104,4);dayOfWeek = bcdToDec(Wire.read());dayOfMonth = bcdToDec(Wire.read());month = bcdToDec(Wire.read());year = bcdToDec(Wire.read());}//=======================================================void set_time(){Wire.beginTransmission(104);Wire.write(0);Wire.write(decToBcd(seconds));Wire.write(decToBcd(minutes));Wire.write(decToBcd(hours));Wire.endTransmission();}//=======================================================void set_date(){Wire.beginTransmission(104);Wire.write(3);Wire.write(decToBcd(dayOfWeek));Wire.write(decToBcd(dayOfMonth));Wire.write(decToBcd(month));Wire.write(decToBcd(year));Wire.endTransmission();}

author: Rerouter
author_rank: Super Contributor
timestamp: September 26, 2013, 10:42:45 am
content: page 9 of the datasheet,http://datasheets.maximintegrated.com/en/ds/DS1307.pdfwrite 0x10 into register 0x07

author: johnboxall
author_rank: Unknown
timestamp: September 30, 2013, 04:42:36 am
content: Schematic:You can put a 560R resistor and LED off the SQW pin to GND. Crystal is 32.768 kHz.Sketch:Code:/*DS1307 Square-wave machineUsed to demonstrate the four different square-wave outputs from Maxim DS1307See page nine of data sheet for more informationJohn Boxall - tronixstuff.com*/#include "Wire.h"#define DS1307_I2C_ADDRESS 0x68 // each I2C object has a unique bus address, the DS1307 is 0x68void setup(){Wire.begin();}void sqw1() // set to 1Hz{Wire.beginTransmission(DS1307_I2C_ADDRESS);Wire.write(0x07); // move pointer to SQW addressWire.write(0x10); // sends 0x10 (hex) 00010000 (binary)Wire.endTransmission();}void sqw2() // set to 4.096 kHz{Wire.beginTransmission(DS1307_I2C_ADDRESS);Wire.write(0x07); // move pointer to SQW addressWire.write(0x11); // sends 0x11 (hex) 00010001 (binary)Wire.endTransmission();}void sqw3() // set to 8.192 kHz{Wire.beginTransmission(DS1307_I2C_ADDRESS);Wire.write(0x07); // move pointer to SQW addressWire.write(0x12); // sends 0x12 (hex) 00010010 (binary)Wire.endTransmission();}void sqw4() // set to 32.768 kHz (the crystal frequency){Wire.beginTransmission(DS1307_I2C_ADDRESS);Wire.write(0x07); // move pointer to SQW addressWire.write(0x13); // sends 0x13 (hex) 00010011 (binary)Wire.endTransmission();}void sqwOff()// turns the SQW off{Wire.beginTransmission(DS1307_I2C_ADDRESS);Wire.write(0x07); // move pointer to SQW addressWire.write(0x00); // turns the SQW pin offWire.endTransmission();}void loop(){sqw1();delay(5000);sqw2();delay(5000);sqw3();delay(5000);sqw4();delay(5000);sqwOff();delay(5000);}More Arduino and RTC athttp://tronixstuff.com/tag/ds1307/