Library for DS3231 RTC

Dependents:   ard2pmod DS3231demo DS3231demo_COM_Port_Output MAXREFDES99_RTC_Display ... more

Embed: (wiki syntax)

« Back to documentation index

Ds3231 Class Reference

Ds3231 Class Reference

Ds3231 Class. More...

#include <ds3231.h>

Public Types

enum  ds3231_regs_t
 

ds3231_regs_t - enumerated DS3231 registers

More...

Public Member Functions

 Ds3231 (PinName sda, PinName scl)
 Constructor for Ds3231 Class.
uint16_t set_time (ds3231_time_t time)
 Sets the time on DS3231 Struct data is in integrer format, not BCD.
uint16_t set_calendar (ds3231_calendar_t calendar)
 Sets the calendar on DS3231.
uint16_t set_alarm (ds3231_alrm_t alarm, bool one_r_two)
 Set either Alarm1 or Alarm2 of DS3231.
uint16_t set_cntl_stat_reg (ds3231_cntl_stat_t data)
 Set control and status registers of DS3231.
uint16_t get_time (ds3231_time_t *time)
 Gets the time on DS3231.
uint16_t get_calendar (ds3231_calendar_t *calendar)
 Gets the calendar on DS3231.
uint16_t get_alarm (ds3231_alrm_t *alarm, bool one_r_two)
 Get either Alarm1 or Alarm2 of DS3231.
uint16_t get_cntl_stat_reg (ds3231_cntl_stat_t *data)
 Get control and status registers of DS3231.
uint16_t get_temperature (void)
 Get temperature data of DS3231.
time_t get_epoch (void)
 Get epoch time based on current RTC time and date.

Detailed Description

Ds3231 Class.

Definition at line 197 of file ds3231.h.


Member Enumeration Documentation

ds3231_regs_t - enumerated DS3231 registers

Definition at line 231 of file ds3231.h.


Constructor & Destructor Documentation

Ds3231 ( PinName  sda,
PinName  scl 
)

Constructor for Ds3231 Class.

On Entry:

Parameters:
[in]sda- sda pin of I2C bus
[in]scl- scl pin of I2C bus

On Exit:

Returns:
none

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 

Definition at line 70 of file ds3231.cpp.


Member Function Documentation

uint16_t get_alarm ( ds3231_alrm_t alarm,
bool  one_r_two 
)

Get either Alarm1 or Alarm2 of DS3231.

On Entry:

Parameters:
[in]alarm- pointer to struct for storing alarm data;
[in]one_r_two- TRUE for Alarm1 and FALSE for Alarm2

On Exit:

Parameters:
[out]alarm- contains integer alarm data
Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 //see ds3231.h for .members and datasheet for alarm format
 ds3231_alrm_t alarm; 
 uint16_t rtn_val;

 rtn_val = rtc.get_alarm(&alarm, FALSE);

Definition at line 516 of file ds3231.cpp.

uint16_t get_calendar ( ds3231_calendar_t calendar )

Gets the calendar on DS3231.

On Entry:

Parameters:
[in]calendar- pointer to struct for storing calendar data

On Exit:

Parameters:
[out]calendar- contains current integer rtc calendar data
Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 //see datasheet for calendar format
 ds3231_calendar_t calendar = {1, 1, 1, 0}; 
 uint16_t rtn_val;

 rtn_val = rtc.get_calendar(&calendar);

Definition at line 466 of file ds3231.cpp.

uint16_t get_cntl_stat_reg ( ds3231_cntl_stat_t data )

Get control and status registers of DS3231.

On Entry:

Parameters:
[in]data- pointer to struct for storing control and status register data

On Exit:

Parameters:
[out]data- contains control and status registers data
Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15);  
 
 //do not use 0xAA, see datasheet for appropriate data 
 ds3231_cntl_stat_t data = {0xAA, 0xAA}; 

 rtn_val = rtc.get_cntl_stat_reg(&data);

Definition at line 625 of file ds3231.cpp.

time_t get_epoch ( void   )

Get epoch time based on current RTC time and date.

DS3231 must be configured and running before this fx is called

On Entry:

On Exit:

Returns:
return value = epoch time

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 time_t epoch_time; 

 epoch_time = rtc.get_epoch();

Definition at line 707 of file ds3231.cpp.

uint16_t get_temperature ( void   )

Get temperature data of DS3231.

On Entry:

On Exit:

Returns:
return value = raw temperature data

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 uint16_t temp; 

 temp = rtc.get_temperature();

Definition at line 665 of file ds3231.cpp.

uint16_t get_time ( ds3231_time_t time )

Gets the time on DS3231.

On Entry:

Parameters:
[in]time- pointer to struct for storing time data

On Exit:

Parameters:
[out]time- contains current integrer rtc time data
Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 //time = 12:00:00 AM 12hr mode
 ds3231_time_t time = {12, 0, 0, 0, 1} 
 uint16_t rtn_val;

 rtn_val = rtc.get_time(&time);

Definition at line 409 of file ds3231.cpp.

uint16_t set_alarm ( ds3231_alrm_t  alarm,
bool  one_r_two 
)

Set either Alarm1 or Alarm2 of DS3231.

On Entry:

Parameters:
[in]alarm- struct cotaining alarm data
[in]one_r_two- TRUE for Alarm1 and FALSE for Alarm2

On Exit:

Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 //see ds3231.h for .members and datasheet for alarm format
 ds3231_alrm_t alarm; 
 uint16_t rtn_val;

 rtn_val = rtc.set_alarm(alarm, FALSE);

Definition at line 218 of file ds3231.cpp.

uint16_t set_calendar ( ds3231_calendar_t  calendar )

Sets the calendar on DS3231.

On Entry:

Parameters:
[in]calendar- struct cotaining calendar data

On Exit:

Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 //see datasheet for calendar format
 ds3231_calendar_t calendar = {1, 1, 1, 0}; 
 uint16_t rtn_val;

 rtn_val = rtc.set_calendar(calendar);

Definition at line 166 of file ds3231.cpp.

uint16_t set_cntl_stat_reg ( ds3231_cntl_stat_t  data )

Set control and status registers of DS3231.

On Entry:

Parameters:
[in]data- Struct containing control and status register data

On Exit:

Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15);  
 
 //do not use 0xAA, see datasheet for appropriate data 
 ds3231_cntl_stat_t data = {0xAA, 0xAA}; 

 rtn_val = rtc.set_cntl_stat_reg(data);

Definition at line 370 of file ds3231.cpp.

uint16_t set_time ( ds3231_time_t  time )

Sets the time on DS3231 Struct data is in integrer format, not BCD.

Fx will convert to BCD for you.

On Entry:

Parameters:
[in]time- struct cotaining time data;

On Exit:

Returns:
return value = 0 on success, non-0 on failure

Example:

 //instantiate rtc object
 Ds3231 rtc(D14, D15); 
 
 //time = 12:00:00 AM 12hr mode
 ds3231_time_t time = {12, 0, 0, 0, 1}
 uint16_t rtn_val;

 rtn_val = rtc.set_time(time);

Definition at line 102 of file ds3231.cpp.