C code and C++ library, driver software for Maxim Integrated DS1775, DS75 thermometer and thermostat temperature sensor. Code supports continuous or shut-down/standby, hysteresis, alarm limits, comparator or interrupt mode, fault filtering, and active low/high. Compact 5-pin SOT23 packaging

Dependents:   DS1775_Digital_Thermostat_Temperature

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ds1775_cpp.h Source File

ds1775_cpp.h

00001 /*******************************************************************************
00002 * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************
00032 * @file ds1775_cpp.h
00033 *******************************************************************************
00034 */
00035 #ifndef DS1775_CPP_H
00036 #define DS1775_CPP_H
00037 #include "mbed.h"
00038 
00039 
00040 /**
00041  * @brief Digital thermometer, thermostat, temperature sensor.
00042  * @version 1.0000.0002
00043  *
00044  * @details The DS1775 reports the device's temperature
00045  * over the I2C bus.
00046  * It supports high, low triggers stored in EEPROM for hystersis
00047  * or limit alarms using comparator or interrupt mode.
00048  * The DS1775 can operate in shutdown and one-shot mode for
00049  * extremely low power applications.
00050  * The software is compatible with the DS75.
00051  * Five pin SOT23 package
00052  * Accuracy is +-2.0°C from -55°C to +125°C (-67°F to +257°),
00053  *
00054  * @code 
00055  * #include "mbed.h"
00056  * #include "max32630fthr.h"
00057  * #include "ds1775.h"
00058  * #include "USBSerial.h"
00059  * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); 
00060  * I2C i2cBus(P3_4, P3_5);
00061  * int main()
00062  * {
00063  *     float temperature;
00064  *     DigitalOut rLED(LED1, LED_OFF);
00065  *     DigitalOut gLED(LED2, LED_OFF);
00066  *     DigitalOut bLED(LED3, LED_OFF);
00067  *     gLED = LED_ON;
00068  *     DS1775 temp_sensor(i2cBus, DS1775_I2C_SLAVE_ADR_R0);
00069  *     i2cBus.frequency(400000);
00070  *        temperature =
00071  *            temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
00072  *        printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
00073  *            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
00074  * }
00075  * @endcode
00076  */
00077 
00078 class DS1775
00079 {
00080     public:
00081 
00082     /**********************************************************//**
00083      * @brief Constructor for DS1775 Class.  
00084      * 
00085      * @details Allows user to use existing I2C object
00086      *
00087      * On Entry:
00088      *     @param[in] i2c_bus - pointer to existing I2C object
00089      *     @param[in] i2c_adrs - 7-bit slave address of DS1775
00090      *
00091      * On Exit:
00092      *
00093      * @return None
00094      **************************************************************/
00095     DS1775(I2C &i2c_bus, uint8_t slave_address);
00096  
00097     /**********************************************************//**
00098      * @brief Default destructor for DS1775 Class.  
00099      *
00100      * @details Destroys I2C object if owner 
00101      *
00102      * On Entry:
00103      *
00104      * On Exit:
00105      *
00106      * @return None
00107      **************************************************************/
00108     ~DS1775();
00109 
00110     /**
00111      * @brief  Read register of device at slave address
00112      * @param[out] value - Read data on success
00113      * @return 0 on success, negative number on failure
00114      */
00115     int read_cfg_reg(uint8_t *value);
00116 
00117     /**
00118      * @brief  Read register of device at slave address
00119      * @param[out] value - Read data on success
00120      * @param reg - Register address
00121      * @return 0 on success, negative number on failure
00122      */
00123     int read_reg16(int16_t *value, char reg);
00124 
00125     /** 
00126      * @brief Reads the temperature registers
00127      * @param reg - the address of the temperature register
00128      * @return temperature in degrees Celsius
00129      */
00130     float read_reg_as_temperature(uint8_t reg);
00131 
00132     /** 
00133      * @brief Writes to the configuration register
00134      * @param cfg - configurate word
00135      * @return 0 on success, negative number on failure
00136      */
00137      int write_cfg_reg(uint8_t cfg);
00138 
00139     /** 
00140      * @brief Writes to the THYST register
00141      * @param temperature - the temperature in Celsius degrees
00142      * @return 0 on success, negative number on failure
00143      */
00144      int write_trip_low_thyst(float temperature);
00145 
00146     /** 
00147      * @brief Writes to the TOS register
00148      * @param temperature - the temperature in Celsius degrees
00149      * @return 0 on success, negative number on failure
00150      */
00151      int write_trip_high_tos(float temperature);
00152 
00153     /** 
00154      * @brief Converts Celsius degrees to Fahrenheit
00155      * @param temp_c - the temperature in Celsius degrees
00156      * @return temperature in Celsius degrees
00157      */
00158      float celsius_to_fahrenheit(float temp_c);
00159 
00160 protected: 
00161     /** 
00162      * @brief Write a value to a register
00163      * @param value - value to write to the register
00164      * @param reg - register address
00165      * @return 0 on success, negative number on failure
00166      */
00167     int write_reg16(int16_t value, char reg);
00168 
00169 private:
00170     /** @var m_i2c
00171      * @brief I2C object
00172      */
00173     I2C &m_i2c;
00174     /** @var m_write_address, m_read_address
00175      * @brief I2C address
00176      */
00177     uint8_t m_write_address, m_read_address;
00178 };
00179 
00180 #endif/* DS1775_CPP_H */