Contiki 3.x
Functions | Variables
ds3231-sensor.c File Reference

            Sensors for DS3231 (RTC with Temperature Sensor).
More...

#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <contiki.h>
#include "ds3231-sensor.h"
#include "i2cmaster.h"
#include <inttypes.h>

Go to the source code of this file.

Functions

int I2C (uint8_t *write, uint16_t write_len, uint8_t *read, uint16_t read_len)
 DS3231 is connected to TWI Master on Port C (Pins 0 & 1). More...
 
int ds3231_get_time (struct tm *t)
 ds3231_get_time More...
 
int ds3231_set_time (struct tm *t)
 ds3231_set_time More...
 
int ds3231_set_alarm (struct tm *t)
 ds3231_set_alarm More...
 
int ds3231_clear_alarm (void)
 ds3231_clear_alarm More...
 
int ds3231_temperature (void)
 ds3231_temperature More...
 
int configure (int type, int c)
 configure
 
int status (int type)
 status
 

Variables

const struct sensors_sensor ds3231_sensor
 Export the DS3231 sensor object. More...
 

Detailed Description

            Sensors for DS3231 (RTC with Temperature Sensor).
Author
Timothy Rule trule.nosp@m..git.nosp@m.hub@n.nosp@m.ym.h.nosp@m.ush.c.nosp@m.om
Note
See http://www.maxim-ic.com/datasheet/index.mvp/id/4627

Definition in file ds3231-sensor.c.

Function Documentation

int ds3231_clear_alarm ( void  )

ds3231_clear_alarm

Clears and disables Alarm 1.

Returns
0 for success, -ve for error.

Definition at line 230 of file ds3231-sensor.c.

Referenced by configure().

int ds3231_get_time ( struct tm t)

ds3231_get_time

Returns
0 for success, -ve for error.
Note
The base date of tm struct is 1900-01-01 and the base date stored in the RTC for this application is 2000-01-01. An adjustment of 100 is made before getting the time.

Definition at line 100 of file ds3231-sensor.c.

int ds3231_set_alarm ( struct tm t)

ds3231_set_alarm

Sets the first alarm of the DS3231. Alarm Mask Bits A1M1-4 are all set to 0 which means the alarm will fire on the complete alarm setting (date, hour, minute & second).

When the alarm is triggered the INT pin of the DS3231 will be pulled low. This pin is connected to Port C Pin 2 of the AVR XMega.

Returns
0 for success, -ve for error.

Definition at line 180 of file ds3231-sensor.c.

Referenced by configure().

int ds3231_set_time ( struct tm t)

ds3231_set_time

Returns
0 for success, -ve for error.
Note
The base date of tm struct is 1900-01-01 and the base date stored in the RTC for this application is 2000-01-01. An adjustment of 100 is made before setting the time.

Definition at line 136 of file ds3231-sensor.c.

Referenced by configure().

int ds3231_temperature ( void  )

ds3231_temperature

Register 11h: bit 7 is sign, bit 6-0 are temperature. Register 12h: bit 7 & 6 are decimal point (0.25 * xxb).

Returns
Temperature * 100 (centi %) however accuracy is limited to 0.25 degree increments.

Definition at line 262 of file ds3231-sensor.c.

References I2C().

int I2C ( uint8_t *  write,
uint16_t  write_len,
uint8_t *  read,
uint16_t  read_len 
)

DS3231 is connected to TWI Master on Port C (Pins 0 & 1).

The active low Interrupt from the DS3231 is connected in Pin 2 of Port C.

Definition at line 62 of file ds3231-sensor.c.

Referenced by ds3231_clear_alarm(), ds3231_get_temperature(), ds3231_get_time(), ds3231_set_alarm(), ds3231_set_time(), ds3231_temperature(), i2c_disable(), and i2c_enable().

Variable Documentation

const struct sensors_sensor ds3231_sensor

Export the DS3231 sensor object.

Can be called as follows:

            #include <dev/ds3231-sensor.h>

            SENSORS_ACTIVATE(ds3231_sensor);
    ds3231_sensor.configure(DS3231_CONFIG_SET_TIME, (int)&t);
    ds3231_sensor.configure(DS3231_CONFIG_SET_ALARM, (int)&t);
    ds3231_sensor.value(DS3231_SENSOR_TEMP);
    ds3231_sensor.value(DS3231_SENSOR_GET_EPOCH_SECONDS_LSB);
    ds3231_sensor.value(DS3231_SENSOR_GET_EPOCH_SECONDS_MSB);
    ds3231_sensor.configure(DS3231_CONFIG_CLEAR_ALARM, 0);

Definition at line 82 of file ds3231-sensor.c.