Skip to content
Michael Miller edited this page Feb 25, 2019 · 3 revisions

RtcDS1307 object provides access to all the functions of the DS1307 module. Along with date and time, this also includes retrieving and setting data into the non-volatile memory and defining what the trigger square wave pin does.

Constructors

template<class T_WIRE_METHOD> RtcDS1307(T_WIRE_METHOD& wire)

Construct a Rtc object using the provided WIRE method.
T_WIRE_METHOD - the typename of the class to use for the wire method. TwoWire is the normal hardware method class.
wire - the instance of the T_WIRE_METHOD to use. Wire is the normal hardware instance to use.
Below is an example of how to create an instance of the object using the normal Arduino hardware Wire support.

#include <Wire.h> 
#include <RtcDS1307.h>

RtcDS1307<TwoWire> Rtc(Wire);

If you want to use SoftwareWire library, you can replace the above with this and it will work.

#include <SoftwareWire.h> 
#include <RtcDS1307.h>

SoftwareWire myWire(SDA, SCL); // replace with the pins you use
RtcDS1307<SoftwareWire> Rtc(myWire);

Methods

void Begin()

The normal begin method that should be called within Setup()

uint8_t LastError()

<return>, the error code from the last Wire transaction. After each method call below, you may check if this return value for an error. See https://www.arduino.cc/en/Reference/WireEndTransmission for values of this error.

bool IsDateTimeValid()

<return>, the RTC has confidence in the date and time it returns. If this returns false it usually means the battery is dead or the date and time has never been set.

bool GetIsRunning()

<return>, the actual clock is running on the RTC.

void SetIsRunning(bool isRunning)

isRunning - set if the clock is running. If false then the time value will not progress.

void SetDateTime(const RtcDateTime& dt)

dt - the date and time to set the RTC to.

RtcDateTime GetDateTime()

<return>, the current date and time in the RTC.

void SetMemory(uint8_t memoryAddress, uint8_t value)

memoryAddress - (0-54) the address within the memory of the RTC to store a value.
value - the 8 bit value to store.

uint8_t GetMemory(uint8_t memoryAddress)

memoryAddress - (0-54) the address within the memory of the RTC to retrieve a value.
<return>, the value of that memory address

uint8_t SetMemory(uint8_t memoryAddress, const uint8_t* pValue, uint8_t countBytes)

memoryAddress - (0-54) the starting address within the memory of the RTC to copy the following buffer
pValue - the pointer to a buffer of bytes
countBytes - the number of bytes to copy
<return>, the number of bytes actually copied. This maybe smaller than countBytes due to reaching the end of the available memory address.

uint8_t GetMemory(uint8_t memoryAddress, uint8_t* pValue, uint8_t countBytes)

memoryAddress - (0-54) the starting address within the memory of the RTC to copy from
pValue - the pointer to a buffer of bytes to copy into
countBytes - the number of bytes to copy
<return>, the number of bytes actually copied. This maybe smaller than countBytes due to reaching the end of the available memory address.

void SetSquareWavePin(DS1307SquareWaveOut pinMode)

piMode - the mode to have the SquareWave pin act as. One of the following values valid.
DS1307SquareWaveOut_1Hz - the pin will trigger high once a second
DS1307SquareWaveOut_4kHz - the pin will trigger high 4096 times a second
DS1307SquareWaveOut_8kHz - the pin will trigger high 8192 times a second
DS1307SquareWaveOut_32kHz - the pin will trigger high 32768 times a second
DS1307SquareWaveOut_High - the pin will remain high
DS1307SquareWaveOut_Low - the pin will remain low