GithubHelp home page GithubHelp logo

paulstoffregen / ds1307rtc Goto Github PK

View Code? Open in Web Editor NEW
133.0 17.0 86.0 11 KB

Use a DS1307 Real Time Clock chip with the Time library

Home Page: http://www.pjrc.com/teensy/td_libs_DS1307RTC.html

C++ 100.00%

ds1307rtc's Introduction

Readme file for DS1307RTC Library

The DS1307RTC library is provided to demonstrate the Arduino Time library.

See the TimeRTC example sketches privided with the Time library download for usage


ds1307rtc's People

Contributors

ivankravets avatar nsayer avatar paulstoffregen avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ds1307rtc's Issues

Error if include DS1307RTC.h on NodeMCU

On my NodeMCU (ESP8266) I get this error on start if add "#include <DS1307RTC.h>"

 ets Jan  8 2013,rst cause:2, boot mode:(3,2)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
vbb28d4a3
~ld

How can I solve it?

DS1307 square wave generation and RTC.read crash ESP32

Description

When using the library for the square wave generation or for a RTC.read (in different sketches) they work fine, however, when combined in a sketch, it crashes the ESP32 and cause unlimited re-boots.

Hardware & Software

Hardware: ESP32-WROOM-32, Elegoo DS1307 module v3, led and pullup resistor of 5k1 on GPIO 5. SQA output of the DS1307 to GPIO 32 as interrupt.
Use of PlatformIO

Arduino Sketch

// sketch is kept in simplest form so as only to confirm the working of the square wave generation and the RTC.read instruction. Sketch will work as written below. Undo comments around RTC if-loop to cause the reboot situation

#include <Arduino.h>
#include <DS1307RTC.h>
#include <Wire.h>
#define DS1307_CTRL_ID 0x68 // DS1307 I2C device address 0x68
#define ledPin 5 // LED via pullup on GPIO 5
#define interruptPin 32 // output of SQA on DS1307 conneceted to GPIO 32

tmElements_t tm;

void setSQW(byte location, byte value) {
Wire.beginTransmission(DS1307_CTRL_ID);
Wire.write(location);
Wire.write(value);
Wire.endTransmission();
}

void IRAM_ATTR handleInt() {
digitalWrite(ledPin, !digitalRead(ledPin));
}

void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Set SQW 1 Hz");

pinMode(ledPin,OUTPUT);
pinMode(interruptPin, INPUT);

// GPIO 32
attachInterrupt(digitalPinToInterrupt(interruptPin),handleInt,FALLING);

// set SQ to 1 Hz
setSQW(0X07, B00010000);

}

void loop() {
/*
if (RTC.read(tm)) {
Serial.print("Time available");
};
*/
delay(1000);
}

Crash/reboot information

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400d0ef9 PS : 0x00060930 A0 : 0x800d10be A1 : 0x3ffe3b50
A2 : 0x3ffbffe8 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x800d0eee A9 : 0x3ffe3b20
A10 : 0x3ffbffe8 A11 : 0x3ffbdc54 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x3ffbdc54 SAR : 0x00000020 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000020 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff

ELF file SHA256: 0000000000000000

Backtrace: 0x400d0ef9:0x3ffe3b50 0x400d10bb:0x3ffe3b70 0x400d10c6:0x3ffe3b90 0x400e29eb:0x3ffe3bb0 0x400827e5:0x3ffe3bd0 0x400829e5:0x3ffe3c20 0x40079247:0x3ffe3c40 0x400792ad:0x3ffe3c70 0x400792b8:0x3ffe3ca0 0x40079465:0x3ffe3cc0 0x400806da:0x3ffe3df0 0x40007c31:0x3ffe3eb0 0x4000073d:0x3ffe3f20

Port to non-blocking I2C library.

@PaulStoffregen I noticed your library still uses the Arduino Wire library, which is blocking and completely freezes the board when there is a problem with the two wire bus. I found Wayne Truchsess' I2C Library which is non-blocking and I have been using for a while with success. The non-blocking principle is based on a configurable time-out, that when reached without response from the I2C device the function returns with an error code. I tried to port the DS1307RTC library to use Wayne's I2C library and I pushed the ported version a branch in my fork.

My idea was to start discussing if a pull-request/merge could be possible.

Best Regards.
Martin.

ESP8266 keeps rebooting due to multiple calls of Wire.begin()

The ESP8266 keeps rebooting when setSyncProvider(RTC.get); is called. This behavior is caused by multiple calls of Wire.begin() in setup().

I am using the DS1307 and a BMP280 temperature sensor connected via I2C.
The BMP280 gets initiated first and calls Wire.begin(). Afterwards the RTC.get() calls Wire.begin() again (automatically). This causes the reboot.
As soon as I remove Wire.begin() in the DS1307RTC() constructor, everything works fine.

So I am wondering if it is good to automatically call Wire.begin() without the knowledge if the bus might has been initialized already. Maybe we could pass a parameter to tell the constructor if Wire.begin() is necessary...? But in this case I think the automatic instance creation by
DS1307RTC RTC = DS1307RTC(); // create an instance for the user
must be deleted.

There is no calibration register in the DS1307

Having recently started implementing something using this chip, I've been taking a look at the libraries that are available. This looks the simplest but I'm puzzled by the set/getCalibration() methods as there is no calibration register.

Can't use for board mkr1000

Serial monitor print

 DS1307RTC Read Test
 -------------------

Then stop.
I tried the example on mega2560 it worked fine.

tmElements_t has not been declared

In DS1307RTC.h I included #include <Time.h> before #include <TimeLib.h> and work propely with Arduino/Genuino boards and with ESP82666 based boards.

DS1307RTC::set(time_t t) t = 0 results in year 2066

Attempt to set time to 0 gives year 2066.

Analysis (copied from http://forum.arduino.cc/index.php?topic=388120.0, reply 7)
This is what seems to happen
1)
rtc.set takes the time (in seconds) and breaks it up (breakTime()) into the usual tm elements; this works fine and year is set to 0
2)
it writes the time using rtc.write(); write use the macro tmYearToY2k which subtracts 30 from the year. This results in a negative number that is treated as an unsigned. So year becomes 226. This is next converted to bcd using dec2bcd() resulting in 358 (0x166); the value is truncated to 0x66 because the variable is a byte. This truncated value is written to the RTC chip.
3)
rtc.get reads the time from the RTC chip using read(); read gets the year and uses the macro y2kYearToTm to add 30 to the year (compensating for the 30 that was subtracted) so the year is now 96.
4)
rtc.get now returns a value based on the year 96; therefore printing the variable t in your code does not give 0.
5)
The year function uses the macro tmYearToCalendar that adds 1970 to the year. The result is 2066.

Note 1: I did a theoretical analysis based on the reported 'issue' in the above thread
Note 2: Title not quite right; it will fail for any time representing a year below 30.

Not compatible with NodeMCU 0.9?

Hi,

cannot compile it on NodeMCU 0.9 (ESP-12 Module) device.

If I add "#include <DS1307RTC.h>" I get this error: "Error compiling for NodeMCU 0.9 card (ESP-12 Module)."

On my code also use TimeLib.

using DS1307 as EEPROM

while we have a at24C32 IC on DS1307 module, can we save some data on it as EEPROM?
I read that it has 56-Byte, Battery-Backed, Non-volatile (NV)RAM for data storage.

P.S: I hope I wrote the IC number correctly because the IC on my module didn't have a clear IC number to read

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.