C, C++ source code driver software for the Maxim Integrated MAX31725, MAX31726 thermostat : The MAX31725, MAX31726 temperature sensors provides temperature measurements with an accuracy of up to +-0.5°C. Extended format allows for high temperature readings up to 150°C. The MAX31725 can operate in a low powered mode by utilizing the shutdown and one-shot mode. MAX31725  supports two-wire serial, I2C bus communications in an 8-pin TQDFN 3x3 mm package.

Dependents:   MAX31725_High_Temperature_Accurate_IC

Committer:
phonemacro
Date:
Tue Apr 09 07:00:32 2019 +0000
Revision:
20:c9805b01e814
Child:
21:bb7ba5566a62
Initial Commit

Who changed what in which revision?

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