Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
ds1307.h File Reference
#include "ultibo/i2c.h"
#include "ultibo/rtc.h"

Go to the source code of this file.

Data Structures

struct  _DS1307_RTC_DEVICE

Macros

#define DS1307_RTC_DESCRIPTION   "Maxim DS1307 Real Time Clock"
 Description of DS1307 device.
#define DS1307_MIN_TIME   125911584000000000
 Time starts at 01/01/2000 00:00:00 (MM/DD/YY HH:MM:SS).
#define DS1307_MAX_TIME   157469183990000000
 Time ends at 12/31/2099 23:59:59 (MM/DD/YY HH:MM:SS).
#define DS1307_CHIP_DS1307   0
#define DS1307_CHIP_DS1337   1
#define DS1307_CHIP_DS1338   2
#define DS1307_CHIP_DS1339   3
#define DS1307_CHIP_DS1340   4
#define DS1307_CHIP_DS1388   5
#define DS1307_CHIP_DS3231   6
#define DS1307_CHIP_M41T00   7
#define DS1307_CHIP_MCP794XX   8
#define DS1307_CHIP_RX8025   9
#define DS1307_REG_SECONDS   0x00
 00-59
#define DS1307_REG_MINUTE   0x01
 00-59
#define DS1307_REG_HOUR   0x02
 00-23 (or 1-12am,pm)
#define DS1307_REG_WEEKDAY   0x03
 01-07
#define DS1307_REG_DAY   0x04
 01-31
#define DS1307_REG_MONTH   0x05
 01-12
#define DS1307_REG_YEAR   0x06
 00-99
#define DS1307_REG_CONTROL   0x07
 Also DS1338.
#define DS1337_REG_CONTROL   0x0e
#define DS1340_REG_CONTROL   0x07
#define DS1340_REG_FLAG   0x09
#define DS1337_REG_STATUS   0x0f
#define DS1339_REG_ALARM1_SECONDS   0x07
#define RX8025_REG_CONTROL1   0x0e
#define RX8025_REG_CONTROL2   0x0f
#define DS1307_REG_SECONDS_CH   0x80
 Clock Halt bit (1 to Disable / 0 to Enable the clock).
#define DS1340_REG_SECONDS_nEOSC   0x80
#define MCP794XX_REG_SECONDS_ST   0x80
 Clock Stop Bit (1 to Enable / 0 to Disable the clock).
#define DS1307_REG_HOUR_12HR   0x40
 12/24 hour bit (1 = 12 hour mode / 0 = 24 hour mode)
#define DS1307_REG_HOUR_PM   0x20
 AM/PM bit (1 = PM / 0 = AM) (Only in 12 hour mode).
#define DS1340_REG_HOUR_CENTURY_EN   0x80
#define DS1340_REG_HOUR_CENTURY   0x40
#define MCP794XX_REG_WEEKDAY_VBATEN   0x08
 Battery Backup Enabled (1 to Enable / 0 to Disable).
#define DS1337_REG_MONTH_CENTURY   0x80
#define DS1307_REG_CONTROL_OUT   0x80
 Output Control (Output level of SQW/OUT pin when SQWE = 0).
#define DS1338_REG_CONTROL_OSF   0x20
#define DS1307_REG_CONTROL_SQWE   0x10
 Square-Wave Enable (When set to 1, enables the oscillator output).
#define DS1307_REG_CONTROL_RS1   0x02
 Rate Select 1 (See datasheet for values).
#define DS1307_REG_CONTROL_RS0   0x01
 Rate Select 2 (See datasheet for values).
#define DS1337_REG_CONTROL_nEOSC   0x80
#define DS1339_REG_CONTROL_BBSQI   0x20
#define DS3231_REG_CONTROL_BBSQW   0x40
 same as BBSQI
#define DS1337_REG_CONTROL_RS2   0x10
#define DS1337_REG_CONTROL_RS1   0x08
#define DS1337_REG_CONTROL_INTCN   0x04
#define DS1337_REG_CONTROL_A2IE   0x02
#define DS1337_REG_CONTROL_A1IE   0x01
#define DS1340_REG_CONTROL_OUT   0x80
#define DS1340_REG_CONTROL_FT   0x40
#define DS1340_REG_CONTROL_CALIB_SIGN   0x20
#define DS1340_REG_CONTROL_M_CALIBRATION   0x1f
#define DS1340_REG_FLAG_OSF   0x80
#define DS1337_REG_STATUS_OSF   0x80
#define DS1337_REG_STATUS_A2I   0x02
#define DS1337_REG_STATUS_A1I   0x01
#define RX8025_REG_CONTROL1_2412   0x20
#define RX8025_REG_CONTROL2_PON   0x10
#define RX8025_REG_CONTROL2_VDET   0x40
#define RX8025_REG_CONTROL2_XST   0x20

Typedefs

