DS1307new

Actual hints

This library is no longer maintained by me. Oliver Kraus is now maintaining this library. You’ll find it here:

http://code.google.com/p/ds1307new/
The code has been moved to https://github.com/olikraus?tab=repositories.

The code is not working with Arduino IDE 1.0

Description

I have rewritten the DS1307 library to use the 56 byte NV-RAM of the clock from scratch. This project is contributed by Oliver Kraus the developer of the dogm128 library.

The problem was, that the libraries in the wild, DS1307 and DS1307RTC, were not able to use the NV-RAM, but one of my projects, a weather station with BMP085 air-pressure and temperature sensor, must use the NV-RAM to store the last address +1 of written weather data into the EEPROM on the board. I had choosen this way to avoid defects with the EEPROM within the ATMEGA328 which has a limited lifetime.

My version of the library for the DS1307 RTC is called DS1307new to avoid confusion with the existing libraries.

Download

The project is hosted at Google Code. Take a look here.

The code has been moved to https://github.com/olikraus?tab=repositories.

Keywords

RTC.startClock();
RTC.stopClock();
RTC.setTime();
RTC.getTime();
RTC.getCTRL();
RTC.setCTRL();
RTC.getRAM(rtc_addr, * rtc_ram, rtc_quantity);
RTC.setRAM(rtc_addr, * rtc_ram, rtc_quantity);
RTC.second;
RTC.minute;
RTC.hour;
RTC.dow;
RTC.day;               //since v1.1 this parameter has been changed from RTC.date
RTC.month;
RTC.year;
RTC.ctrl;
RTC.ydn;               // new since v1.1
RTC.cdn;               // new since v1.1
RTC.time2000;          // new since v1.1
RTC.fillByCDN;         // new since v1.1
RTC.fillByTime2000;    // new since v1.1
RTC.fillByHMS;         // new since v1.1
RTC.fillByYMD;         // new since v1.1
RTC.isMEZSummerTime;   // new since v1.2

License

The code is published under the cc-by-sa-3.0 license!!

6 comments

  • Gary (6 Jahren)

    Hi, I am attempting to use this library on a data logging shield by Adafruit. http://www.adafruit.com/products/243
    Can you share the hardware connections required for your test program ?

    • der-schmelle (6 Jahren)

      Hi Gary,
      I’m unsure what you mean, but the I2C Bus connectors are fixed to A4 (SDA) & A5 (SCL) at the Arduino board. Additionally you can use the D2 pin as input for the SQW output of the DS1307. Please take a look into the Eagle schematic of my BaroTemp board.

      HTH BR Peter

  • Per (7 Jahren)

    Thanks for creating this library!

  • soul (7 Jahren)

    can you post a example call for the method RTC.setTime()
    I have the problem that I will set the RTC over the serial terminal.
    thx forward

    • der-schmelle (7 Jahren)

      Hi Soul,
      I havn’t got a demo setting the time via the serial port at the moment.
      Pls. try this:


      Wire.begin(); // I2C control

      /*
      Uncomment the next 2 lines if you want to SET the clock
      Comment them out if the clock is set.
      DON'T ASK ME WHY: YOU MUST UPLOAD THE CODE TWICE TO LET HIM WORK
      AFTER SETTING THE CLOCK ONCE.
      */
      // TimeIsSet = 0xffff;
      // RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));

      RTC.getRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));// Clock control
      if (TimeIsSet != 0xaa55)
      {
      RTC.stopClock();
      RTC.second = 0; // DON'T USE '00' IF YOU MEAN '0' SECONDS!!!
      RTC.minute = 44;
      RTC.hour = 9;
      RTC.dow = 3; // SUN=7,MON=1...
      RTC.date = 10;
      RTC.month = 11;
      RTC.year = 2010;
      RTC.setTime();
      RTC.startClock();
      TimeIsSet = 0xaa55;
      RTC.setRAM(54, (uint8_t *)&TimeIsSet, sizeof(uint16_t));
      }

      BR Peter

    • der-schmelle (7 Jahren)

      The lib has been revised and a Testprogram has been added. Take a look here: http://code.google.com/p/ds1307new/source/browse

      HTH
      Peter

Go to Top