Maxim Integrated / MAX31723_Digital_Temperature_Sensor

Dependents:   MAX31723_Thermostat_Thermometer_Sensor

Committer:
phonemacro
Date:
Sun Jan 27 07:26:37 2019 +0000
Revision:
2:7a20e65da621
Parent:
0:4a3d6ac5042d
Child:
3:f39791139435
Correct configuration register not being updating.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:4a3d6ac5042d 1 /*******************************************************************************
phonemacro 0:4a3d6ac5042d 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:4a3d6ac5042d 3 *
phonemacro 0:4a3d6ac5042d 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:4a3d6ac5042d 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:4a3d6ac5042d 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:4a3d6ac5042d 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:4a3d6ac5042d 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:4a3d6ac5042d 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:4a3d6ac5042d 10 *
phonemacro 0:4a3d6ac5042d 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:4a3d6ac5042d 12 * in all copies or substantial portions of the Software.
phonemacro 0:4a3d6ac5042d 13 *
phonemacro 0:4a3d6ac5042d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:4a3d6ac5042d 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:4a3d6ac5042d 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:4a3d6ac5042d 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:4a3d6ac5042d 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:4a3d6ac5042d 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:4a3d6ac5042d 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:4a3d6ac5042d 21 *
phonemacro 0:4a3d6ac5042d 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:4a3d6ac5042d 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:4a3d6ac5042d 24 * Products, Inc. Branding Policy.
phonemacro 0:4a3d6ac5042d 25 *
phonemacro 0:4a3d6ac5042d 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:4a3d6ac5042d 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:4a3d6ac5042d 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:4a3d6ac5042d 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:4a3d6ac5042d 30 * ownership rights.
phonemacro 0:4a3d6ac5042d 31 *******************************************************************************
phonemacro 0:4a3d6ac5042d 32 * @file MAX31723.h
phonemacro 0:4a3d6ac5042d 33 *******************************************************************************
phonemacro 0:4a3d6ac5042d 34 */
phonemacro 0:4a3d6ac5042d 35 #ifndef MAX31723_H
phonemacro 0:4a3d6ac5042d 36 #define MAX31723_H
phonemacro 0:4a3d6ac5042d 37
phonemacro 0:4a3d6ac5042d 38 #include "mbed.h"
phonemacro 0:4a3d6ac5042d 39
phonemacro 0:4a3d6ac5042d 40 #define MAX31723_NO_ERROR 0
phonemacro 0:4a3d6ac5042d 41 #define MAX31723_ERROR -1
phonemacro 0:4a3d6ac5042d 42
phonemacro 0:4a3d6ac5042d 43 #define MAX31723_WRITE_MASK 0x80
phonemacro 0:4a3d6ac5042d 44
phonemacro 0:4a3d6ac5042d 45 #define MAX31723_REG_CFG 0x00
phonemacro 0:4a3d6ac5042d 46 #define MAX31723_REG_TEMP_LSB 0x01
phonemacro 0:4a3d6ac5042d 47 #define MAX31723_REG_TEMP_MSB 0x02
phonemacro 0:4a3d6ac5042d 48
phonemacro 0:4a3d6ac5042d 49 /* Configuration, Status masks */
phonemacro 0:4a3d6ac5042d 50 #define MAX31723_CFG_CONTINUOUS 0x00
phonemacro 0:4a3d6ac5042d 51 #define MAX31723_CFG_STANDBY 0x01
phonemacro 0:4a3d6ac5042d 52
phonemacro 0:4a3d6ac5042d 53 #define MAX31723_CFG_RESOLUTION_9BIT 0x00
phonemacro 0:4a3d6ac5042d 54 #define MAX31723_CFG_RESOLUTION_10BIT 0x02
phonemacro 0:4a3d6ac5042d 55 #define MAX31723_CFG_RESOLUTION_11BIT 0x04
phonemacro 0:4a3d6ac5042d 56 #define MAX31723_CFG_RESOLUTION_12BIT 0x06
phonemacro 0:4a3d6ac5042d 57
phonemacro 0:4a3d6ac5042d 58 #define MAX31723_CFG_TM_MODE_INTERRUPT 0x08
phonemacro 0:4a3d6ac5042d 59 #define MAX31723_CFG_1SHOT 0x10
phonemacro 0:4a3d6ac5042d 60 #define MAX31723_CFG_NVB_NVRAM_BUSY 0x20
phonemacro 0:4a3d6ac5042d 61 #define MAX31723_CFG_MEMW_CFG_WR_EEPROM 0x40
phonemacro 0:4a3d6ac5042d 62
phonemacro 0:4a3d6ac5042d 63 #define MAX31723_CONV_TIME_MSEC_9BIT .025
phonemacro 0:4a3d6ac5042d 64 #define MAX31723_CONV_TIME_MSEC_10BIT .050
phonemacro 0:4a3d6ac5042d 65 #define MAX31723_CONV_TIME_MSEC_11BIT .100
phonemacro 0:4a3d6ac5042d 66 #define MAX31723_CONV_TIME_MSEC_12BIT .200
phonemacro 0:4a3d6ac5042d 67
phonemacro 0:4a3d6ac5042d 68 /**
phonemacro 0:4a3d6ac5042d 69 * @brief 9-bit to 12bit device temperature sensor with digital-to-analog converters (DACs)
phonemacro 0:4a3d6ac5042d 70 * for the MAX31723, MAX5214.
phonemacro 2:7a20e65da621 71 * @version 1.0000.0001
phonemacro 0:4a3d6ac5042d 72 *
phonemacro 0:4a3d6ac5042d 73 * @details The MAX31722/MAX31723 provides device temperature readings
phonemacro 0:4a3d6ac5042d 74 * for thermostats and thermometers. Communications may be either SPI or
phonemacro 0:4a3d6ac5042d 75 * 3-wire. There are two operating modes available: comparator or interrupt.
phonemacro 0:4a3d6ac5042d 76 * Temperature limits may be stored in NVRAM so that the TOUT_N pin can be
phonemacro 0:4a3d6ac5042d 77 * triggered when the limits are exceeded while in the comparator mode.
phonemacro 0:4a3d6ac5042d 78 * Typically applications are for temperature sensitive systems.
phonemacro 0:4a3d6ac5042d 79 *
phonemacro 0:4a3d6ac5042d 80 */
phonemacro 0:4a3d6ac5042d 81
phonemacro 0:4a3d6ac5042d 82 class MAX31723{
phonemacro 0:4a3d6ac5042d 83 public:
phonemacro 0:4a3d6ac5042d 84
phonemacro 0:4a3d6ac5042d 85 /**************************************************************
phonemacro 0:4a3d6ac5042d 86 * @brief Constructor for MAX31723 Class.
phonemacro 0:4a3d6ac5042d 87 *
phonemacro 0:4a3d6ac5042d 88 * @details Requires an existing SPI object as well as a DigitalOut object.
phonemacro 0:4a3d6ac5042d 89 * The DigitalOut object is used for a chip enable signal
phonemacro 0:4a3d6ac5042d 90 *
phonemacro 0:4a3d6ac5042d 91 * On Entry:
phonemacro 0:4a3d6ac5042d 92 * @param[in] spi - pointer to existing SPI object
phonemacro 0:4a3d6ac5042d 93 * @param[in] ce_pin - pointer to a DigitalOut pin object
phonemacro 0:4a3d6ac5042d 94 * @param[in] ic_variant - which type of MAX521x is used
phonemacro 0:4a3d6ac5042d 95 *
phonemacro 0:4a3d6ac5042d 96 * On Exit:
phonemacro 0:4a3d6ac5042d 97 *
phonemacro 0:4a3d6ac5042d 98 * @return None
phonemacro 0:4a3d6ac5042d 99 ***************************************************************
phonemacro 0:4a3d6ac5042d 100 */
phonemacro 0:4a3d6ac5042d 101 MAX31723(SPI &spi, DigitalOut &ce_pin);
phonemacro 0:4a3d6ac5042d 102
phonemacro 0:4a3d6ac5042d 103 /**
phonemacro 0:4a3d6ac5042d 104 * @brief Write a value to a register
phonemacro 0:4a3d6ac5042d 105 * @param val - 8-bit value to write to the register
phonemacro 0:4a3d6ac5042d 106 * @param reg - register address
phonemacro 0:4a3d6ac5042d 107 * @return 0 on success, negative number on failure
phonemacro 0:4a3d6ac5042d 108 */
phonemacro 0:4a3d6ac5042d 109 int write_reg(uint8_t val, uint8_t reg);
phonemacro 0:4a3d6ac5042d 110
phonemacro 0:4a3d6ac5042d 111 /**
phonemacro 0:4a3d6ac5042d 112 * @brief Read a value from a register
phonemacro 0:4a3d6ac5042d 113 * @param val - 8-bit value read from the register
phonemacro 0:4a3d6ac5042d 114 * @param reg - register address
phonemacro 0:4a3d6ac5042d 115 * @return 0 on success, negative number on failure
phonemacro 0:4a3d6ac5042d 116 */
phonemacro 0:4a3d6ac5042d 117 int read_reg(uint8_t &val, uint8_t reg);
phonemacro 0:4a3d6ac5042d 118
phonemacro 0:4a3d6ac5042d 119 /**
phonemacro 0:4a3d6ac5042d 120 * @brief Write a value to a register
phonemacro 0:4a3d6ac5042d 121 * @param val - 8-bit value to write to the register
phonemacro 0:4a3d6ac5042d 122 * @param reg - register address
phonemacro 0:4a3d6ac5042d 123 * @return temprature in degrees celsius
phonemacro 0:4a3d6ac5042d 124 */
phonemacro 0:4a3d6ac5042d 125 float read_temp();
phonemacro 0:4a3d6ac5042d 126
phonemacro 0:4a3d6ac5042d 127 /**
phonemacro 0:4a3d6ac5042d 128 * @brief Configures the device to perform a one-shot temperature reading
phonemacro 2:7a20e65da621 129 * and places the device in standby mode, interrupt mode.
phonemacro 0:4a3d6ac5042d 130 * @param resolution - the resolution of the calculation is set to this
phonemacro 0:4a3d6ac5042d 131 * @return 0 on success, negative number on failure
phonemacro 0:4a3d6ac5042d 132 */
phonemacro 2:7a20e65da621 133 int perform_one_shot_int(uint8_t resolution);
phonemacro 0:4a3d6ac5042d 134
phonemacro 0:4a3d6ac5042d 135 /**
phonemacro 0:4a3d6ac5042d 136 * @brief Converts Celcius degrees to Fahrenheit
phonemacro 0:4a3d6ac5042d 137 * @param temp_c - the temperature in Celsius degrees
phonemacro 0:4a3d6ac5042d 138 * @return 0 on success, negative number on failure
phonemacro 0:4a3d6ac5042d 139 */
phonemacro 0:4a3d6ac5042d 140 float celsius_to_fahrenheit(float temp_c);
phonemacro 0:4a3d6ac5042d 141
phonemacro 0:4a3d6ac5042d 142
phonemacro 0:4a3d6ac5042d 143 /************************************************************
phonemacro 0:4a3d6ac5042d 144 * @brief Default destructor for MAX31723 Class.
phonemacro 0:4a3d6ac5042d 145 *
phonemacro 0:4a3d6ac5042d 146 * @details Destroys SPI object if owner
phonemacro 0:4a3d6ac5042d 147 *
phonemacro 0:4a3d6ac5042d 148 * On Entry:
phonemacro 0:4a3d6ac5042d 149 *
phonemacro 0:4a3d6ac5042d 150 * On Exit:
phonemacro 0:4a3d6ac5042d 151 *
phonemacro 0:4a3d6ac5042d 152 * @return None
phonemacro 0:4a3d6ac5042d 153 *************************************************************
phonemacro 0:4a3d6ac5042d 154 */
phonemacro 0:4a3d6ac5042d 155 ~MAX31723();
phonemacro 0:4a3d6ac5042d 156 private:
phonemacro 0:4a3d6ac5042d 157 // SPI object
phonemacro 0:4a3d6ac5042d 158 SPI &m_spi;
phonemacro 0:4a3d6ac5042d 159 // chip enable pin
phonemacro 0:4a3d6ac5042d 160 DigitalOut &m_chip_enable;
phonemacro 0:4a3d6ac5042d 161 };
phonemacro 0:4a3d6ac5042d 162
phonemacro 0:4a3d6ac5042d 163 #endif