BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Macros | Typedefs | Functions
ds3231.h File Reference

Chip data for Maxim DS3231 I2C RTC/TCXO/Crystal. More...

#include <bsp430/core.h>
#include <time.h>

Go to the source code of this file.

Data Structures

struct  sDS3231registers
 

Macros

#define DS3231_I2C_ADDRESS   0x68
 

Typedefs

typedef struct sDS3231registers sDS3231registers
 

Functions

uint8_t ucDS3231encodeHour (unsigned int hours, int is_12h)
 
unsigned int uiDS3231decodeHour (uint8_t hour_ds3231)
 
const struct tm * xDS3231registersToTm (const sDS3231registers *regp, struct tm *timep)
 
const sDS3231registersxDS3231tmToRegisters (const struct tm *timep, sDS3231registers *regp)
 

Detailed Description

Chip data for Maxim DS3231 I2C RTC/TCXO/Crystal.

This file contains the register map for the DS3231 real-time clock chip. There is no abstraction for the functional capability of the chip, except that there are routines to convert between the register map and POSIX standard time structures.

To incorporate the conversion routines add the following to your Makefile:

VPATH += $(BSP430_ROOT)/chips
MODULES += chips/ds3231
Homepage
http://github.com/pabigot/bsp430

Macro Definition Documentation

#define DS3231_I2C_ADDRESS   0x68

I2C address for DS3231 I2C RTX/TCXO/Crystal

Typedef Documentation

DS3231 register map

Function Documentation

uint8_t ucDS3231encodeHour ( unsigned int  hours,
int  is_12h 
)

Convert from integer hour value to DS3231 encoded hour

The DS3231 represents hours as a register encoding either a 12-hr or 24-hr time, not a basic BCD representation.

Parameters
hoursthe integer hour value in the range 0..23
is_12hnon-zero to represent the time as 12h with AM/PM; zero to represent time as a 24-hour value.
Returns
hour value encoded in DS3231 format
unsigned int uiDS3231decodeHour ( uint8_t  hour_ds3231)

Convert from encoded DS3231 hour value to integer hour

Parameters
hour_ds3231Hour value encoded in DS3231 including 12h/24h flag in BIT6
Returns
integer hour value in range 0..23
const struct tm* xDS3231registersToTm ( const sDS3231registers regp,
struct tm *  timep 
)

Convert DS3231 date/time register settings to POSIX standard structure.

The previous contents of *timep are completely erased. The time conversion supports both 12-hour and 24-hour formats.

Parameters
regppointer to a DS3231 register map complete through byte 0x06.
timeppointer to a POSIX time structure that will be cleared and initialized to the time recorded in regp
Returns
timep
const sDS3231registers* xDS3231tmToRegisters ( const struct tm *  timep,
sDS3231registers regp 
)

Convert POSIX time structure to DSD3231 date/time register settings.

The first seven bytes of *regp are erased, except that BIT6 of sDS3231registers::hours is preserved to record whether 12-hour or 24-hour time is desired. The remaining bytes of *regp are unmodified.

Parameters
timeppointer to the POSIX time
regppointer to a DS3231 register map
Returns
regp