Device drive interface for the DS1307 real-time clock. More...

Detailed Description

Device drive interface for the DS1307 real-time clock.

Files

file  ds1307_internal.h
 Register definitions for DS1307 RTC.
 
file  ds1307.h
 DS1307 definitions.
 

Data Structures

struct  ds1307_t
 Device descriptor for DS1307 devices. More...
 
struct  ds1307_params_t
 Set of configuration parameters for DS1307 devices. More...
 

Macros

#define DS1307_I2C_ADDRESS   (0x68)
 I2C address of DS1307 RTC.
 
#define DS1307_I2C_MAX_CLK   (I2C_SPEED_FAST)
 Maximum I2C bus speed to use with the device.
 
#define DS1307_NVRAM_MAX_SIZE   (56U)
 Maximum size in byte of on-chip NVRAM.
 

Enumerations

enum  ds1307_sqw_mode_t {
  DS1307_SQW_MODE_0 = 0x00, DS1307_SQW_MODE_1000HZ = 0x10, DS1307_SQW_MODE_4096HZ = 0x11, DS1307_SQW_MODE_8192HZ = 0x12,
  DS1307_SQW_MODE_32768HZ = 0x13, DS1307_SQW_MODE_1 = 0x80
}
 Modes for the DS1307 square wave / output driver. More...
 

Functions

int ds1307_init (ds1307_t *dev, const ds1307_params_t *params)
 Initialize the given DS1307 device. More...
 
int ds1307_set_time (const ds1307_t *dev, const struct tm *time)
 Set RTC to a given time. More...
 
int ds1307_get_time (const ds1307_t *dev, struct tm *time)
 Get current RTC time. More...
 
int ds1307_halt (const ds1307_t *dev)
 Halt clock. More...
 
int ds1307_set_sqw_mode (const ds1307_t *dev, ds1307_sqw_mode_t mode)
 Set mode of square wave / output driver. More...
 
int ds1307_get_sqw_mode (const ds1307_t *dev)
 Get current mode of square wave / output driver. More...
 

Enumeration Type Documentation

◆ ds1307_sqw_mode_t

Modes for the DS1307 square wave / output driver.

Enumerator
DS1307_SQW_MODE_0 

OUT: 0.

DS1307_SQW_MODE_1000HZ 

SQW: 1kHz.

DS1307_SQW_MODE_4096HZ 

SQW: 4.096 kHz.

DS1307_SQW_MODE_8192HZ 

SQW: 8.192 kHz.

DS1307_SQW_MODE_32768HZ 

SQW: 32.768 kHz.

DS1307_SQW_MODE_1 

OUT: 1.

Definition at line 72 of file ds1307.h.

Function Documentation

◆ ds1307_get_sqw_mode()

int ds1307_get_sqw_mode ( const ds1307_t dev)

Get current mode of square wave / output driver.

Note
To get the actual output of the driver, attach the pin via GPIO
Parameters
[in]devdevice descriptor of the targeted device
Returns
current mode of the square wave / output driver (see ds1307_sqw_mode_t)
< 0 if unable to speak to the device

◆ ds1307_get_time()

int ds1307_get_time ( const ds1307_t dev,
struct tm time 
)

Get current RTC time.

Parameters
[in]devdevice descriptor of the targeted device
[out]timepointer to the struct to write the time to.
Returns
0 on success
< 0 if unable to speak to the device

◆ ds1307_halt()

int ds1307_halt ( const ds1307_t dev)

Halt clock.

Note
Can be reversed using ds1307_set_time()
Parameters
[in]devdevice descriptor of the targeted device
Returns
0 on success
< 0 if unable to speak to the device

◆ ds1307_init()

int ds1307_init ( ds1307_t dev,
const ds1307_params_t params 
)

Initialize the given DS1307 device.

Parameters
[out]devdevice descriptor of the targeted device
[in]paramsdevice configuration (i2c bus, address and bus clock)
Returns
0 on success
< 0 if unable to speak to the device

◆ ds1307_set_sqw_mode()

int ds1307_set_sqw_mode ( const ds1307_t dev,
ds1307_sqw_mode_t  mode 
)

Set mode of square wave / output driver.

Note
To get the actual output of the driver, attach the pin via GPIO
Parameters
[in]devdevice descriptor of the targeted device
[in]modemode for the square wave / output driver
Returns
0 on success
< 0 if unable to speak to the device

◆ ds1307_set_time()

int ds1307_set_time ( const ds1307_t dev,
const struct tm time 
)

Set RTC to a given time.

Parameters
[in]devdevice descriptor of the targeted device
[in]timepointer to the struct holding the time to set.
Returns
0 on success
< 0 if unable to speak to the device