Working Version of the Real Time Clock module DS1307.

Dependents:   Rtc_Ds1307_Sample TAREA_5_PROCESADORES Rtc_Ds1307_lcd_alarma Rtc_Ds1307_Reloj_con_alarma_aplazable ... more

Embed: (wiki syntax)

« Back to documentation index

Rtc_Ds1307 Class Reference

Rtc_Ds1307 Class Reference

Class Rtc_Ds1307 implements the real time clock module DS1307. More...

#include <Rtc_Ds1307.h>

Inherited by RtcCls.

Data Structures

struct  Time_rtc
 Structure which is used to exchange the time and date. More...

Public Types

enum  SqwRateSelect_t
 

RateSelect specifies the valid frequency values for the square wave output.

More...

Public Member Functions

 Rtc_Ds1307 (PinName sda, PinName scl)
 public constructor which creates the real time clock object
virtual bool getTime (Time_rtc &time)
 Read the current time from RTC chip.
virtual bool setTime (Time_rtc &time, bool start, bool thm)
 Write the given time onto the RTC chip.
bool startClock ()
 Start the clock.
bool stopClock ()
 Stop the clock.
const char * weekdayToString (int wday)
 Service function to convert a weekday into a string representation.
bool setSquareWaveOutput (bool ena, SqwRateSelect_t rs)
 Enable Square Wave output.

Detailed Description

Class Rtc_Ds1307 implements the real time clock module DS1307.

You can read the clock and set a new time and date. It is also possible to start and stop the clock. Rtc_Ds1307 allows you to display the time in a 12h or 24h format

Definition at line 34 of file Rtc_Ds1307.h.


Member Enumeration Documentation

RateSelect specifies the valid frequency values for the square wave output.

Definition at line 52 of file Rtc_Ds1307.h.


Constructor & Destructor Documentation

Rtc_Ds1307 ( PinName  sda,
PinName  scl 
)

public constructor which creates the real time clock object

Parameters:
sda: specifies the pin for the SDA communication line.
scl: the pin for the serial clock

Definition at line 12 of file Rtc_Ds1307.cpp.


Member Function Documentation

bool getTime ( Time_rtc time ) [virtual]

Read the current time from RTC chip.

Parameters:
time: reference to a struct tm which will be filled with the time from rtc
Returns:
true if successful, otherwise an acknowledge error occured

Definition at line 61 of file Rtc_Ds1307.cpp.

bool setSquareWaveOutput ( bool  ena,
SqwRateSelect_t  rs 
)

Enable Square Wave output.

The function enables or disables the square wave output of the module and sets the desired frequency.

Parameters:
ena: if set to true, the square wave output is enabled.
rs: rate select, can be either one of the four values defined by type /c RateSelect_t
Returns:
true if the operation was successful or false otherwise

Definition at line 137 of file Rtc_Ds1307.cpp.

bool setTime ( Time_rtc time,
bool  start,
bool  thm 
) [virtual]

Write the given time onto the RTC chip.

Parameters:
time: refereence to a struct which contains valid date and time information
start: contains true if the clock shall start (or keep on running).
thm: 12-hour-mode if set to true, otherwise 24-hour-mode will be set.
Returns:
true if successful, otherwise an acknowledge error occured

Definition at line 29 of file Rtc_Ds1307.cpp.

bool startClock (  )

Start the clock.

Please note that the seconds register need to be read and written in order to start or stop the clock. This can lead to an error in the time value. The recommended way of starting and stoping the clock is to write the actual date and time and set the start bit accordingly.

Returns:
true if the clock was started, false if a communication error occured

Definition at line 93 of file Rtc_Ds1307.cpp.

bool stopClock (  )

Stop the clock.

Please note that the seconds register need to be read and written in order to start or stop the clock. This can lead to an error in the time value. The recommended way of starting and stoping the clock is to write the actual date and time and set the start bit accordingly.

Returns:
true if the clock was stopped, false if a communication error occured

Definition at line 115 of file Rtc_Ds1307.cpp.

const char* weekdayToString ( int  wday )

Service function to convert a weekday into a string representation.

Parameters:
wday: day of week to convert (starting with sunday = 1, monday = 2, ..., saturday = 7
Returns:
the corresponding string representation

Definition at line 120 of file Rtc_Ds1307.h.