DS3231 Real Time Clock

Driver for the Maxim DS3231 extremely accurate RTC. More...

Detailed Description

Driver for the Maxim DS3231 extremely accurate RTC.

About

This module implements a device driver for Maxim DS3231 RTC.

Implementation status

The current implementation does only support reading and setting of time registers as well as reading the temperature register and configuring the aging offset.

Setting alarms and configuring the square wave output is not yet supported.

Files

file  ds3231_params.h
 Default configuration for DS3231 devices.
 
file  ds3231.h
 Interface definition for the Maxim DS3231 RTC.
 

Data Structures

struct  ds3231_t
 Device descriptor for DS3231 devices. More...
 
struct  ds3231_params_t
 Set of configuration parameters for DS3231 devices. More...
 

Macros

#define DS3231_I2C_ADDR   0x68
 Default address of DS3231 sensors.
 

Enumerations

enum  { DS3231_OPT_BAT_ENABLE = 0x01, DS2321_OPT_32KHZ_ENABLE = 0x02 }
 Configuration options.
 

Functions

int ds3231_init (ds3231_t *dev, const ds3231_params_t *params)
 Initialize the given DS3231 device. More...
 
int ds3231_get_time (const ds3231_t *dev, struct tm *time)
 Get date and time from the device. More...
 
int ds3231_set_time (const ds3231_t *dev, const struct tm *time)
 Set date and time of the device. More...
 
int ds3231_get_aging_offset (const ds3231_t *dev, int8_t *offset)
 Get the configured aging offset (see datasheet for more information) More...
 
int ds3231_set_aging_offset (const ds3231_t *dev, int8_t offset)
 Set the aging offset (see datasheet for more information) More...
 
int ds3231_get_temp (const ds3231_t *dev, int16_t *temp)
 Get temperature from the device. More...
 
int ds3231_enable_bat (const ds3231_t *dev)
 Enable the backup battery. More...
 
int ds3231_disable_bat (const ds3231_t *dev)
 Disable the backup battery. More...
 

Function Documentation

◆ ds3231_disable_bat()

int ds3231_disable_bat ( const ds3231_t dev)

Disable the backup battery.

Parameters
[in]devDS3231 device descriptor
Returns
0 on success
-EIO on I2C communication error

◆ ds3231_enable_bat()

int ds3231_enable_bat ( const ds3231_t dev)

Enable the backup battery.

Parameters
[in]devDS3231 device descriptor
Returns
0 on success
-EIO on I2C communication error

◆ ds3231_get_aging_offset()

int ds3231_get_aging_offset ( const ds3231_t dev,
int8_t *  offset 
)

Get the configured aging offset (see datasheet for more information)

Parameters
[in]devDS3231 device descriptor
[out]offsetaging offset
Returns
0 on success
-EIO on I2C communication error

◆ ds3231_get_temp()

int ds3231_get_temp ( const ds3231_t dev,
int16_t *  temp 
)

Get temperature from the device.

Parameters
[in]devDS3231 device descriptor
[out]tempcurrent value of the temperature register [in centi °C]
Returns
0 on success
-EIO on I2C communication error

◆ ds3231_get_time()

int ds3231_get_time ( const ds3231_t dev,
struct tm *  time 
)

Get date and time from the device.

Parameters
[in]devDS3231 device descriptor
[out]timecurrent date and time from on device
Returns
0 on success
-EIO on I2C communication error

◆ ds3231_init()

int ds3231_init ( ds3231_t dev,
const ds3231_params_t params 
)

Initialize the given DS3231 device.

Parameters
[out]devdevice descriptor of the targeted device
[in]paramsdevice configuration
Returns
0 on success
-EIO if no DS3231 device was found

◆ ds3231_set_aging_offset()

int ds3231_set_aging_offset ( const ds3231_t dev,
int8_t  offset 
)

Set the aging offset (see datasheet for more information)

Parameters
[in]devDS3231 device descriptor
[in]offsetaging offset
Returns
0 on success
-EIO on I2C communication error

◆ ds3231_set_time()

int ds3231_set_time ( const ds3231_t dev,
const struct tm *  time 
)

Set date and time of the device.

Parameters
[in]devDS3231 device descriptor
[in]timetarget date and time
Returns
0 on success
-EIO on I2C communication error