RTC DS1307 - "RTC not running"

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
miker
 
Posts: 38
Joined: Fri Mar 02, 2012 6:16 am

RTC DS1307 - "RTC not running"

Post by miker »

I'm stumped... I assembled and have tested the Adafruit DS1307 Breakout Kit. When run
on a breadboard using the code provided in the Adafruit tutorials, it works fine.
When I copy the code and imbed it in a larger project, I get the message
"RTC not running" when the compile completes... ??? What would make the
RTC.isrunning method fail??

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: RTC DS1307 - "RTC not running"

Post by adafruit_support_bill »

Did you remember the blob of solder under the battery clip? Make sure you have good battery contact. Loss of backup power can cause the RTC to stop.

User avatar
miker
 
Posts: 38
Joined: Fri Mar 02, 2012 6:16 am

Re: RTC DS1307 - "RTC not running"

Post by miker »

Yes.. probably a bit too large but the battery has a tight fit. I'm running the Serial interface at 9600 baud
but this should not be an issue .. ??

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: RTC DS1307 - "RTC not running"

Post by adafruit_support_bill »

Serial communication at 9600 should not be an issue. What other differences are there between the example code & your current configuration?

User avatar
miker
 
Posts: 38
Joined: Fri Mar 02, 2012 6:16 am

Re: RTC DS1307 - "RTC not running"

Post by miker »

Here's the test code:

Code: Select all

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

RTC_DS1307 RTC;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    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(__DATE__, __TIME__));
  }
}
void loop () {
    DateTime now = RTC.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
 ...
}
Here's the code I'm embedding the test code in:

Code: Select all

  #include <Wire.h>
  #include <RTClib.h>
  #include "font_5x4.h"
  #include "font_5x7.h"
  #include <HT1632.h>
  #include <Time.h>
  #include <stdio.h>

  #define dly 1000
  RTC_DS1307 RTC;
  
  void setup()
  {
    Serial.begin(9600);
    HT1632.begin(9, 8, 10, 11);
    Wire.begin();
    RTC.begin();
    delay(dly);

    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(__DATE__, __TIME__));
    }
  }
  
  void loop()
  {
    HT1632.drawTarget(BUFFER_BOARD(1));
    HT1632.setBrightness(10);
    HT1632.clear();
    HT1632.render();
    HT1632.drawTarget(BUFFER_BOARD(2));
    HT1632.setBrightness(10);
    HT1632.clear();
    HT1632.render();
    DateTime now = RTC.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    //displayit( message, board#, x offset, y offset)
    displayit( "TUNE ", 1, 1, 1);
    delay(dly);
    displayit( "FM 10", 1, 1, 1);
    delay(dly);
    displayit( "7.5  ", 2, 0, 1);
    delay(dly);

    clearTgt(1);
    clearTgt(2);
    displayit( "NEXT ", 1, 1, 1);
    displayit( "SHOW ", 2, 1, 1);
    delay(dly);
    countDown(9);  // countDown( mins );
    
//    i_hour = hour(now());
//    i_min = minute(now());
//    i_sec = second(now());
//    printDigits(i_hour);
//    Serial.print(":");
//    printDigits(i_min);
//    Serial.print(":");
//    printDigits(i_sec);
//    Serial.println();
    
    //blank displays
    clearTgt(1);
    clearTgt(2);
    delay(dly);
  }
  
  void clearTgt(int bd)
  {
    HT1632.drawTarget(BUFFER_BOARD(bd));
    HT1632.clear();
    HT1632.render();
  }
  
  void displayit( char msg[], int board, int x_offset, int y_offset)
  {
    HT1632.drawTarget(BUFFER_BOARD(board));
    HT1632.clear();
    HT1632.render();
    for(int z = 0, x = x_offset; z < 6; z++, x+=6)
    {
      HT1632.drawText((const char *)&msg[z], x, y_offset, FONT_5X7, FONT_5X7_WIDTH, FONT_5X7_HEIGHT, FONT_5X7_STEP_GLYPH);
    }
    HT1632.render();
  }
  
  void printDigits(int digits)
  {
    // utility function for digital clock display: prints preceding colon and leading 0
    if(digits < 10)
      Serial.print('0');
    Serial.print(digits);
  }

  void countDown(int mins)
  {
    char text[6];
    char temp[2];
    char msg[] = ":00 ";
    sprintf(temp, "%d", mins);
    text[0] = temp[0];
    text[1] = msg[0];
    text[2] = msg[1];
    text[3] = msg[2];
    text[4] = msg[3];
    text[5] = msg[4];
    clearTgt(1);
    clearTgt(2);
    displayit(text, 1, 1, 1);
    //Serial.println(text);
    delay(1000);
    for(int w = mins-1; w >= 0; w--)
    { 
      Serial.print("w:");
      Serial.println(w);
      char msg[] = ":59";
      sprintf(temp, "%d", w);
      text[0] = temp[0];
      text[1] = msg[0];
      text[2] = msg[1];
      text[3] = msg[2];
      text[4] = msg[3];
      Serial.println(text);
      displayit( text, 1, 1, 1 );
      for(int y = 5; y >= 0; y--)
      {
        for(int z = 9; z >= 0; z--)
        {
          //Serial.println(z); 
          sprintf(temp, "%d", w);
          text[0] = temp[0];
          text[1] = ':';
          sprintf(temp, "%d", y);
          text[2] = temp[0];
          sprintf(temp, "%d", z);
          text[3] = temp[0];
          text[4] = '\0';
          displayit(text, 1, 1, 1);
          Serial.println(text);
          delay(1000);
        }
      } 
    }
    for(int z = 10; z > 2; z--)
    {
      HT1632.setBrightness(z);
      delay(150);
    }
  }

User avatar
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 6:59 pm

Re: RTC DS1307 - "RTC not running"

Post by philba »

Just a guess here but I think isrunning just returns the high bit of the seconds register which is the clock halt bit and is 1 by default (clock halted). When you program that register (i.e. set the time) it gets cleared and the ds1307 runs. Try setting the time before you do anything else.

User avatar
miker
 
Posts: 38
Joined: Fri Mar 02, 2012 6:16 am

Re: RTC DS1307 - "RTC not running"

Post by miker »

OK, I've found the issue.... I was testing the RTC Breakout board using an
OSEPP UNO board. Worked fine. My realtime board is an Arduino UNO.
When I moved the RTC Breakout board to the Arduino, I reversed the SDA
and SCL lines.... that would make a difference!! When I connected them
correctly, the code works fine... DUH.

Thanks for your quick responses....

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”