upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions | Data Fields
DS1307 Class Reference

API for the DS1307 Real-Time CLock. More...

Detailed Description

UPM module for the DS1307-based real-time clock. The clock can provide information about seconds, minutes, hours, day of the week, day of the month, month, and year. It can operate in either a 24-hour or a 12-hour format. This device can also output a square wave at 1Khz, 4Khz, 8Khz, and 32Khz. However, this capability is not implemented in this module.

ds1307.jpg
// Instantiate a DS1037 on I2C bus 0
upm::DS1307 *rtc = new upm::DS1307(0);
// always do this first
cout << "Loading the current time... " << endl;
if (!rtc->loadTime())
{
cerr << "rtc->loadTime() failed." << endl;
return 0;
}
printTime(rtc);
// set the year as an example
cout << "setting the year to 50" << endl;
rtc->year = 50;
rtc->setTime();
// reload the time and print it
rtc->loadTime();
printTime(rtc);

Public Member Functions

 DS1307 (int bus)
 
bool loadTime ()
 
bool setTime ()
 
mraa::Result enableClock ()
 
mraa::Result disableClock ()
 
mraa::Result writeBytes (uint8_t reg, uint8_t *buffer, int len)
 
int readBytes (uint8_t reg, uint8_t *buffer, int len)
 
unsigned int bcdToDec (uint8_t val)
 
uint8_t decToBcd (unsigned int val)
 

Data Fields

unsigned int seconds
 
unsigned int minutes
 
unsigned int hours
 
unsigned int dayOfWeek
 
unsigned int dayOfMonth
 
unsigned int month
 
unsigned int year
 
bool amPmMode
 
bool pm
 

Constructor & Destructor Documentation

DS1307 ( int  bus)

DS1307 constructor

Parameters
busI2C bus to use

Member Function Documentation

bool loadTime ( )

Loads all the time values

Returns
True if time data loaded successfully

Here is the call graph for this function:

bool setTime ( )

Sets the time. You should call loadTime() beforehand to maintain consistency

Returns
True if time is set successfully

Here is the call graph for this function:

mraa::Result enableClock ( )

Enables an oscillator on the clock.

Returns
0 (mraa::SUCCESS) if successful; non-zero otherwise

Here is the call graph for this function:

mraa::Result disableClock ( )

Disables the oscillator on the clock. This prevents the clock from updating any time/date values

Returns
0 (mraa::SUCCESS) if successful; non-zero otherwise

Here is the call graph for this function:

mraa::Result writeBytes ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Writes value(s) into registers

Parameters
regRegister location to start writing into
bufferBuffer for data storage
lenNumber of bytes to write
Returns
0 (mraa::SUCCESS) if successful; non-zero otherwise

Here is the caller graph for this function:

int readBytes ( uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Reads value(s) from registers

Parameters
regRegister location to start reading from
bufferBuffer for data storage
lenNumber of bytes to read
Returns
Number of bytes read

Here is the caller graph for this function:

unsigned int bcdToDec ( uint8_t  val)

Converts a BCD value into decimal

Parameters
valBCD value to convert
Returns
Converted decimal value

Here is the caller graph for this function:

uint8_t decToBcd ( unsigned int  val)

Converts a decimal value into BCD

Parameters
valDecimal value to convert
Returns
Converted BCD value

Here is the caller graph for this function:

Field Documentation

unsigned int seconds

Holds seconds

unsigned int minutes

Holds minutes

unsigned int hours

Holds hours; 1-12 in the am/pm format, 0-23 otherwise

unsigned int dayOfWeek

Holds a day of the week; 1-7, where 1 is Sunday

unsigned int dayOfMonth

Holds a day of the month, 1-31

unsigned int month

Holds a month, 1-12

unsigned int year

Holds a year, 0-99

bool amPmMode

True if the am/pm format is used, false otherwise

bool pm

For the am/pm format, it is true if it's pm, false otherwise


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