Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAX31723_Thermostat_Thermometer_Sensor
max31723.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 MAX31723.h 00033 ******************************************************************************* 00034 */ 00035 #ifndef MAX31723_H 00036 #define MAX31723_H 00037 00038 #include "mbed.h" 00039 00040 #define MAX31723_NO_ERROR 0 00041 #define MAX31723_ERROR -1 00042 00043 #define MAX31723_WRITE_MASK 0x80 00044 00045 #define MAX31723_REG_CFG 0x00 00046 #define MAX31723_REG_TEMP_LSB 0x01 00047 #define MAX31723_REG_TEMP_MSB 0x02 00048 #define MAX31723_REG_TRIP_HI_LSB 0x03 00049 #define MAX31723_REG_TRIP_HI_MSB 0x04 00050 #define MAX31723_REG_TRIP_LO_LSB 0x05 00051 #define MAX31723_REG_TRIP_LO_MSB 0x06 00052 #define MAX31723_REG_MAX MAX31723_REG_TRIP_LO_MSB 00053 00054 /* Configuration, Status masks */ 00055 #define MAX31723_CFG_CONTINUOUS 0x00 00056 #define MAX31723_CFG_STANDBY 0x01 00057 00058 #define MAX31723_CFG_RESOLUTION_9BIT 0x00 00059 #define MAX31723_CFG_RESOLUTION_10BIT 0x02 00060 #define MAX31723_CFG_RESOLUTION_11BIT 0x04 00061 #define MAX31723_CFG_RESOLUTION_12BIT 0x06 00062 #define MAX31723_CFG_RESOLUTION_MASK 0x06 00063 00064 #define MAX31723_CFG_TM_MODE_INTERRUPT 0x08 00065 #define MAX31723_CFG_1SHOT 0x10 00066 #define MAX31723_CFG_NVB_NVRAM_BUSY 0x20 00067 #define MAX31723_CFG_MEMW_CFG_WR_EEPROM 0x40 00068 00069 #define MAX31723_CONV_TIME_MSEC_9BIT 0.025 00070 #define MAX31723_CONV_TIME_MSEC_10BIT 0.050 00071 #define MAX31723_CONV_TIME_MSEC_11BIT 0.100 00072 #define MAX31723_CONV_TIME_MSEC_12BIT 0.200 00073 00074 #define MAX31723_NVRAM_WRITE_TIME_MSEC 0.015 00075 00076 #define MAX31723_CF_LSB (0.00390625f) 00077 00078 /** 00079 * @brief 9-bit to 12bit device temperature sensor with digital-to-analog converters (DACs) 00080 * for the MAX31723. 00081 * @version 1.0000.0004 00082 * 00083 * @details The MAX31722/MAX31723 provides device temperature readings 00084 * for thermostats and thermometers. Communications may be either SPI or 00085 * 3-wire. There are two operating modes available: comparator or interrupt. 00086 * Temperature limits may be stored in NVRAM so that the TOUT_N pin can be 00087 * triggered when the limits are exceeded while in the comparator mode. 00088 * Typically applications are for temperature sensitive systems. 00089 * 00090 * @code 00091 * #include "mbed.h" 00092 * #include "max32630fthr.h" 00093 * #include "max31723.h" 00094 * #include "USBSerial.h" 00095 * 00096 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_1V8); 00097 * 00098 * DigitalOut gLED(LED2); 00099 * 00100 * DigitalOut selectPin(P3_0); 00101 * SPI spi(P5_1, P5_2, P5_0); 00102 * 00103 * int main() 00104 * { 00105 * int i, ret; 00106 * float temperature; 00107 * DigitalOut gLED(LED2, LED_OFF); 00108 * printf("MAX31723 Temperature Sensor example code.\r\n"); 00109 * printf("\r\n"); 00110 * 00111 * gLED = LED_ON; 00112 * 00113 * MAX31723 temp_sensor(spi, selectPin); 00114 * spi.format(8,3); 00115 * spi.frequency(5000000); 00116 * ret = temp_sensor.perform_one_shot_int(MAX31723_CFG_RESOLUTION_12BIT); 00117 * 00118 * for (i = 0; i < 5; i++) { 00119 * ret = temp_sensor.perform_one_shot_int(MAX31723_CFG_RESOLUTION_12BIT); 00120 * wait(MAX31723_CONV_TIME_MSEC_12BIT); 00121 * temperature = temp_sensor.read_temperature(); 00122 * printf("Temperature = %4.4f Celsius, %4.4f Fahrenheit\r\n", 00123 * temperature, temp_sensor.celsius_to_fahrenheit(temperature)); 00124 * wait(2); 00125 * } 00126 * printf("Configuration Register = 0x%02Xh \r\n", temp_sensor.read_cfg()); 00127 * } 00128 * 00129 */ 00130 00131 class MAX31723{ 00132 public: 00133 00134 /************************************************************** 00135 * @brief Constructor for MAX31723 Class. 00136 * 00137 * @details Requires an existing SPI object as well as a DigitalOut object. 00138 * The DigitalOut object is used for a chip enable signal 00139 * 00140 * On Entry: 00141 * @param[in] spi - pointer to existing SPI object 00142 * @param[in] ce_pin - pointer to a DigitalOut pin object 00143 * 00144 * On Exit: 00145 * 00146 * @return None 00147 *************************************************************** 00148 */ 00149 MAX31723(SPI &spi, DigitalOut &ce_pin); 00150 00151 /** 00152 * @brief Reads the register 00153 * @param &val - register value 00154 * @param reg - address of the register 00155 * @return 0 on success, negative number on failure 00156 */ 00157 int read_reg(uint8_t &val, uint8_t reg); 00158 00159 /** 00160 * @brief Reads the configuration register 00161 * @return value of the configuration register 00162 */ 00163 uint8_t read_cfg(); 00164 00165 /** 00166 * @brief Reads the temperature register 00167 * @return temperature in degrees Celsius 00168 */ 00169 float read_temperature(void); 00170 00171 /** 00172 * @brief Reads the trip low temperature register 00173 * @return trip low temperature in degrees Celsius 00174 */ 00175 float read_trip_low(void); 00176 00177 /** 00178 * @brief Reads the trip high temperature register 00179 * @return trip high temperature in degrees Celsius 00180 */ 00181 float read_trip_high(void); 00182 00183 /** 00184 * @brief Writes to the configuration register 00185 * @param val - the configuration value 00186 * @return 0 on success, negative number on failure 00187 */ 00188 int write_cfg(uint8_t val); 00189 00190 /** 00191 * @brief Writes to the Tlow register (the write takes 30 msec) 00192 * @param temperature - the temperature in Celsius degrees 00193 * @return 0 on success, negative number on failure 00194 */ 00195 int write_trip_low(float temperature); 00196 00197 /** 00198 * @brief Writes to the Thigh register (the write takes 30 msec) 00199 * @param temperature - the temperature in Celsius degrees 00200 * @return 0 on success, negative number on failure 00201 */ 00202 int write_trip_high(float temperature); 00203 00204 /** 00205 * @brief Reads the temperature registers 00206 * @param reg - the address of the temperature register 00207 * @return temprature in degrees Celsius 00208 */ 00209 float read_reg_as_temperature(uint8_t reg); 00210 00211 /** 00212 * @brief Configures the device to perform a one-shot temperature reading 00213 * and places the device in standby mode, interrupt mode. 00214 * @param resolution - the resolution of the calculation is set to this 00215 * @return 0 on success, negative number on failure 00216 */ 00217 int perform_one_shot_int(uint8_t resolution); 00218 00219 /** 00220 * @brief Configures the device to perform a one-shot temperature reading 00221 * and places the device in standby mode, comparator mode. 00222 * @param resolution - the resolution of the calculation is set to this 00223 * @return 0 on success, negative number on failure 00224 */ 00225 int perform_one_shot_comparator(uint8_t resolution); 00226 00227 /** 00228 * @brief Converts Celcius degrees to Fahrenheit 00229 * @param temp_c - the temperature in Celsius degrees 00230 * @return 0 on success, negative number on failure 00231 */ 00232 float celsius_to_fahrenheit(float temp_c); 00233 00234 /************************************************************ 00235 * @brief Default destructor for MAX31723 Class. 00236 * 00237 * @details Destroys SPI object if owner 00238 * 00239 * On Entry: 00240 * 00241 * On Exit: 00242 * 00243 * @return None 00244 ************************************************************* 00245 */ 00246 ~MAX31723(); 00247 00248 protected: 00249 /** 00250 * @brief Configures the device to perform a one-shot temperature reading 00251 * and places the device in standby mode, interrupt mode. 00252 * @param resolution - the resolution of the calculation is set to this 00253 * @return 0 on success, negative number on failure 00254 */ 00255 int perform_one_shot(uint8_t resolution, uint8_t interrupt_mode); 00256 00257 private: 00258 /** 00259 * @brief Write a value to a register 00260 * @param val - 8-bit value to write to the register 00261 * @param reg - register address 00262 * @return 0 on success, negative number on failure 00263 */ 00264 int write_reg(uint8_t val, uint8_t reg); 00265 00266 /** @var m_spi 00267 * @brief SPI object 00268 */ 00269 SPI &m_spi; 00270 00271 /** @var m_chip_enable 00272 * @brief Chip Enable pin 00273 */ 00274 /* chip enable pin */ 00275 00276 DigitalOut &m_chip_enable; 00277 }; 00278 00279 #endif
Generated on Tue Jul 12 2022 20:30:15 by
1.7.2