MD_D1307 Real Time Clock Library  1.3
Library to control DS1307 real time clock
MD_DS1307 Class Reference

#include <MD_DS1307.h>

Public Member Functions

 MD_DS1307 ()
 
 MD_DS1307 (int sda, int scl)
 
Methods for object and hardware control.
void control (uint8_t item, uint8_t value)
 
uint8_t status (uint8_t item)
 
Methods for RTC operations
void readTime (void)
 
void writeTime (void)
 
void now (void)
 
boolean isRunning (void)
 
Miscellaneous methods
uint8_t readRAM (uint8_t addr, uint8_t *buf, uint8_t len)
 
uint8_t writeRAM (uint8_t addr, uint8_t *buf, uint8_t len)
 
uint8_t calcDoW (uint16_t yyyy, uint8_t mm, uint8_t dd)
 

Public Attributes

Public variables for reading and writing time data
uint16_t yyyy
 Year including the century.
 
uint8_t mm
 Month (1-12)
 
uint8_t dd
 Date of the month (1-31)
 
uint8_t h
 Hour of the day (1-12) or (0-23) depending on the am/pm or 24h mode setting.
 
uint8_t m
 Minutes past the hour (0-59)
 
uint8_t s
 Seconds past the minute (0-59)
 
uint8_t dow
 Day of the week (1-7). Sequential number; day coding depends on the application and zero is an undefined value.
 
uint8_t pm
 Non-zero if 12 hour clock mode and PM, always zero for 24 hour clock. Check the time and if < 12 then check this indicator.
 

Detailed Description

Core object for the MD_DS1307 library

Constructor & Destructor Documentation

◆ MD_DS1307() [1/2]

MD_DS1307::MD_DS1307 ( )

Class Constructor

Instantiate a new instance of the class. One instance of the class is created in the libraries as the RTC object.

◆ MD_DS1307() [2/2]

MD_DS1307::MD_DS1307 ( int  sda,
int  scl 
)

Overloaded Class Constructor (ESP8266 only)

Provides a way to assign custom SCL and SDA pins if the architecture supports them.

Parameters
sdaPin number for the SDA signal
sclPin number for the SCL signal

Member Function Documentation

◆ calcDoW()

uint8_t MD_DS1307::calcDoW ( uint16_t  yyyy,
uint8_t  mm,
uint8_t  dd 
)

Calculate day of week for a given date

Given the specified date, calculate the day of week.

See also
Wikipedia https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
Parameters
yyyyyear for specified date. yyyy must be > 1752.
mmmonth for the specified date where mm is in the range [1..12], 1 = January.
dddate for the specified date in the range [1..31], where 1 = first day of the month.
Returns
dow value calculated [1..7], where 1 = Sunday.

◆ control()

void MD_DS1307::control ( uint8_t  item,
uint8_t  value 
)

Set the control status of the specified parameter to the specified value.

The device has a number of control parameters that can be set through this method. The type of control action required is passed through the mode parameter and should be one of the defined control actions. The value that needs to be supplied on the control action required is one of the defined status values. Not all combinations of item and value are valid.

See also
Software Overview section in the introduction for a table of valid combinations.
Parameters
itemone of the defined code request values.
valuevalue as one of the defined code status values.

◆ isRunning()

boolean MD_DS1307::isRunning ( void  )

Compatibility function - Check if RTC is running

Wrapper for a HALT status check

See also
status() method
Returns
true if running, false otherwise.

◆ now()

void MD_DS1307::now ( void  )

Compatibility function - Read the current time

Wrapper to read the current time.

See also
readTime() method
Returns
no return value.

◆ readRAM()

uint8_t MD_DS1307::readRAM ( uint8_t  addr,
uint8_t *  buf,
uint8_t  len 
)

Read the raw RTC clock data

Read len bytes from the RTC clock starting at addr as raw data into the buffer supplied. The size of the buffer should be at least MAX_BUF bytes long (defined in the library cpp file).

Read address starts at 0.

See also
writeRAM() method
Parameters
addrstarting address for the read.
bufaddress of the receiving byte buffer.
lennumber of bytes to read.
Returns
number of bytes successfully read.

◆ readTime()

void MD_DS1307::readTime ( void  )

Read the current time into the interface registers

Query the RTC for the current time and load that into the library interface registers (yyyy, mm, dd, h, m, s, dow, pm) from which the data can be accessed.

Returns
false if errors, true otherwise.

◆ status()

uint8_t MD_DS1307::status ( uint8_t  item)

Obtain the current setting for the specified parameter.

Any of the parameters that can be set from the control() method can be queried using this method. The code status value returned will be one of the defined values for the control() method for each specific code request parameter.

See also
Software Overview section in the introduction for a table of valid combinations.
Parameters
itemone of the defined control request values.
Returns
one of the defined code status values or DS1307_ERROR if an error occurred.

◆ writeRAM()

uint8_t MD_DS1307::writeRAM ( uint8_t  addr,
uint8_t *  buf,
uint8_t  len 
)

Write the raw RTC clock data

Write len bytes of data in the buffer supplied to the RTC clock starting at addr. The size of the buffer should be at least len bytes long.

Write address starts at 8 (first 7 bytes are for clock registers).

See also
readRAM() method
Parameters
addrstarting address for the write.
bufaddress of the data buffer.
lennumber of bytes to write.
Returns
number of bytes successfully written.

◆ writeTime()

void MD_DS1307::writeTime ( void  )

Write the current time from the interface registers

Write the data in the interface registers (yyyy, mm, dd, h, m, s, dow, pm) as the current time in the RTC.


The documentation for this class was generated from the following files: