8000 Ds1302 by Makuna · Pull Request #78 · Makuna/Rtc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ds1302 #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions examples/DS1302_Memory/DS1302_Memory.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

// CONNECTIONS:
// DS1302 CLK/SCLK --> 5
// DS1302 DAT/IO --> 4
// DS1302 RST/CE --> 2
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#include <ThreeWire.h>
#include <RtcDS1302.h>

ThreeWire myWire(4,5,2); // IO, SCLK, CE
RtcDS1302<ThreeWire> Rtc(myWire);

#define countof(a) (sizeof(a) / sizeof(a[0]))

const char data[] = "what time is it";

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

Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);

Rtc.Begin();

RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();

if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");
Rtc.SetIsWriteProtected(false);
}

if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}

RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}


/* comment out on a second run to see that the info is stored long term */
// Store something in memory on the RTC
uint8_t count = sizeof(data);
uint8_t written = Rtc.SetMemory((const uint8_t*)data, count); // this includes a null terminator for the string
if (written != count)
{
Serial.print("something didn't match, count = ");
Serial.print(count, DEC);
Serial.print(", written = ");
Serial.print(written, DEC);
Serial.println();
}
/* end of comment out section */
}

void loop ()
{
RtcDateTime now = Rtc.GetDateTime();

printDateTime(now);
Serial.println(" +");

delay(5000);

// read data
uint8_t buff[20];
const uint8_t count = sizeof(buff);
// get our data
uint8_t gotten = Rtc.GetMemory(buff, count);

if (gotten != count)
{
Serial.print("something didn't match, count = ");
Serial.print(count, DEC);
Serial.print(", gotten = ");
Serial.print(gotten, DEC);
Serial.println();
}

Serial.print("data read (");
Serial.print(gotten);
Serial.print(") = \"");
// print the string, but terminate if we get a null
for (uint8_t ch = 0; ch < gotten && buff[ch]; ch++)
{
Serial.print((char)buff[ch]);
}
Serial.println("\"");

delay(5000);
}



void printDateTime(const RtcDateTime& dt)
{
char datestring[20];

snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}

84 changes: 84 additions & 0 deletions examples/DS1302_Simple/DS1302_Simple.ino
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

// CONNECTIONS:
// DS1302 CLK/SCLK --> 5
// DS1302 DAT/IO --> 4
// DS1302 RST/CE --> 2
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND

#include <ThreeWire.h>
#include <RtcDS1302.h>

ThreeWire myWire(4,5,2); // IO, SCLK, CE
RtcDS1302<ThreeWire> Rtc(myWire);

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

Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);

Rtc.Begin();

RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();

if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");
Rtc.SetIsWriteProtected(false);
}

if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}

RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
}

void loop ()
{
RtcDateTime now = Rtc.GetDateTime();

printDateTime(now);
Serial.println();

delay(10000); // ten seconds
}

#define countof(a) (sizeof(a) / sizeof(a[0]))

void printDateTime(const RtcDateTime& dt)
{
char datestring[20];

snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}

15 changes: 15 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Datatypes (KEYWORD1)
#######################################

ThreeWire KEYWORD1
RtcDS1302 KEYWORD1
RtcDS1307 KEYWORD1
DS3234AlarmOne KEYWORD1
DS3234AlarmTwo KEYWORD1
Expand All @@ -26,6 +28,8 @@ Begin KEYWORD2
IsDateTimeValid KEYWORD2
GetIsRunning KEYWORD2
SetIsRunning KEYWORD2
GetIsWriteProtected KEYWORD2
SetIsWriteProtected KEYWORD2
SetDateTime KEYWORD2
GetDateTime KEYWORD2
GetTemperature KEYWORD2
Expand All @@ -44,6 +48,8 @@ GetAgingOffset KEYWORD2
SetAgingOffset KEYWORD2
GetMemory KEYWORD2
SetMemory KEYWORD2
GetTrickleChargeSettings KEYWORD2
SetTrickleChargeSettings KEYWORD2
AsFloatDegC KEYWORD2
AsFloatDegF KEYWORD2
AsCentiDegC KEYWORD2
Expand Down Expand Up @@ -87,6 +93,15 @@ DS3231AlarmTwoControl_HoursMinutesDayOfWeekMatch LITERAL1
DS3231AlarmFlag_Alarm1 LITERAL1
DS3231AlarmFlag_Alarm2 LITERAL1
DS3231AlarmFlag_AlarmBoth LITERAL1
DS1302RamSize LITERAL1
DS1302Tcr_Disabled LITERAL1
DS1302TcrResistor_2KOhm LITERAL1
DS1302TcrResistor_4KOhm LITERAL1
DS1302TcrResistor_8KOhm LITERAL1
DS1302TcrDiodes_One LITERAL1
DS1302TcrDiodes_Two LITERAL1
DS1302TcrStatus_Enabled LITERAL1
DS1302TcrStatus_Disabled LITERAL1
DS1307SquareWaveOut_1Hz LITERAL1
DS1307SquareWaveOut_4kHz LITERAL1
DS1307SquareWaveOut_8kHz LITERAL1
Expand Down
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "RTC",
"keywords": "RTC, DS1307, DS3231, DS3234, AT24C32, clock",
"description": "A library that makes interfacing DS1307, DS3231, and DS3234 Real Time Clock modules easy.",
"keywords": "RTC, DS1302, DS1307, DS3231, DS3234, AT24C32, clock",
"description": "A library that makes interfacing DS1302, DS1307, DS3231, and DS3234 Real Time Clock modules easy.",
"repository": {
"type": "git",
2E87 "url": "https://github.com/Makuna/Rtc.git"
},
"version": "2.2.0",
"version": "2.3.0",
"frameworks": "arduino",
"platforms": "*"
}
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name=Rtc by Makuna
version=2.2.0
version=2.3.0
author=Michael C. Miller (makuna@live.com)
maintainer=Michael C. Miller (makuna@live.com)
sentence=A library that makes interfacing DS1307, DS3231, and DS3234 Real Time Clock modules easy.
sentence=A library that makes interfacing DS1302, DS1307, DS3231, and DS3234 Real Time Clock modules easy.
paragraph=Includes deep support of module features, including temperature, alarms and memory storage if present. Tested on esp8266.
category=Device Control
url=https://github.com/Makuna/Rtc/wiki
Expand Down
Loading
0