Maxim Integrated / Mbed 2 deprecated MAX31856_example_program

Dependencies:   MAX31856 mbed

Fork of MAX31856_example_program by Central Applications - Mbed Code repo

Committer:
DevinAlexander
Date:
Mon Jul 31 07:41:26 2017 +0000
Revision:
4:589401418bf0
Parent:
3:a99a4367c909
Child:
5:3a51bb306f41
Doxygen info re-added in attempt to finalize style of the header

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DevinAlexander 4:589401418bf0 1 /*******************************************************************************
DevinAlexander 4:589401418bf0 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
DevinAlexander 4:589401418bf0 3 *
DevinAlexander 4:589401418bf0 4 * Permission is hereby granted, free of charge, to any person obtaining a
DevinAlexander 4:589401418bf0 5 * copy of this software and associated documentation files (the "Software"),
DevinAlexander 4:589401418bf0 6 * to deal in the Software without restriction, including without limitation
DevinAlexander 4:589401418bf0 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
DevinAlexander 4:589401418bf0 8 * and/or sell copies of the Software, and to permit persons to whom the
DevinAlexander 4:589401418bf0 9 * Software is furnished to do so, subject to the following conditions:
DevinAlexander 4:589401418bf0 10 *
DevinAlexander 4:589401418bf0 11 * The above copyright notice and this permission notice shall be included
DevinAlexander 4:589401418bf0 12 * in all copies or substantial portions of the Software.
DevinAlexander 4:589401418bf0 13 *
DevinAlexander 4:589401418bf0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
DevinAlexander 4:589401418bf0 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
DevinAlexander 4:589401418bf0 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
DevinAlexander 4:589401418bf0 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
DevinAlexander 4:589401418bf0 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
DevinAlexander 4:589401418bf0 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
DevinAlexander 4:589401418bf0 20 * OTHER DEALINGS IN THE SOFTWARE.
DevinAlexander 4:589401418bf0 21 *
DevinAlexander 4:589401418bf0 22 * Except as contained in this notice, the name of Maxim Integrated
DevinAlexander 4:589401418bf0 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
DevinAlexander 4:589401418bf0 24 * Products, Inc. Branding Policy.
DevinAlexander 4:589401418bf0 25 *
DevinAlexander 4:589401418bf0 26 * The mere transfer of this software does not imply any licenses
DevinAlexander 4:589401418bf0 27 * of trade secrets, proprietary technology, copyrights, patents,
DevinAlexander 4:589401418bf0 28 * trademarks, maskwork rights, or any other form of intellectual
DevinAlexander 4:589401418bf0 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
DevinAlexander 4:589401418bf0 30 * ownership rights.
DevinAlexander 4:589401418bf0 31 *******************************************************************************
DevinAlexander 4:589401418bf0 32 */
DevinAlexander 0:456e9e702d57 33 #ifndef MAX31856_h
DevinAlexander 0:456e9e702d57 34 #define MAX31856_h
DevinAlexander 4:589401418bf0 35 #include "mbed.h"
DevinAlexander 0:456e9e702d57 36
DevinAlexander 4:589401418bf0 37
DevinAlexander 4:589401418bf0 38 //Define all the addresses of the registers in the MAX31856
DevinAlexander 4:589401418bf0 39 #define ADDRESS_CR0_READ 0x00 //Factory Default 00h
DevinAlexander 4:589401418bf0 40 #define ADDRESS_CR0_WRITE 0x80
DevinAlexander 4:589401418bf0 41 #define ADDRESS_CR1_READ 0x01 //Factory Default 03h
DevinAlexander 4:589401418bf0 42 #define ADDRESS_CR1_WRITE 0x81
DevinAlexander 4:589401418bf0 43 #define ADDRESS_MASK_READ 0x02 //Factory Default FFh
DevinAlexander 4:589401418bf0 44 #define ADDRESS_MASK_WRITE 0x82
DevinAlexander 4:589401418bf0 45 #define ADDRESS_CJHF_READ 0x03 //Factory Default 7Fh
DevinAlexander 4:589401418bf0 46 #define ADDRESS_CJHF_WRITE 0x83
DevinAlexander 4:589401418bf0 47 #define ADDRESS_CJLF_READ 0x04 //Factory Default C0h
DevinAlexander 4:589401418bf0 48 #define ADDRESS_CJLF_WRITE 0x84
DevinAlexander 4:589401418bf0 49 #define ADDRESS_LTHFTH_READ 0x05 //Factory Default 7Fh
DevinAlexander 4:589401418bf0 50 #define ADDRESS_LTHFTH_WRITE 0x85
DevinAlexander 4:589401418bf0 51 #define ADDRESS_LTHFTL_READ 0x06 //Factory Default FFh
DevinAlexander 4:589401418bf0 52 #define ADDRESS_LTHFTL_WRITE 0x86
DevinAlexander 4:589401418bf0 53 #define ADDRESS_LTLFTH_READ 0x07 //Factory Default 80h
DevinAlexander 4:589401418bf0 54 #define ADDRESS_LTLFTH_WRITE 0x87
DevinAlexander 4:589401418bf0 55 #define ADDRESS_LTLFTL_READ 0x08 //Factory Default 00h
DevinAlexander 4:589401418bf0 56 #define ADDRESS_LTLFTL_WRITE 0x88
DevinAlexander 4:589401418bf0 57 #define ADDRESS_CJTO_READ 0x09 //Factory Default 00h
DevinAlexander 4:589401418bf0 58 #define ADDRESS_CJTO_WRITE 0x89
DevinAlexander 4:589401418bf0 59 #define ADDRESS_CJTH_READ 0x0A //Factory Default 00h
DevinAlexander 4:589401418bf0 60 #define ADDRESS_CJTH_WRITE 0x8A
DevinAlexander 4:589401418bf0 61 #define ADDRESS_CJTL_READ 0x0B //Factory Default 00h
DevinAlexander 4:589401418bf0 62 #define ADDRESS_CJTL_WRITE 0x8B
DevinAlexander 4:589401418bf0 63 #define ADDRESS_LTCBH_READ 0x0C
DevinAlexander 4:589401418bf0 64 #define ADDRESS_LTCBM_READ 0x0D
DevinAlexander 4:589401418bf0 65 #define ADDRESS_LTCBL_READ 0x0E
DevinAlexander 4:589401418bf0 66 #define ADDRESS_SR_READ 0x0F
DevinAlexander 4:589401418bf0 67
DevinAlexander 4:589401418bf0 68
DevinAlexander 4:589401418bf0 69 //Define parameters for control register zero (CR0)
DevinAlexander 4:589401418bf0 70 #define CR0_CONV_MODE_NORMALLY_OFF 0x00 //Power On Default value
DevinAlexander 4:589401418bf0 71 #define CR0_CONV_MODE_NORMALLY_ON 0x80
DevinAlexander 4:589401418bf0 72
DevinAlexander 4:589401418bf0 73 #define CR0_1_SHOT_MODE_NO_CONVERSION 0x00 //defaults to this value
DevinAlexander 4:589401418bf0 74 #define CR0_1_SHOT_MODE_ONE_CONVERSION 0x40 //^
DevinAlexander 4:589401418bf0 75
DevinAlexander 4:589401418bf0 76 #define CR0_OC_DETECT_DISABLED 0x00
DevinAlexander 4:589401418bf0 77 #define CR0_OC_DETECT_ENABLED_R_LESS_5k 0x10
DevinAlexander 4:589401418bf0 78 #define CR0_OC_DETECT_ENABLED_TC_LESS_2ms 0x20
DevinAlexander 4:589401418bf0 79 #define CR0_OC_DETECT_ENABLED_TC_MORE_2ms 0x30
DevinAlexander 4:589401418bf0 80
DevinAlexander 4:589401418bf0 81 #define CR0_COLD_JUNC_ENABLE 0x00 //Power On Default value
DevinAlexander 4:589401418bf0 82 #define CR0_COLD_JUNC_DISABLE 0x08 //speed of conversion is sped up by 25ms when this optionis selected (Disable the cold junc)
DevinAlexander 4:589401418bf0 83
DevinAlexander 4:589401418bf0 84 #define CR0_FAULT_MODE_COMPARATOR 0x00 //Power On Default value
DevinAlexander 4:589401418bf0 85 #define CR0_FAULT_MODE_INTERUPT 0x04
DevinAlexander 4:589401418bf0 86
DevinAlexander 4:589401418bf0 87 #define CR0_FAULTCLR_DEFAULT_VAL 0x00 //defaults to this value
DevinAlexander 4:589401418bf0 88 #define CR0_FAULTCLR_RETURN_FAULTS_TO_ZERO 0x02 //^
DevinAlexander 4:589401418bf0 89
DevinAlexander 4:589401418bf0 90 #define CR0_FILTER_OUT_60Hz 0x00 //Preset value
DevinAlexander 4:589401418bf0 91 #define CR0_FILTER_OUT_50Hz 0x01 //^
DevinAlexander 4:589401418bf0 92
DevinAlexander 4:589401418bf0 93
DevinAlexander 4:589401418bf0 94
DevinAlexander 4:589401418bf0 95 //Define parameters for control register one (CR1)
DevinAlexander 4:589401418bf0 96 /* Adding Samples increases the conversion time and reduces noise.
DevinAlexander 4:589401418bf0 97 Typical conversion times:
DevinAlexander 4:589401418bf0 98 1-shot or first conversion in Auto mode:
DevinAlexander 4:589401418bf0 99 = t_Conversion + (samples-1)*33.33mS (60Hz rejection)
DevinAlexander 4:589401418bf0 100 = t_Conversion + (samples-1)*40.00mS (50Hz rejection)
DevinAlexander 4:589401418bf0 101 2 thru n conversions in Auto mode:
DevinAlexander 4:589401418bf0 102 = t_Conversion + (samples-1)*16.67mS (60Hz rejection)
DevinAlexander 4:589401418bf0 103 = t_Conversion + (samples-1)*20.00mS (50Hz rejection)
DevinAlexander 4:589401418bf0 104 */
DevinAlexander 4:589401418bf0 105 #define CR1_AVG_TC_SAMPLES_1 0x00 //Power on default value
DevinAlexander 4:589401418bf0 106 #define CR1_AVG_TC_SAMPLES_2 0x10
DevinAlexander 4:589401418bf0 107 #define CR1_AVG_TC_SAMPLES_4 0x20
DevinAlexander 4:589401418bf0 108 #define CR1_AVG_TC_SAMPLES_8 0x30
DevinAlexander 4:589401418bf0 109 #define CR1_AVG_TC_SAMPLES_16 0x40
DevinAlexander 4:589401418bf0 110
DevinAlexander 4:589401418bf0 111 // Define which type of thermocouple the MAX31856 is using. This is for lineariztion purposes
DevinAlexander 4:589401418bf0 112 #define CR1_TC_TYPE_B 0x00
DevinAlexander 4:589401418bf0 113 #define CR1_TC_TYPE_E 0x01
DevinAlexander 4:589401418bf0 114 #define CR1_TC_TYPE_J 0x02
DevinAlexander 4:589401418bf0 115 #define CR1_TC_TYPE_K 0x03 //Power on default value
DevinAlexander 4:589401418bf0 116 #define CR1_TC_TYPE_N 0x04
DevinAlexander 4:589401418bf0 117 #define CR1_TC_TYPE_R 0x05
DevinAlexander 4:589401418bf0 118 #define CR1_TC_TYPE_S 0x06
DevinAlexander 4:589401418bf0 119 #define CR1_TC_TYPE_T 0x07
DevinAlexander 4:589401418bf0 120 #define CR1_TC_TYPE_VOLT_MODE_GAIN_8 0x08
DevinAlexander 4:589401418bf0 121 #define CR1_TC_TYPE_VOLT_MODE_GAIN_32 0x0C
DevinAlexander 4:589401418bf0 122
DevinAlexander 4:589401418bf0 123 //Define parameters for the mask register (MASK)
DevinAlexander 4:589401418bf0 124 #define MASK_CJ_FAULT_THRESHOLD_HIGH 0x20
DevinAlexander 4:589401418bf0 125 #define MASK_CJ_FAULT_THRESHOLD_LOW 0x10
DevinAlexander 4:589401418bf0 126 #define MASK_TC_FAULT_THRESHOLD_HIGH 0x08
DevinAlexander 4:589401418bf0 127 #define MASK_TC_FAULT_THRESHOLD_LOW 0x04
DevinAlexander 4:589401418bf0 128 #define MASK_OVER_UNDER_VOLT_FAULT 0x02
DevinAlexander 4:589401418bf0 129 #define MASK_OPEN_CIRCUIT_FAULT 0x01
DevinAlexander 4:589401418bf0 130
DevinAlexander 4:589401418bf0 131
DevinAlexander 4:589401418bf0 132 //If these defined values are &= (ANDed) with the contents of a register, it will reset the bits pertaing to the naming convention to zero
DevinAlexander 4:589401418bf0 133 #define CR0_CLEAR_BITS_7 ~0x80
DevinAlexander 4:589401418bf0 134 #define CR0_CLEAR_BITS_6 ~0x40
DevinAlexander 4:589401418bf0 135 #define CR0_CLEAR_BITS_5_4 ~0x30
DevinAlexander 4:589401418bf0 136 #define CR0_CLEAR_BITS_3 ~0x08
DevinAlexander 4:589401418bf0 137 #define CR0_CLEAR_BITS_2 ~0x04
DevinAlexander 4:589401418bf0 138 #define CR0_CLEAR_BITS_1 ~0x02
DevinAlexander 4:589401418bf0 139 #define CR0_CLEAR_BITS_0 ~0x01
DevinAlexander 4:589401418bf0 140
DevinAlexander 4:589401418bf0 141 #define CR1_CLEAR_BITS_6_4 ~0x70
DevinAlexander 4:589401418bf0 142 #define CR1_CLEAR_BITS_3_0 ~0x0F
DevinAlexander 4:589401418bf0 143
DevinAlexander 4:589401418bf0 144
DevinAlexander 4:589401418bf0 145 #define MASK_CLEAR_BITS_5 ~0x01UL << 5))
DevinAlexander 4:589401418bf0 146 #define MASK_CLEAR_BITS_4 ~0x01UL << 4))
DevinAlexander 4:589401418bf0 147 #define MASK_CLEAR_BITS_3 ~0x01UL << 3))
DevinAlexander 4:589401418bf0 148 #define MASK_CLEAR_BITS_2 ~0x01UL << 2))
DevinAlexander 4:589401418bf0 149 #define MASK_CLEAR_BITS_1 ~0x01UL << 1))
DevinAlexander 4:589401418bf0 150 #define MASK_CLEAR_BITS_0 ~0x01
DevinAlexander 4:589401418bf0 151
DevinAlexander 4:589401418bf0 152 //The following are predefined times that the MAX31856 needs to wait in between
DevinAlexander 4:589401418bf0 153 #define MIN_TIME_BETWEEN_READINGS
DevinAlexander 4:589401418bf0 154
DevinAlexander 4:589401418bf0 155 /**
DevinAlexander 4:589401418bf0 156 * @brief Library for the MAX31856\n
DevinAlexander 4:589401418bf0 157 * The MAX30205 temperature sensor accurately measures temperature and provide
DevinAlexander 4:589401418bf0 158 * an overtemperature alarm/interrupt/shutdown output. This device converts the
DevinAlexander 4:589401418bf0 159 * temperature measurements to digital form using a high-resolution,
DevinAlexander 4:589401418bf0 160 * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical
DevinAlexander 4:589401418bf0 161 * thermometry specification of the ASTM E1112 when soldered on the final PCB.
DevinAlexander 4:589401418bf0 162 * Communication is through an I2C-compatible 2-wire serial interface.
DevinAlexander 4:589401418bf0 163 *
DevinAlexander 4:589401418bf0 164 * @code
DevinAlexander 4:589401418bf0 165 * #include "mbed.h"
DevinAlexander 4:589401418bf0 166 * #include "MAX31856.h"
DevinAlexander 4:589401418bf0 167 *
DevinAlexander 4:589401418bf0 168 *
DevinAlexander 4:589401418bf0 169 * //Get I2C instance
DevinAlexander 4:589401418bf0 170 * I2C i2cBus(I2C1_SDA, I2C1_SCL);
DevinAlexander 4:589401418bf0 171 *
DevinAlexander 4:589401418bf0 172 * //Get temp sensor instance
DevinAlexander 4:589401418bf0 173 * MAX30205 bodyTempSensor(i2cBus, 0x4D); //Constructor takes 7-bit slave adrs
DevinAlexander 4:589401418bf0 174 *
DevinAlexander 4:589401418bf0 175 * int main(void)
DevinAlexander 4:589401418bf0 176 * {
DevinAlexander 4:589401418bf0 177 * //use sensor
DevinAlexander 4:589401418bf0 178 * }
DevinAlexander 4:589401418bf0 179 * @endcode
DevinAlexander 4:589401418bf0 180 */
DevinAlexander 4:589401418bf0 181
DevinAlexander 4:589401418bf0 182
DevinAlexander 4:589401418bf0 183
DevinAlexander 1:b58719a76fc3 184 /** Please see pages 18-26 in the MAX31856 data sheet to see what register bit masks are needed to be set
DevinAlexander 1:b58719a76fc3 185 to achieve functionality desired. The data sheet can be found at
DevinAlexander 1:b58719a76fc3 186
DevinAlexander 1:b58719a76fc3 187 *** https://datasheets.maximintegrated.com/en/ds/MAX31856.pdf ***
DevinAlexander 1:b58719a76fc3 188 */
DevinAlexander 0:456e9e702d57 189
DevinAlexander 4:589401418bf0 190 ///Parameters that are used throughout the library
DevinAlexander 1:b58719a76fc3 191 #define TC_MAX_VAL_FAULT 1800
DevinAlexander 1:b58719a76fc3 192 #define TC_MIN_VAL_FAULT -210
DevinAlexander 1:b58719a76fc3 193 #define CJ_MAX_VAL_FAULT 125
DevinAlexander 1:b58719a76fc3 194 #define CJ_MIN_VAL_FAULT -55
DevinAlexander 1:b58719a76fc3 195
DevinAlexander 1:b58719a76fc3 196
DevinAlexander 1:b58719a76fc3 197
DevinAlexander 1:b58719a76fc3 198
DevinAlexander 0:456e9e702d57 199
DevinAlexander 0:456e9e702d57 200
DevinAlexander 0:456e9e702d57 201
DevinAlexander 0:456e9e702d57 202
DevinAlexander 0:456e9e702d57 203 class MAX31856
DevinAlexander 0:456e9e702d57 204 {
DevinAlexander 0:456e9e702d57 205 // public:
DevinAlexander 1:b58719a76fc3 206 // struct time_adjusting_factors {
DevinAlexander 1:b58719a76fc3 207 // int samples; // 1, 2, 4, 8, or 16 samples are the possible values
DevinAlexander 1:b58719a76fc3 208 // bool filter; // 0=60Hz, 1=50Hz
DevinAlexander 1:b58719a76fc3 209 //
DevinAlexander 1:b58719a76fc3 210 // } conversion_time;
DevinAlexander 1:b58719a76fc3 211
DevinAlexander 4:589401418bf0 212 public:
DevinAlexander 4:589401418bf0 213
DevinAlexander 4:589401418bf0 214 /**
DevinAlexander 4:589401418bf0 215 * @brief Constructor using reference to I2C object
DevinAlexander 4:589401418bf0 216 * @param _spi - Reference to SPI object
DevinAlexander 4:589401418bf0 217 * @param _ncs - Chip Select for SPI comunications with the oject
DevinAlexander 4:589401418bf0 218 * @param _type - Type of thermocouple used
DevinAlexander 4:589401418bf0 219 * @param _fltr - Feature of the MAX31856 to filter out either 50Hz/60Hz from signal
DevinAlexander 4:589401418bf0 220 * @param _samples - How many samples are averaged for one conversion
DevinAlexander 4:589401418bf0 221 * @param _conversion_mode - Choose between always on and making conversions and off in between requests for a reading
DevinAlexander 4:589401418bf0 222 */
DevinAlexander 4:589401418bf0 223 MAX31856(SPI& _spi, PinName _ncs, uint8_t _type=CR1_TC_TYPE_K, uint8_t _fltr=CR0_FILTER_OUT_60Hz, uint8_t _samples=CR1_AVG_TC_SAMPLES_1, uint8_t _conversion_mode=CR0_CONV_MODE_NORMALLY_OFF);
DevinAlexander 0:456e9e702d57 224 // float read(temperature_type_t type = THERMOCOUPLE_T);
DevinAlexander 4:589401418bf0 225
DevinAlexander 4:589401418bf0 226 /** @brief Destructor */
DevinAlexander 4:589401418bf0 227 ~MAX30205(void);
DevinAlexander 4:589401418bf0 228
DevinAlexander 4:589401418bf0 229 /** @brief Writes the chip seleect pin low to begin SPI communications */
DevinAlexander 4:589401418bf0 230 void spiEnable();
DevinAlexander 4:589401418bf0 231 /** @brief Writes the chip seleect pin high to end SPI communications */
DevinAlexander 4:589401418bf0 232 void spiDisable();
DevinAlexander 4:589401418bf0 233 /**
DevinAlexander 4:589401418bf0 234 * @brief Requests read of the thermocouple temperature
DevinAlexander 4:589401418bf0 235 * @return float of the converted thermocouple reading based on current configurations
DevinAlexander 4:589401418bf0 236 */
DevinAlexander 4:589401418bf0 237 float readTC();
DevinAlexander 4:589401418bf0 238 /**
DevinAlexander 4:589401418bf0 239 * @brief Requests read of the cold junction temperature
DevinAlexander 4:589401418bf0 240 * @return float of the converted artificial cold junction reading based on current configurations
DevinAlexander 4:589401418bf0 241 */
DevinAlexander 4:589401418bf0 242 float readCJ();
DevinAlexander 4:589401418bf0 243
DevinAlexander 4:589401418bf0 244
DevinAlexander 4:589401418bf0 245
DevinAlexander 4:589401418bf0 246
DevinAlexander 4:589401418bf0 247
DevinAlexander 4:589401418bf0 248 //Functions for register CR0
DevinAlexander 4:589401418bf0 249 /**
DevinAlexander 4:589401418bf0 250 * @brief Sets bits in the configuration register zero for setting the rate of conversions
DevinAlexander 4:589401418bf0 251 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 252 */
DevinAlexander 4:589401418bf0 253 bool setConversionMode(uint8_t val);
DevinAlexander 4:589401418bf0 254 /**
DevinAlexander 4:589401418bf0 255 * @brief Sets bits in the configuration register zero for enabling one conversion to take place
DevinAlexander 4:589401418bf0 256 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 257 */
DevinAlexander 4:589401418bf0 258 bool setOneShotMode(uint8_t val);
DevinAlexander 4:589401418bf0 259 /**
DevinAlexander 4:589401418bf0 260 * @brief Sets bits in the configuration register zero for configuring open circuit fault detection
DevinAlexander 4:589401418bf0 261 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 262 */
DevinAlexander 4:589401418bf0 263 bool setOpenCircuitFaultDetection(uint8_t val);
DevinAlexander 4:589401418bf0 264 /**
DevinAlexander 4:589401418bf0 265 * @brief Sets bits in the configuration register zero for disabling or enabling the Cold Junction
DevinAlexander 4:589401418bf0 266 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 267 */
DevinAlexander 4:589401418bf0 268 bool setColdJunctionDisable(uint8_t val);
DevinAlexander 4:589401418bf0 269 /**
DevinAlexander 4:589401418bf0 270 * @brief Sets bits in the configuration register zero for setting fault mode status
DevinAlexander 4:589401418bf0 271 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 272 */
DevinAlexander 4:589401418bf0 273 bool setFaultMode(uint8_t val);
DevinAlexander 4:589401418bf0 274 /**
DevinAlexander 4:589401418bf0 275 * @brief Sets bits in the configuration register zero for clearing fault status
DevinAlexander 4:589401418bf0 276 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 277 */
DevinAlexander 4:589401418bf0 278 bool setFaultStatusClear(uint8_t val);
DevinAlexander 4:589401418bf0 279 /**
DevinAlexander 4:589401418bf0 280 * @brief Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation
DevinAlexander 4:589401418bf0 281 * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
DevinAlexander 4:589401418bf0 282 */
DevinAlexander 4:589401418bf0 283 bool setEmiFilterFreq(uint8_t val);
DevinAlexander 4:589401418bf0 284
DevinAlexander 4:589401418bf0 285 //Functions for register CR1
DevinAlexander 4:589401418bf0 286 bool setNumSamplesAvg(uint8_t val);
DevinAlexander 4:589401418bf0 287 bool setThermocoupleType(uint8_t val);
DevinAlexander 4:589401418bf0 288
DevinAlexander 4:589401418bf0 289 //Functions for register MASK
DevinAlexander 4:589401418bf0 290 bool setFaultMasks(uint8_t val, bool enable);
DevinAlexander 4:589401418bf0 291 float setFaultThresholds(uint8_t val, bool enable_mask, float temperature);
DevinAlexander 4:589401418bf0 292
DevinAlexander 4:589401418bf0 293
DevinAlexander 4:589401418bf0 294
DevinAlexander 4:589401418bf0 295
DevinAlexander 4:589401418bf0 296
DevinAlexander 4:589401418bf0 297 //General Functions
DevinAlexander 4:589401418bf0 298
DevinAlexander 4:589401418bf0 299 /**
DevinAlexander 4:589401418bf0 300 * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
DevinAlexander 4:589401418bf0 301 * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
DevinAlexander 4:589401418bf0 302 * @param read_address - Address of register to read the data before it's changed
DevinAlexander 4:589401418bf0 303 * @param write_address - Address of register to rewrite the changed data
DevinAlexander 4:589401418bf0 304 * @param clear_bits - Parameter that is
DevinAlexander 4:589401418bf0 305 * @param val - Bitfield that contains bits related to function specific settings
DevinAlexander 4:589401418bf0 306 * @return 1 on success, and zero on failure
DevinAlexander 4:589401418bf0 307 */
DevinAlexander 4:589401418bf0 308 bool registerReadWriteByte(uint8_t read_address, uint8_t write_address, uint8_t clear_bits, uint8_t val);
DevinAlexander 4:589401418bf0 309 /**
DevinAlexander 4:589401418bf0 310 * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
DevinAlexander 4:589401418bf0 311 * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
DevinAlexander 4:589401418bf0 312 * @param read_address - Address of register to read the data before it's changed
DevinAlexander 4:589401418bf0 313 * @param write_address - Address of register to rewrite the changed data
DevinAlexander 4:589401418bf0 314 * @return 1 on success, and zero on failure
DevinAlexander 4:589401418bf0 315 */
DevinAlexander 4:589401418bf0 316 bool registerWriteByte(uint8_t write_address, uint8_t val);
DevinAlexander 4:589401418bf0 317 /**
DevinAlexander 4:589401418bf0 318 * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
DevinAlexander 4:589401418bf0 319 * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
DevinAlexander 4:589401418bf0 320 * @param temp -
DevinAlexander 4:589401418bf0 321 * @return 1 on success, and zero on failure
DevinAlexander 4:589401418bf0 322 */
DevinAlexander 4:589401418bf0 323 int8_t twosComplimentToSigned8(int8_t temp);
DevinAlexander 4:589401418bf0 324 /**
DevinAlexander 4:589401418bf0 325 * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
DevinAlexander 4:589401418bf0 326 * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
DevinAlexander 4:589401418bf0 327 * @param temp -
DevinAlexander 4:589401418bf0 328 * @return 1 on success, and zero on failure
DevinAlexander 4:589401418bf0 329 */
DevinAlexander 4:589401418bf0 330 int16_t twosComplimentToSigned16(int16_t temp);
DevinAlexander 2:296485923589 331 // void printSetting(string register_bits, string register_info);
DevinAlexander 4:589401418bf0 332
DevinAlexander 4:589401418bf0 333 ///Define a return val for all boolean functions
DevinAlexander 4:589401418bf0 334 bool return_val;
DevinAlexander 4:589401418bf0 335
DevinAlexander 4:589401418bf0 336 private:
DevinAlexander 4:589401418bf0 337 /// SPI object
DevinAlexander 0:456e9e702d57 338 SPI& spi;
DevinAlexander 4:589401418bf0 339 /// SPI object
DevinAlexander 0:456e9e702d57 340 DigitalOut ncs;
DevinAlexander 4:589401418bf0 341 /// Number of samples the thermocouple is configured to average
DevinAlexander 1:b58719a76fc3 342 uint8_t samples;
DevinAlexander 4:589401418bf0 343 /// value is a 1 if the thermocouple is configured to report in voltage mode, value is a zero if thermocouple is set to one of 8 thermocouple types
DevinAlexander 1:b58719a76fc3 344 bool voltage_mode; // used to determine what kind of read of the thermalcouple temperature will take place
DevinAlexander 1:b58719a76fc3 345 bool filter_mode; // 0=60Hz and 1=50Hz
DevinAlexander 1:b58719a76fc3 346 bool conversion_mode;
DevinAlexander 1:b58719a76fc3 347 bool cold_junction_enabled;
DevinAlexander 1:b58719a76fc3 348
DevinAlexander 1:b58719a76fc3 349
DevinAlexander 0:456e9e702d57 350 float thermocoupleT;
DevinAlexander 0:456e9e702d57 351 float internalT;
DevinAlexander 0:456e9e702d57 352 uint32_t lastReadTime;
DevinAlexander 0:456e9e702d57 353 };
DevinAlexander 0:456e9e702d57 354
DevinAlexander 4:589401418bf0 355 #endif /* __MAX31856_H_ */