Library for the DS1721, 2-Wire Digital Thermometer and Thermostat from Dallas Semiconductor (Maxim Integrated)

Embed: (wiki syntax)

« Back to documentation index

DS1721 Class Reference

DS1721 Class Reference

!Library for the DS1721 temperature sensor. More...

#include <DS1721.h>

Public Member Functions

 DS1721 (I2C &i2c, int addr=(DS1721_ADDR<< 1))
 DS1721 constructor.
 DS1721 (I2C &i2c, int resolution, int polarity, int mode, int addr=(DS1721_ADDR<< 1))
 DS1721 constructor.
 ~DS1721 ()
float getTemp (void)
 Reads the temperature from the DS1721 and converts it to a useable value.
int setPolarity (int polarity)
 Sets the temperature polarity (POL) bit of the sensor.
int getPolarity (void)
 Gets the temperature polarity (POL) bit of the sensor.
int startConversion (void)
 Initiates a temperature conversion.
int stopConversion (void)
 Stops a temperature conversion.
int setConfig (int config)
 Sets the configuration register of the DS1721.
int getConfig (int *config)
 Retrieves the configuration register of the DS1721.
float getLowSp (void)
 Retrieves the configured low temperature set point value.
int setLowSp (float newSp)
 Sets the low temperature set point value.
float getHighSp (void)
 Retrieves the configured high temperature set point value.
int setHighSp (float newSp)
 Sets the high temperature set point value.

Detailed Description

!Library for the DS1721 temperature sensor.

The DS1721 is an I2C digital temperature sensor, with a range of -55C to +125C and a 0.125C resolution.

 #include "mbed.h"
 #include "DS1721.h"
 
 #define DS1721_I2C_ADDRESS (0x48<<1)
 
 int main(void) {
 I2C m_i2c(PTC9, PTC8);
 DS1721 thermo(m_i2c, DS1721_I2C_ADDRESS);
 
 // initialize the temperature sensor
 thermo.startConversion();
 thermo.setLowSp(25);
 thermo.setHighSp(27);
 thermo.setPolarity(POLARITY_ACTIVE_HIGH);
 
     while (true) {       
         printf("Temp: %d\r\n", thermo.getTemp());
     }
 } 

Definition at line 94 of file DS1721.h.


Constructor & Destructor Documentation

DS1721 ( I2C &  i2c,
int  addr = (DS1721_ADDR<<1) 
)

DS1721 constructor.

Parameters:
&i2cpointer to i2c object
addraddr of the I2C peripheral default = (DS1721_ADDR<<1)

Definition at line 42 of file DS1721.cpp.

DS1721 ( I2C &  i2c,
int  resolution,
int  polarity,
int  mode,
int  addr = (DS1721_ADDR<<1) 
)

DS1721 constructor.

Parameters:
&i2cpointer to I2C object
resolutionreadout resolution of the theremometer (9, 10, 11, 12 bit)
polaritythe state on which the thermostat output is enabled
modethe temperature conversion mode (single shot or continuous)
addraddr of the I2C peripheral default = (DS1721_ADDR<<1)

Definition at line 53 of file DS1721.cpp.

~DS1721 ( void   )

DS1721 destructor

Definition at line 61 of file DS1721.cpp.


Member Function Documentation

int getConfig ( int *  config )

Retrieves the configuration register of the DS1721.

Returns:

Definition at line 78 of file DS1721.cpp.

float getHighSp ( void   )

Retrieves the configured high temperature set point value.

Returns:
the current high temperature set point value (degrees C)

Definition at line 204 of file DS1721.cpp.

float getLowSp ( void   )

Retrieves the configured low temperature set point value.

Returns:
the current low temperature set point value (degrees C)

Definition at line 165 of file DS1721.cpp.

int getPolarity ( void   )

Gets the temperature polarity (POL) bit of the sensor.

This bit determines upon which set point the theremostat output (Tout) is active.

Returns:
the value of the POL bit (0 - active low, 1 - active high)

Definition at line 132 of file DS1721.cpp.

float getTemp ( void   )

Reads the temperature from the DS1721 and converts it to a useable value.

Returns:
the current temperature, as a float

Definition at line 98 of file DS1721.cpp.

int setConfig ( int  config )

Sets the configuration register of the DS1721.

Parameters:
intthe new configuration value (resolution | polarity | mode)
Returns:
the result of the function (0 - Failure, 1 - Success)

Definition at line 65 of file DS1721.cpp.

int setHighSp ( float  newSp )

Sets the high temperature set point value.

Parameters:
intthe new high temperature set point value (degrees C)
Returns:
the result of the function (0 - Failure, 1 - Success)

Definition at line 225 of file DS1721.cpp.

int setLowSp ( float  newSp )

Sets the low temperature set point value.

Parameters:
intthe new low set point temperature (degrees C)
Returns:
the result of the function (0 - Failure, 1 - Success)

Definition at line 187 of file DS1721.cpp.

int setPolarity ( int  polarity )

Sets the temperature polarity (POL) bit of the sensor.

This bit determines upon which set point the theremostat output is active.

Parameters:
intthe new polarity value
Returns:
the result of the function (0 - Failure, 1 - Success)

Definition at line 126 of file DS1721.cpp.

int startConversion ( void   )

Initiates a temperature conversion.

If the DS1721 is configured for single shot mode this function must be called prior to reading the temperature (re: getTemp())

Returns:
the result of the function (0 - Failure, 1 - Success)

Definition at line 139 of file DS1721.cpp.

int stopConversion ( void   )

Stops a temperature conversion.

Returns:
the result of the function (0 - Failure, 1 - Success)

Definition at line 152 of file DS1721.cpp.