Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ds3231 by
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. | |
| Ds3231 (I2C &i2c_bus) | |
| 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 158 of file ds3231.h.
Member Enumeration Documentation
| enum ds3231_regs_t |
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 65 of file ds3231.cpp.
| Ds3231 | ( | I2C & | i2c_bus ) |
Constructor for Ds3231 Class.
On Entry:
- Parameters:
-
[in] i2c_bus - reference to existing bus
On Exit:
- Returns:
- none
Definition at line 73 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 360 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 337 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 445 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 487 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 466 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 305 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 160 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 133 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 290 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 91 of file ds3231.cpp.
Generated on Tue Jul 12 2022 23:14:20 by
1.7.2
