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
max31725_cpp.h@24:b4fdbbe79036, 2019-04-17 (annotated)
- Committer:
- phonemacro
- Date:
- Wed Apr 17 21:28:29 2019 +0000
- Revision:
- 24:b4fdbbe79036
- Parent:
- 22:692515ac2bb7
update comment
Who changed what in which revision?
User | Revision | Line number | New 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 | 21:bb7ba5566a62 | 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 | 21:bb7ba5566a62 | 50 | * Accuracy is +-0.5°C from -40°C to +105°C (-40°F to +221°). |
phonemacro | 21:bb7ba5566a62 | 51 | * Operating temperature: -55°C to +150°C (-67°F to +302°). |
phonemacro | 21:bb7ba5566a62 | 52 | * VDD: 2.5V to 3.7V. |
phonemacro | 20:c9805b01e814 | 53 | * |
phonemacro | 20:c9805b01e814 | 54 | * @code |
phonemacro | 20:c9805b01e814 | 55 | * #include "mbed.h" |
phonemacro | 20:c9805b01e814 | 56 | * #include "max32630fthr.h" |
phonemacro | 20:c9805b01e814 | 57 | * #include "max31725.h" |
phonemacro | 20:c9805b01e814 | 58 | * #include "USBSerial.h" |
phonemacro | 20:c9805b01e814 | 59 | * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
phonemacro | 20:c9805b01e814 | 60 | * I2C i2cBus(P3_4, P3_5); |
phonemacro | 20:c9805b01e814 | 61 | * int main() |
phonemacro | 20:c9805b01e814 | 62 | * { |
phonemacro | 20:c9805b01e814 | 63 | * float temperature; |
phonemacro | 20:c9805b01e814 | 64 | * DigitalOut rLED(LED1, LED_OFF); |
phonemacro | 20:c9805b01e814 | 65 | * DigitalOut gLED(LED2, LED_OFF); |
phonemacro | 20:c9805b01e814 | 66 | * DigitalOut bLED(LED3, LED_OFF); |
phonemacro | 20:c9805b01e814 | 67 | * gLED = LED_ON; |
phonemacro | 22:692515ac2bb7 | 68 | * MAX31725 temp_sensor(i2cBus, MAX31725_I2C_SLAVE_ADR_00); |
phonemacro | 20:c9805b01e814 | 69 | * i2cBus.frequency(400000); |
phonemacro | 20:c9805b01e814 | 70 | * temperature = |
phonemacro | 20:c9805b01e814 | 71 | * temp_sensor.read_reg_as_temperature(MAX31725_REG_TEMPERATURE); |
phonemacro | 20:c9805b01e814 | 72 | * printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", |
phonemacro | 20:c9805b01e814 | 73 | * temperature, temp_sensor.celsius_to_fahrenheit(temperature)); |
phonemacro | 20:c9805b01e814 | 74 | * } |
phonemacro | 20:c9805b01e814 | 75 | * @endcode |
phonemacro | 20:c9805b01e814 | 76 | */ |
phonemacro | 20:c9805b01e814 | 77 | |
phonemacro | 20:c9805b01e814 | 78 | class MAX31725 |
phonemacro | 20:c9805b01e814 | 79 | { |
phonemacro | 20:c9805b01e814 | 80 | public: |
phonemacro | 20:c9805b01e814 | 81 | |
phonemacro | 20:c9805b01e814 | 82 | /**********************************************************//** |
phonemacro | 20:c9805b01e814 | 83 | * @brief Constructor for MAX31725 Class. |
phonemacro | 20:c9805b01e814 | 84 | * |
phonemacro | 20:c9805b01e814 | 85 | * @details Allows user to use existing I2C object |
phonemacro | 20:c9805b01e814 | 86 | * |
phonemacro | 20:c9805b01e814 | 87 | * On Entry: |
phonemacro | 20:c9805b01e814 | 88 | * @param[in] i2c_bus - pointer to existing I2C object |
phonemacro | 20:c9805b01e814 | 89 | * @param[in] i2c_adrs - 7-bit slave address of MAX31725 |
phonemacro | 20:c9805b01e814 | 90 | * |
phonemacro | 20:c9805b01e814 | 91 | * On Exit: |
phonemacro | 20:c9805b01e814 | 92 | * |
phonemacro | 20:c9805b01e814 | 93 | * @return None |
phonemacro | 20:c9805b01e814 | 94 | **************************************************************/ |
phonemacro | 20:c9805b01e814 | 95 | MAX31725(I2C &i2c_bus, uint8_t slave_address); |
phonemacro | 20:c9805b01e814 | 96 | |
phonemacro | 20:c9805b01e814 | 97 | /**********************************************************//** |
phonemacro | 20:c9805b01e814 | 98 | * @brief Default destructor for MAX31725 Class. |
phonemacro | 20:c9805b01e814 | 99 | * |
phonemacro | 20:c9805b01e814 | 100 | * @details Destroys I2C object if owner |
phonemacro | 20:c9805b01e814 | 101 | * |
phonemacro | 20:c9805b01e814 | 102 | * On Entry: |
phonemacro | 20:c9805b01e814 | 103 | * |
phonemacro | 20:c9805b01e814 | 104 | * On Exit: |
phonemacro | 20:c9805b01e814 | 105 | * |
phonemacro | 20:c9805b01e814 | 106 | * @return None |
phonemacro | 20:c9805b01e814 | 107 | **************************************************************/ |
phonemacro | 20:c9805b01e814 | 108 | ~MAX31725(); |
phonemacro | 20:c9805b01e814 | 109 | |
phonemacro | 20:c9805b01e814 | 110 | /** |
phonemacro | 20:c9805b01e814 | 111 | * @brief Read register of device at slave address |
phonemacro | 20:c9805b01e814 | 112 | * @param[out] value - Read data on success |
phonemacro | 20:c9805b01e814 | 113 | * @return 0 on success, negative number on failure |
phonemacro | 20:c9805b01e814 | 114 | */ |
phonemacro | 20:c9805b01e814 | 115 | int read_cfg_reg(uint8_t *value); |
phonemacro | 20:c9805b01e814 | 116 | |
phonemacro | 20:c9805b01e814 | 117 | /** |
phonemacro | 20:c9805b01e814 | 118 | * @brief Read register of device at slave address |
phonemacro | 20:c9805b01e814 | 119 | * @param[out] value - Read data on success |
phonemacro | 20:c9805b01e814 | 120 | * @param reg - Register address |
phonemacro | 20:c9805b01e814 | 121 | * @return 0 on success, negative number on failure |
phonemacro | 20:c9805b01e814 | 122 | */ |
phonemacro | 20:c9805b01e814 | 123 | int read_reg16(int16_t *value, char reg); |
phonemacro | 20:c9805b01e814 | 124 | |
phonemacro | 20:c9805b01e814 | 125 | /** |
phonemacro | 20:c9805b01e814 | 126 | * @brief Reads the temperature registers |
phonemacro | 20:c9805b01e814 | 127 | * @param reg - the address of the temperature register |
phonemacro | 20:c9805b01e814 | 128 | * @return temperature in degrees Celsius |
phonemacro | 20:c9805b01e814 | 129 | */ |
phonemacro | 20:c9805b01e814 | 130 | float read_reg_as_temperature(uint8_t reg); |
phonemacro | 20:c9805b01e814 | 131 | |
phonemacro | 20:c9805b01e814 | 132 | /** |
phonemacro | 20:c9805b01e814 | 133 | * @brief Writes to the configuration register |
phonemacro | 20:c9805b01e814 | 134 | * @param cfg - configurate word |
phonemacro | 20:c9805b01e814 | 135 | * @return 0 on success, negative number on failure |
phonemacro | 20:c9805b01e814 | 136 | */ |
phonemacro | 20:c9805b01e814 | 137 | int write_cfg_reg(uint8_t cfg); |
phonemacro | 20:c9805b01e814 | 138 | |
phonemacro | 20:c9805b01e814 | 139 | /** |
phonemacro | 20:c9805b01e814 | 140 | * @brief Writes to the THYST register |
phonemacro | 20:c9805b01e814 | 141 | * @param temperature - the temperature in Celsius degrees |
phonemacro | 20:c9805b01e814 | 142 | * @return 0 on success, negative number on failure |
phonemacro | 20:c9805b01e814 | 143 | */ |
phonemacro | 20:c9805b01e814 | 144 | int write_trip_low_thyst(float temperature); |
phonemacro | 20:c9805b01e814 | 145 | |
phonemacro | 20:c9805b01e814 | 146 | /** |
phonemacro | 20:c9805b01e814 | 147 | * @brief Writes to the TOS register |
phonemacro | 20:c9805b01e814 | 148 | * @param temperature - the temperature in Celsius degrees |
phonemacro | 20:c9805b01e814 | 149 | * @return 0 on success, negative number on failure |
phonemacro | 20:c9805b01e814 | 150 | */ |
phonemacro | 20:c9805b01e814 | 151 | int write_trip_high_tos(float temperature); |
phonemacro | 20:c9805b01e814 | 152 | |
phonemacro | 20:c9805b01e814 | 153 | /** |
phonemacro | 20:c9805b01e814 | 154 | * @brief Converts Celsius degrees to Fahrenheit |
phonemacro | 20:c9805b01e814 | 155 | * @param temp_c - the temperature in Celsius degrees |
phonemacro | 20:c9805b01e814 | 156 | * @return temperature in Celsius degrees |
phonemacro | 20:c9805b01e814 | 157 | */ |
phonemacro | 20:c9805b01e814 | 158 | float celsius_to_fahrenheit(float temp_c); |
phonemacro | 20:c9805b01e814 | 159 | |
phonemacro | 20:c9805b01e814 | 160 | protected: |
phonemacro | 20:c9805b01e814 | 161 | /** |
phonemacro | 20:c9805b01e814 | 162 | * @brief Write a value to a register |
phonemacro | 20:c9805b01e814 | 163 | * @param value - value to write to the register |
phonemacro | 20:c9805b01e814 | 164 | * @param reg - register address |
phonemacro | 20:c9805b01e814 | 165 | * @return 0 on success, negative number on failure |
phonemacro | 20:c9805b01e814 | 166 | */ |
phonemacro | 20:c9805b01e814 | 167 | int write_reg16(int16_t value, char reg); |
phonemacro | 20:c9805b01e814 | 168 | |
phonemacro | 20:c9805b01e814 | 169 | private: |
phonemacro | 20:c9805b01e814 | 170 | /** @var m_i2c |
phonemacro | 20:c9805b01e814 | 171 | * @brief I2C object |
phonemacro | 20:c9805b01e814 | 172 | */ |
phonemacro | 20:c9805b01e814 | 173 | I2C &m_i2c; |
phonemacro | 20:c9805b01e814 | 174 | /** @var m_write_address, m_read_address |
phonemacro | 20:c9805b01e814 | 175 | * @brief I2C address |
phonemacro | 20:c9805b01e814 | 176 | */ |
phonemacro | 20:c9805b01e814 | 177 | uint8_t m_write_address, m_read_address; |
phonemacro | 20:c9805b01e814 | 178 | /** @var m_extended_format |
phonemacro | 20:c9805b01e814 | 179 | * @brief Extended format, add 64°C to the temperature reading |
phonemacro | 20:c9805b01e814 | 180 | */ |
phonemacro | 20:c9805b01e814 | 181 | uint32_t max31725_extended_format; |
phonemacro | 20:c9805b01e814 | 182 | |
phonemacro | 20:c9805b01e814 | 183 | }; |
phonemacro | 20:c9805b01e814 | 184 | |
phonemacro | 24:b4fdbbe79036 | 185 | #endif/* MAX31725_CPP_H */ |