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

Committer:
phonemacro
Date:
Sun Apr 07 11:24:02 2019 +0000
Revision:
14:c74a5b4d6715
Parent:
12:3ca79cd71289
Child:
15:449134e4b43f
updated comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 8:b2d4c71268aa 1 /*******************************************************************************
phonemacro 8:b2d4c71268aa 2 * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 8:b2d4c71268aa 3 *
phonemacro 8:b2d4c71268aa 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 8:b2d4c71268aa 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 8:b2d4c71268aa 6 * to deal in the Software without restriction, including without limitation
phonemacro 8:b2d4c71268aa 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 8:b2d4c71268aa 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 8:b2d4c71268aa 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 8:b2d4c71268aa 10 *
phonemacro 8:b2d4c71268aa 11 * The above copyright notice and this permission notice shall be included
phonemacro 8:b2d4c71268aa 12 * in all copies or substantial portions of the Software.
phonemacro 8:b2d4c71268aa 13 *
phonemacro 8:b2d4c71268aa 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 8:b2d4c71268aa 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 8:b2d4c71268aa 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 8:b2d4c71268aa 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 8:b2d4c71268aa 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 8:b2d4c71268aa 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 8:b2d4c71268aa 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 8:b2d4c71268aa 21 *
phonemacro 8:b2d4c71268aa 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 8:b2d4c71268aa 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 8:b2d4c71268aa 24 * Products, Inc. Branding Policy.
phonemacro 8:b2d4c71268aa 25 *
phonemacro 8:b2d4c71268aa 26 * The mere transfer of this software does not imply any licenses
phonemacro 8:b2d4c71268aa 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 8:b2d4c71268aa 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 8:b2d4c71268aa 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 8:b2d4c71268aa 30 * ownership rights.
phonemacro 8:b2d4c71268aa 31 *******************************************************************************
phonemacro 8:b2d4c71268aa 32 * @file ds1775_cpp.h
phonemacro 8:b2d4c71268aa 33 *******************************************************************************
phonemacro 8:b2d4c71268aa 34 */
phonemacro 8:b2d4c71268aa 35 #ifndef DS1775_CPP_H
phonemacro 8:b2d4c71268aa 36 #define DS1775_CPP_H
phonemacro 8:b2d4c71268aa 37 #include "mbed.h"
phonemacro 8:b2d4c71268aa 38
phonemacro 8:b2d4c71268aa 39
phonemacro 8:b2d4c71268aa 40 /**
phonemacro 12:3ca79cd71289 41 * @brief Digital thermometer, thermostat, temperature sensor.
phonemacro 12:3ca79cd71289 42 * @version 1.0000.0000
phonemacro 8:b2d4c71268aa 43 *
phonemacro 14:c74a5b4d6715 44 * @details The DS1775 reports the device's temperature
phonemacro 14:c74a5b4d6715 45 * over the I2C bus.
phonemacro 8:b2d4c71268aa 46 * It supports high, low triggers stored in EEPROM for hystersis
phonemacro 8:b2d4c71268aa 47 * or limit alarms using comparator or interrupt mode.
phonemacro 8:b2d4c71268aa 48 * The DS1775 can operate in shutdown and one-shot mode for
phonemacro 8:b2d4c71268aa 49 * extremely low power applications.
phonemacro 14:c74a5b4d6715 50 * The software is compatible with the DS75.
phonemacro 14:c74a5b4d6715 51 * Five pin SOT23 package
phonemacro 14:c74a5b4d6715 52 * Accuracy is +-2.0°C from -55°C to +125°C (-67°F to +257°),
phonemacro 8:b2d4c71268aa 53 *
phonemacro 8:b2d4c71268aa 54 * @code
phonemacro 8:b2d4c71268aa 55 * #include "mbed.h"
phonemacro 8:b2d4c71268aa 56 * #include "max32630fthr.h"
phonemacro 8:b2d4c71268aa 57 * #include "ds1775.h"
phonemacro 8:b2d4c71268aa 58 * #include "USBSerial.h"
phonemacro 14:c74a5b4d6715 59 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 8:b2d4c71268aa 60 * I2C i2cBus(P3_4, P3_5);
phonemacro 8:b2d4c71268aa 61 * int main()
phonemacro 8:b2d4c71268aa 62 * {
phonemacro 8:b2d4c71268aa 63 * float temperature;
phonemacro 8:b2d4c71268aa 64 * DigitalOut rLED(LED1, LED_OFF);
phonemacro 8:b2d4c71268aa 65 * DigitalOut gLED(LED2, LED_OFF);
phonemacro 8:b2d4c71268aa 66 * DigitalOut bLED(LED3, LED_OFF);
phonemacro 8:b2d4c71268aa 67 * gLED = LED_ON;
phonemacro 8:b2d4c71268aa 68 * DS1775 temp_sensor(i2cBus, DS1775_I2C_SLAVE_ADR_R0);
phonemacro 12:3ca79cd71289 69 * i2cBus.frequency(400000);
phonemacro 12:3ca79cd71289 70 * temperature =
phonemacro 12:3ca79cd71289 71 * temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
phonemacro 12:3ca79cd71289 72 * printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 12:3ca79cd71289 73 * temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 8:b2d4c71268aa 74 * }
phonemacro 8:b2d4c71268aa 75 * @endcode
phonemacro 8:b2d4c71268aa 76 */
phonemacro 8:b2d4c71268aa 77
phonemacro 8:b2d4c71268aa 78 class DS1775
phonemacro 8:b2d4c71268aa 79 {
phonemacro 8:b2d4c71268aa 80 public:
phonemacro 8:b2d4c71268aa 81
phonemacro 8:b2d4c71268aa 82 /**********************************************************//**
phonemacro 8:b2d4c71268aa 83 * @brief Constructor for DS1775 Class.
phonemacro 8:b2d4c71268aa 84 *
phonemacro 8:b2d4c71268aa 85 * @details Allows user to use existing I2C object
phonemacro 8:b2d4c71268aa 86 *
phonemacro 8:b2d4c71268aa 87 * On Entry:
phonemacro 8:b2d4c71268aa 88 * @param[in] i2c_bus - pointer to existing I2C object
phonemacro 8:b2d4c71268aa 89 * @param[in] i2c_adrs - 7-bit slave address of DS1775
phonemacro 8:b2d4c71268aa 90 *
phonemacro 8:b2d4c71268aa 91 * On Exit:
phonemacro 8:b2d4c71268aa 92 *
phonemacro 8:b2d4c71268aa 93 * @return None
phonemacro 8:b2d4c71268aa 94 **************************************************************/
phonemacro 8:b2d4c71268aa 95 DS1775(I2C &i2c_bus, uint8_t slave_address);
phonemacro 8:b2d4c71268aa 96
phonemacro 8:b2d4c71268aa 97 /**********************************************************//**
phonemacro 8:b2d4c71268aa 98 * @brief Default destructor for DS1775 Class.
phonemacro 8:b2d4c71268aa 99 *
phonemacro 8:b2d4c71268aa 100 * @details Destroys I2C object if owner
phonemacro 8:b2d4c71268aa 101 *
phonemacro 8:b2d4c71268aa 102 * On Entry:
phonemacro 8:b2d4c71268aa 103 *
phonemacro 8:b2d4c71268aa 104 * On Exit:
phonemacro 8:b2d4c71268aa 105 *
phonemacro 8:b2d4c71268aa 106 * @return None
phonemacro 8:b2d4c71268aa 107 **************************************************************/
phonemacro 8:b2d4c71268aa 108 ~DS1775();
phonemacro 8:b2d4c71268aa 109
phonemacro 8:b2d4c71268aa 110 /**
phonemacro 8:b2d4c71268aa 111 * @brief Read register of device at slave address
phonemacro 8:b2d4c71268aa 112 * @param[out] value - Read data on success
phonemacro 9:315236fb3c6a 113 * @return 0 on success, negative number on failure
phonemacro 9:315236fb3c6a 114 */
phonemacro 9:315236fb3c6a 115 int read_cfg_reg(uint8_t *value);
phonemacro 9:315236fb3c6a 116
phonemacro 9:315236fb3c6a 117 /**
phonemacro 9:315236fb3c6a 118 * @brief Read register of device at slave address
phonemacro 9:315236fb3c6a 119 * @param[out] value - Read data on success
phonemacro 8:b2d4c71268aa 120 * @param reg - Register address
phonemacro 8:b2d4c71268aa 121 * @return 0 on success, negative number on failure
phonemacro 8:b2d4c71268aa 122 */
phonemacro 10:03645de9c017 123 int read_reg(int16_t *value, char reg);
phonemacro 8:b2d4c71268aa 124
phonemacro 8:b2d4c71268aa 125 /**
phonemacro 8:b2d4c71268aa 126 * @brief Reads the temperature registers
phonemacro 8:b2d4c71268aa 127 * @param reg - the address of the temperature register
phonemacro 8:b2d4c71268aa 128 * @return temperature in degrees Celsius
phonemacro 8:b2d4c71268aa 129 */
phonemacro 8:b2d4c71268aa 130 float read_reg_as_temperature(uint8_t reg);
phonemacro 8:b2d4c71268aa 131
phonemacro 8:b2d4c71268aa 132 /**
phonemacro 8:b2d4c71268aa 133 * @brief Writes to the configuration register
phonemacro 8:b2d4c71268aa 134 * @param cfg - configurate word
phonemacro 8:b2d4c71268aa 135 * @return 0 on success, negative number on failure
phonemacro 8:b2d4c71268aa 136 */
phonemacro 8:b2d4c71268aa 137 int write_cfg(uint16_t cfg);
phonemacro 8:b2d4c71268aa 138
phonemacro 8:b2d4c71268aa 139 /**
phonemacro 8:b2d4c71268aa 140 * @brief Writes to the THYST register
phonemacro 8:b2d4c71268aa 141 * @param temperature - the temperature in Celsius degrees
phonemacro 8:b2d4c71268aa 142 * @return 0 on success, negative number on failure
phonemacro 8:b2d4c71268aa 143 */
phonemacro 8:b2d4c71268aa 144 int write_trip_low(float temperature);
phonemacro 8:b2d4c71268aa 145
phonemacro 8:b2d4c71268aa 146 /**
phonemacro 8:b2d4c71268aa 147 * @brief Writes to the TOS register
phonemacro 8:b2d4c71268aa 148 * @param temperature - the temperature in Celsius degrees
phonemacro 8:b2d4c71268aa 149 * @return 0 on success, negative number on failure
phonemacro 8:b2d4c71268aa 150 */
phonemacro 8:b2d4c71268aa 151 int write_trip_high(float temperature);
phonemacro 8:b2d4c71268aa 152
phonemacro 8:b2d4c71268aa 153 /**
phonemacro 8:b2d4c71268aa 154 * @brief Converts Celsius degrees to Fahrenheit
phonemacro 8:b2d4c71268aa 155 * @param temp_c - the temperature in Celsius degrees
phonemacro 8:b2d4c71268aa 156 * @return temperature in Celsius degrees
phonemacro 8:b2d4c71268aa 157 */
phonemacro 8:b2d4c71268aa 158 float celsius_to_fahrenheit(float temp_c);
phonemacro 8:b2d4c71268aa 159
phonemacro 8:b2d4c71268aa 160 protected:
phonemacro 8:b2d4c71268aa 161 /**
phonemacro 8:b2d4c71268aa 162 * @brief Write a value to a register
phonemacro 8:b2d4c71268aa 163 * @param value - value to write to the register
phonemacro 8:b2d4c71268aa 164 * @param reg - register address
phonemacro 8:b2d4c71268aa 165 * @return 0 on success, negative number on failure
phonemacro 8:b2d4c71268aa 166 */
phonemacro 10:03645de9c017 167 int write_reg(int16_t value, char reg);
phonemacro 8:b2d4c71268aa 168
phonemacro 9:315236fb3c6a 169 /**
phonemacro 9:315236fb3c6a 170 * @brief Write a value to a register
phonemacro 9:315236fb3c6a 171 * @param value - value to write to the register
phonemacro 9:315236fb3c6a 172 * @param reg - register address
phonemacro 9:315236fb3c6a 173 * @return 0 on success, negative number on failure
phonemacro 9:315236fb3c6a 174 */
phonemacro 9:315236fb3c6a 175 int write_reg_one_byte(uint8_t value, char reg);
phonemacro 8:b2d4c71268aa 176 private:
phonemacro 8:b2d4c71268aa 177 /** @var m_i2c
phonemacro 8:b2d4c71268aa 178 * @brief I2C object
phonemacro 8:b2d4c71268aa 179 */
phonemacro 8:b2d4c71268aa 180 I2C &m_i2c;
phonemacro 8:b2d4c71268aa 181 /** @var m_write_address, m_read_address
phonemacro 8:b2d4c71268aa 182 * @brief I2C address
phonemacro 8:b2d4c71268aa 183 */
phonemacro 8:b2d4c71268aa 184 uint8_t m_write_address, m_read_address;
phonemacro 8:b2d4c71268aa 185 };
phonemacro 8:b2d4c71268aa 186
phonemacro 8:b2d4c71268aa 187 #endif/* DS1775_CPP_H */