typedef uint8_t DS1307_RTC_TIME[7]
typedef struct _DS1307_RTC_DEVICE DS1307_RTC_DEVICE

Functions

RTC_DEVICE *STDCALL ds1307_rtc_create (char *device, uint16_t address, uint32_t chip)
 Create, register and start a new DS1307 RTC device connected to the specified I2C device.
uint32_t STDCALL ds1307_rtc_destroy (RTC_DEVICE *rtc)
 Stop, deregister and destroy a DS1307 RTC device created by this driver.

Macro Definition Documentation

◆ DS1307_RTC_DESCRIPTION

#define DS1307_RTC_DESCRIPTION   "Maxim DS1307 Real Time Clock"

Description of DS1307 device.

DS1307 specific constants

◆ DS1307_MIN_TIME

#define DS1307_MIN_TIME   125911584000000000

Time starts at 01/01/2000 00:00:00 (MM/DD/YY HH:MM:SS).

◆ DS1307_MAX_TIME

#define DS1307_MAX_TIME   157469183990000000

Time ends at 12/31/2099 23:59:59 (MM/DD/YY HH:MM:SS).

◆ DS1307_CHIP_DS1307

#define DS1307_CHIP_DS1307   0

DS1307 chip constants

◆ DS1307_CHIP_DS1337

#define DS1307_CHIP_DS1337   1

◆ DS1307_CHIP_DS1338

#define DS1307_CHIP_DS1338   2

◆ DS1307_CHIP_DS1339

#define DS1307_CHIP_DS1339   3

◆ DS1307_CHIP_DS1340

#define DS1307_CHIP_DS1340   4

◆ DS1307_CHIP_DS1388

#define DS1307_CHIP_DS1388   5

◆ DS1307_CHIP_DS3231

#define DS1307_CHIP_DS3231   6

◆ DS1307_CHIP_M41T00

#define DS1307_CHIP_M41T00   7

◆ DS1307_CHIP_MCP794XX

#define DS1307_CHIP_MCP794XX   8

◆ DS1307_CHIP_RX8025

#define DS1307_CHIP_RX8025   9

◆ DS1307_REG_SECONDS

#define DS1307_REG_SECONDS   0x00

00-59

DS1307 RTC registers

◆ DS1307_REG_MINUTE

#define DS1307_REG_MINUTE   0x01

00-59

◆ DS1307_REG_HOUR

#define DS1307_REG_HOUR   0x02

00-23 (or 1-12am,pm)

◆ DS1307_REG_WEEKDAY

#define DS1307_REG_WEEKDAY   0x03

01-07

◆ DS1307_REG_DAY

#define DS1307_REG_DAY   0x04

01-31

◆ DS1307_REG_MONTH

#define DS1307_REG_MONTH   0x05

01-12

◆ DS1307_REG_YEAR

#define DS1307_REG_YEAR   0x06

00-99

◆ DS1307_REG_CONTROL

#define DS1307_REG_CONTROL   0x07

Also DS1338.

DS1307 Control and Status registers

◆ DS1337_REG_CONTROL

#define DS1337_REG_CONTROL   0x0e

◆ DS1340_REG_CONTROL

#define DS1340_REG_CONTROL   0x07

◆ DS1340_REG_FLAG

#define DS1340_REG_FLAG   0x09

◆ DS1337_REG_STATUS

#define DS1337_REG_STATUS   0x0f

◆ DS1339_REG_ALARM1_SECONDS

#define DS1339_REG_ALARM1_SECONDS   0x07

◆ RX8025_REG_CONTROL1

#define RX8025_REG_CONTROL1   0x0e

◆ RX8025_REG_CONTROL2

#define RX8025_REG_CONTROL2   0x0f

◆ DS1307_REG_SECONDS_CH

#define DS1307_REG_SECONDS_CH   0x80

Clock Halt bit (1 to Disable / 0 to Enable the clock).

DS1307 Seconds register bits

◆ DS1340_REG_SECONDS_nEOSC

#define DS1340_REG_SECONDS_nEOSC   0x80

◆ MCP794XX_REG_SECONDS_ST

#define MCP794XX_REG_SECONDS_ST   0x80

Clock Stop Bit (1 to Enable / 0 to Disable the clock).

◆ DS1307_REG_HOUR_12HR

#define DS1307_REG_HOUR_12HR   0x40

12/24 hour bit (1 = 12 hour mode / 0 = 24 hour mode)

DS1307 Hour register bits

◆ DS1307_REG_HOUR_PM

#define DS1307_REG_HOUR_PM   0x20

AM/PM bit (1 = PM / 0 = AM) (Only in 12 hour mode).

◆ DS1340_REG_HOUR_CENTURY_EN

#define DS1340_REG_HOUR_CENTURY_EN   0x80

◆ DS1340_REG_HOUR_CENTURY

