Main Page | File List | Globals | Related Pages

c/ds1621.h File Reference

This file contains methods to access a DS1621 i2c temperature sensor over an i2c bus. More...

#include "globals.h"

Go to the source code of this file.

Defines

#define DS1621_ADDR   0x9e
 The i2c device address of the ds1621.
#define DS1621_FLAG_DONE   7
 Bit in status register that indicates the end of the temperature conversion progress.
#define DS1621_FLAG_1SHOT   0
 Bit in status register.
#define DS1621_CMD_START_CONVERT   0xee
 Command to start the temperature conversion.
#define DS1621_CMD_STOP_CONVERT   0x22
 Command to stop the temperature conversion when in continuous mode.
#define DS1621_CMD_READ_TEMP   0xaa
 Command to read the temperature from the ds1621 device.
#define DS1621_CMD_ACCESS_CONFIG   0xac
 Command to read the configuration register.
#define DS1621_CMD_READ_COUNTER   0xa8
 Command to read the temperature counter.
#define DS1621_CMD_READ_SLOPE   0xa9
 Command to read the slope counter.

Typedefs

typedef signed char temp_t
 Typedef for temperature data.
typedef u16 hires_temp_t
 Typedef for high resolution temperature data.

Functions

void ds1621_do_conversion (void)
 Start the temperature conversion inside the DS1621 device.
temp_t ds1621_gettemp (void)
 Read the temperature data and return it.
u08 ds1621_getreg (u08 cmd)
 Read a one-byte register from ds1621.
hires_temp_t ds1621_hires_gettemp (void)
 Read the temperature of the ds1621 with high resolution.


Detailed Description

This file contains methods to access a DS1621 i2c temperature sensor over an i2c bus.

The device address is currently hardcoded in the implementation file and supports only one DS1621 attached to the bus.


Define Documentation

#define DS1621_CMD_ACCESS_CONFIG   0xac
 

Command to read the configuration register.

Returns a one-byte-value, so you can use ds1621_retreg().

#define DS1621_CMD_READ_COUNTER   0xa8
 

Command to read the temperature counter.

Returns a one-byte-value, so you can use ds1621_retreg().

#define DS1621_CMD_READ_SLOPE   0xa9
 

Command to read the slope counter.

Returns a one-byte-value, so you can use ds1621_retreg().

#define DS1621_CMD_READ_TEMP   0xaa
 

Command to read the temperature from the ds1621 device.

After executing this command, you can read out a two-byte-value.

#define DS1621_FLAG_1SHOT   0
 

Bit in status register.

Indicates if the ds1621 is in 1shot-mode.


Typedef Documentation

typedef u16 hires_temp_t
 

Typedef for high resolution temperature data.

The high byte (msb) is the temperature in degree celsius. The low byte (lsb) can be interpreted as a fixed point number with its point before the first digit, i.e. 0x80 is 0.5°C, 0x40 is 0.25°C or 0xb0 is 0.75°C.

typedef signed char temp_t
 

Typedef for temperature data.

This has no special meaning or funciton, it only makes the code more readable by showing which function parameter or return value is coded as 8 bit temperature data, i.e as a fixed point number with the lsb making the 0.5°C bit.


Function Documentation

void ds1621_do_conversion void   ) 
 

Start the temperature conversion inside the DS1621 device.

This has to be done before each call to ds1621_gettemp() or ds1621_hires_gettemp().

u08 ds1621_getreg u08  cmd  ) 
 

Read a one-byte register from ds1621.

Parameters:
cmd The command / register to read.

temp_t ds1621_gettemp void   ) 
 

Read the temperature data and return it.

You need to call ds1621_do_conversion() before you can get valid temperature data if the DS1621 is in one-shot mode.

hires_temp_t ds1621_hires_gettemp void   ) 
 

Read the temperature of the ds1621 with high resolution.

You need to call ds1621_do_conversion() before you can get valid temperature data if the DS1621 is in one-shot mode. See the datasheet for an explanation how the temperature is calculated.

Todo:
Currently there is a bug in the code that results in wrong measurements. If the temperature raises e.g. from 20.7 to 20.8, the returned values are 20.7 -> 19.7 -> 20.8. If the temperature is falling there is a similar effect.


Generated on Wed Oct 27 10:57:05 2004 by  doxygen 1.3.9.1