Go Down

Topic: RTC DS1307 + UNO not working, pls help!!! (Read 1 time) previous topic - next topic

whatsap45

Jun 14, 2014, 06:06 pm Last Edit: Jun 14, 2014, 06:08 pm by whatsap45 Reason: 1
To be more detailed, I'm testing my RTC ds1307 i just built recently and tried the sample coding with a little modication. As a result, the serial monitor shows that the DS1307 is running but the time and date did not change and remains the same. Does anyone has any idea on this?

Code: [Select]
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

void setup () {
 Serial.begin(19200);
#ifdef AVR
 Wire.begin();
#else
 Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
 rtc.begin();

 if (! rtc.isrunning()) {
   Serial.println("RTC is NOT running!");
   // following line sets the RTC to the date & time this sketch was compiled
   rtc.adjust(DateTime(2014,6,14,23,33,0));
   // This line sets the RTC with an explicit date & time, for example to set
   // January 21, 2014 at 3am you would call:
   // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
 }
}

void loop () {
   DateTime now = rtc.now();
   
   Serial.print(now.year());
   Serial.print('/');
   Serial.print(now.month());
   Serial.print('/');
   Serial.print(now.day());
   Serial.print(' ');
   Serial.print(now.hour());
   Serial.print(':');
   Serial.print(now.minute());
   Serial.print(':');
   Serial.print(now.second());
   Serial.println();
   
 
   
   Serial.println();
  delay(1000);
}



johnwasser

http://datasheets.maximintegrated.com/en/ds/DS1307.pdf

Maybe your crystal isn't working.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

steinie44

Code: [Select]

void setup()
{
  Serial.begin(9600);

  RTC.begin();
  //To set clock, remove the // on the RTC.adjust line below
  //Upload sketch, then replace // and upload again.
// RTC.adjust(DateTime(__DATE__, __TIME__));
}


Follow instructions above.
You must upload twice.
The 2nd upload with the // replaced prevents the time from reloading the 1st compiled time,
when the Arduino is reset.

luisilva

I had the same problem, and I solved it (I believe). I use a TinyRTC and I saw that when I pass the finger tips over the connection holes in the module, the module momentarily works. After that I add a resistor of approximately 1k between the Vcc and the SDA and SCL pins. I've never notice more problems.

whatsap45

I tried the pull resistors and still doesn't work. Oh, how do you check if the crystal is faulty?

luisilva

#5
Jun 15, 2014, 04:37 am Last Edit: Jun 15, 2014, 05:11 am by luisilva Reason: 1
You are using a module or the chip it self?
Do you have an oscilloscope?
I think that you can verify the signal that is coming out from the SQ pin.

EDIT: To have some signal coming out from the SQ pin you must have to config the  SQ enable bit of the DS1307, so if you are not able to communicate with the device, I believe, that not work for you. But if, like you said in the first post, you are able to communicate with the device, you can write the value 0x90 to the register 0x07, and attach one LED and one resistor to the SQ pin. To write the value to the device I modify the "RTClib.cpp", modifying the begin() method:

Code: [Select]

uint8_t RTC_DS1307::begin(void) {
 i=7;
 Wire.beginTransmission(DS1307_ADDRESS);
 Wire.write(i);
 Wire.write(0x90);
 Wire.endTransmission();
 i=0;
 return 1;
}


When you attach the LED to the pin, like I said, you must see the LED blinking at the frequency of 1Hz (1 time per second).

Go Up