#define DS1340_REG_HOUR_CENTURY   0x40

◆ MCP794XX_REG_WEEKDAY_VBATEN

#define MCP794XX_REG_WEEKDAY_VBATEN   0x08

Battery Backup Enabled (1 to Enable / 0 to Disable).

MCP794XX Weekday register bits

◆ DS1337_REG_MONTH_CENTURY

#define DS1337_REG_MONTH_CENTURY   0x80

DS1337 Month register bits

◆ DS1307_REG_CONTROL_OUT

#define DS1307_REG_CONTROL_OUT   0x80

Output Control (Output level of SQW/OUT pin when SQWE = 0).

DS1307 Control register bits

◆ DS1338_REG_CONTROL_OSF

#define DS1338_REG_CONTROL_OSF   0x20

◆ DS1307_REG_CONTROL_SQWE

#define DS1307_REG_CONTROL_SQWE   0x10

Square-Wave Enable (When set to 1, enables the oscillator output).

◆ DS1307_REG_CONTROL_RS1

#define DS1307_REG_CONTROL_RS1   0x02

Rate Select 1 (See datasheet for values).

◆ DS1307_REG_CONTROL_RS0

#define DS1307_REG_CONTROL_RS0   0x01

Rate Select 2 (See datasheet for values).

◆ DS1337_REG_CONTROL_nEOSC

#define DS1337_REG_CONTROL_nEOSC   0x80

DS1337 Control register bits

◆ DS1339_REG_CONTROL_BBSQI

#define DS1339_REG_CONTROL_BBSQI   0x20

◆ DS3231_REG_CONTROL_BBSQW

#define DS3231_REG_CONTROL_BBSQW   0x40

same as BBSQI

◆ DS1337_REG_CONTROL_RS2

#define DS1337_REG_CONTROL_RS2   0x10

◆ DS1337_REG_CONTROL_RS1

#define DS1337_REG_CONTROL_RS1   0x08

◆ DS1337_REG_CONTROL_INTCN

#define DS1337_REG_CONTROL_INTCN   0x04

◆ DS1337_REG_CONTROL_A2IE

#define DS1337_REG_CONTROL_A2IE   0x02

◆ DS1337_REG_CONTROL_A1IE

#define DS1337_REG_CONTROL_A1IE   0x01

◆ DS1340_REG_CONTROL_OUT

#define DS1340_REG_CONTROL_OUT   0x80

DS1340 Control register bits

◆ DS1340_REG_CONTROL_FT

#define DS1340_REG_CONTROL_FT   0x40

◆ DS1340_REG_CONTROL_CALIB_SIGN

#define DS1340_REG_CONTROL_CALIB_SIGN   0x20

◆ DS1340_REG_CONTROL_M_CALIBRATION

#define DS1340_REG_CONTROL_M_CALIBRATION   0x1f

◆ DS1340_REG_FLAG_OSF

#define DS1340_REG_FLAG_OSF   0x80

DS1340 Flag register bits

◆ DS1337_REG_STATUS_OSF

#define DS1337_REG_STATUS_OSF   0x80

DS1337 Status register bits

◆ DS1337_REG_STATUS_A2I

#define DS1337_REG_STATUS_A2I   0x02

◆ DS1337_REG_STATUS_A1I

#define DS1337_REG_STATUS_A1I   0x01

◆ RX8025_REG_CONTROL1_2412

#define RX8025_REG_CONTROL1_2412   0x20

RX8025 Control1 register bits

◆ RX8025_REG_CONTROL2_PON

#define RX8025_REG_CONTROL2_PON   0x10

RX8025 Control2 register bits

◆ RX8025_REG_CONTROL2_VDET

#define RX8025_REG_CONTROL2_VDET   0x40

◆ RX8025_REG_CONTROL2_XST

#define RX8025_REG_CONTROL2_XST   0x20

Typedef Documentation

◆ DS1307_RTC_TIME

typedef uint8_t DS1307_RTC_TIME[7]

DS1307 specific types

◆ DS1307_RTC_DEVICE

Function Documentation

◆ ds1307_rtc_create()

RTC_DEVICE *STDCALL ds1307_rtc_create ( char * device,
uint16_t address,
uint32_t chip )

Create, register and start a new DS1307 RTC device connected to the specified I2C device.

DS1307 Functions

Parameters
DeviceThe I2C device this DS1307 is connected to
AddressThe I2C address for this DS1307
ChipThe chip type for this DS1307 (eg DS1307_CHIP_DS1307)
Returns
Pointer to the new RTC device or nil on failure

◆ ds1307_rtc_destroy()

uint32_t STDCALL ds1307_rtc_destroy ( RTC_DEVICE * rtc)

Stop, deregister and destroy a DS1307 RTC device created by this driver.

Parameters
RTCThe RTC device to destroy
Returns
ERROR_SUCCESS if completed or another error code on failure