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.
Fork of MAX31856_example_program by
MAX31856.h@7:2e45068189b1, 2017-07-31 (annotated)
- Committer:
- DevinAlexander
- Date:
- Mon Jul 31 18:46:49 2017 +0000
- Revision:
- 7:2e45068189b1
- Parent:
- 6:e1200ae7d6a3
- Child:
- 8:8723d0006097
Cleaned up the code a significant amount and started restructuring the .h file significantly!
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:e1200ae7d6a3 | 145 | #define MASK_CLEAR_BITS_5 ~0x20 |
DevinAlexander | 6:e1200ae7d6a3 | 146 | #define MASK_CLEAR_BITS_4 ~0x10 |
DevinAlexander | 6:e1200ae7d6a3 | 147 | #define MASK_CLEAR_BITS_3 ~0x08 |
DevinAlexander | 6:e1200ae7d6a3 | 148 | #define MASK_CLEAR_BITS_2 ~0x04 |
DevinAlexander | 6:e1200ae7d6a3 | 149 | #define MASK_CLEAR_BITS_1 ~0x02 |
DevinAlexander | 6:e1200ae7d6a3 | 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 | 1:b58719a76fc3 | 205 | |
DevinAlexander | 4:589401418bf0 | 206 | public: |
DevinAlexander | 4:589401418bf0 | 207 | |
DevinAlexander | 4:589401418bf0 | 208 | /** |
DevinAlexander | 4:589401418bf0 | 209 | * @brief Constructor using reference to I2C object |
DevinAlexander | 4:589401418bf0 | 210 | * @param _spi - Reference to SPI object |
DevinAlexander | 4:589401418bf0 | 211 | * @param _ncs - Chip Select for SPI comunications with the oject |
DevinAlexander | 4:589401418bf0 | 212 | * @param _type - Type of thermocouple used |
DevinAlexander | 4:589401418bf0 | 213 | * @param _fltr - Feature of the MAX31856 to filter out either 50Hz/60Hz from signal |
DevinAlexander | 4:589401418bf0 | 214 | * @param _samples - How many samples are averaged for one conversion |
DevinAlexander | 4:589401418bf0 | 215 | * @param _conversion_mode - Choose between always on and making conversions and off in between requests for a reading |
DevinAlexander | 4:589401418bf0 | 216 | */ |
DevinAlexander | 4:589401418bf0 | 217 | 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 | 4:589401418bf0 | 218 | |
DevinAlexander | 7:2e45068189b1 | 219 | /** @brief Destructor */ |
DevinAlexander | 7:2e45068189b1 | 220 | ~MAX31856(void); |
DevinAlexander | 4:589401418bf0 | 221 | |
DevinAlexander | 7:2e45068189b1 | 222 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 223 | //Temperature Functions |
DevinAlexander | 7:2e45068189b1 | 224 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 225 | /** |
DevinAlexander | 4:589401418bf0 | 226 | * @brief Requests read of the thermocouple temperature |
DevinAlexander | 4:589401418bf0 | 227 | * @return float of the converted thermocouple reading based on current configurations |
DevinAlexander | 4:589401418bf0 | 228 | */ |
DevinAlexander | 4:589401418bf0 | 229 | float readTC(); |
DevinAlexander | 7:2e45068189b1 | 230 | |
DevinAlexander | 7:2e45068189b1 | 231 | |
DevinAlexander | 4:589401418bf0 | 232 | /** |
DevinAlexander | 4:589401418bf0 | 233 | * @brief Requests read of the cold junction temperature |
DevinAlexander | 4:589401418bf0 | 234 | * @return float of the converted artificial cold junction reading based on current configurations |
DevinAlexander | 4:589401418bf0 | 235 | */ |
DevinAlexander | 4:589401418bf0 | 236 | float readCJ(); |
DevinAlexander | 7:2e45068189b1 | 237 | |
DevinAlexander | 4:589401418bf0 | 238 | |
DevinAlexander | 7:2e45068189b1 | 239 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 240 | //Functions for register CR0 |
DevinAlexander | 7:2e45068189b1 | 241 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 242 | /** |
DevinAlexander | 4:589401418bf0 | 243 | * @brief Sets bits in the configuration register zero for setting the rate of conversions |
DevinAlexander | 6:e1200ae7d6a3 | 244 | * @param val - CR0_CONV_MODE_NORMALLY_OFF |
DevinAlexander | 6:e1200ae7d6a3 | 245 | * CR0_CONV_MODE_NORMALLY_ON |
DevinAlexander | 4:589401418bf0 | 246 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 4:589401418bf0 | 247 | */ |
DevinAlexander | 4:589401418bf0 | 248 | bool setConversionMode(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 249 | |
DevinAlexander | 7:2e45068189b1 | 250 | |
DevinAlexander | 4:589401418bf0 | 251 | /** |
DevinAlexander | 4:589401418bf0 | 252 | * @brief Sets bits in the configuration register zero for enabling one conversion to take place |
DevinAlexander | 4:589401418bf0 | 253 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 4:589401418bf0 | 254 | */ |
DevinAlexander | 4:589401418bf0 | 255 | bool setOneShotMode(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 256 | |
DevinAlexander | 7:2e45068189b1 | 257 | |
DevinAlexander | 4:589401418bf0 | 258 | /** |
DevinAlexander | 4:589401418bf0 | 259 | * @brief Sets bits in the configuration register zero for configuring open circuit fault detection |
DevinAlexander | 4:589401418bf0 | 260 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 4:589401418bf0 | 261 | */ |
DevinAlexander | 4:589401418bf0 | 262 | bool setOpenCircuitFaultDetection(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 263 | |
DevinAlexander | 7:2e45068189b1 | 264 | |
DevinAlexander | 4:589401418bf0 | 265 | /** |
DevinAlexander | 4:589401418bf0 | 266 | * @brief Sets bits in the configuration register zero for disabling or enabling the Cold Junction |
DevinAlexander | 4:589401418bf0 | 267 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 4:589401418bf0 | 268 | */ |
DevinAlexander | 4:589401418bf0 | 269 | bool setColdJunctionDisable(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 270 | |
DevinAlexander | 7:2e45068189b1 | 271 | |
DevinAlexander | 4:589401418bf0 | 272 | /** |
DevinAlexander | 4:589401418bf0 | 273 | * @brief Sets bits in the configuration register zero for setting fault mode status |
DevinAlexander | 4:589401418bf0 | 274 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 4:589401418bf0 | 275 | */ |
DevinAlexander | 4:589401418bf0 | 276 | bool setFaultMode(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 277 | |
DevinAlexander | 7:2e45068189b1 | 278 | |
DevinAlexander | 4:589401418bf0 | 279 | /** |
DevinAlexander | 4:589401418bf0 | 280 | * @brief Sets bits in the configuration register zero for clearing fault status |
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 setFaultStatusClear(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 284 | |
DevinAlexander | 7:2e45068189b1 | 285 | |
DevinAlexander | 4:589401418bf0 | 286 | /** |
DevinAlexander | 4:589401418bf0 | 287 | * @brief Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation |
DevinAlexander | 4:589401418bf0 | 288 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 4:589401418bf0 | 289 | */ |
DevinAlexander | 4:589401418bf0 | 290 | bool setEmiFilterFreq(uint8_t val); |
DevinAlexander | 4:589401418bf0 | 291 | |
DevinAlexander | 6:e1200ae7d6a3 | 292 | |
DevinAlexander | 7:2e45068189b1 | 293 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 294 | //Functions for register CR1 |
DevinAlexander | 7:2e45068189b1 | 295 | //***************************************************************************** |
DevinAlexander | 6:e1200ae7d6a3 | 296 | /** |
DevinAlexander | 6:e1200ae7d6a3 | 297 | * @brief Sets bits in the configuration register one for setting how many readings are taken |
DevinAlexander | 6:e1200ae7d6a3 | 298 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 6:e1200ae7d6a3 | 299 | */ |
DevinAlexander | 4:589401418bf0 | 300 | bool setNumSamplesAvg(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 301 | |
DevinAlexander | 7:2e45068189b1 | 302 | |
DevinAlexander | 6:e1200ae7d6a3 | 303 | /** |
DevinAlexander | 7:2e45068189b1 | 304 | * @brief Sets bits in the configuration register one for setting which thermocouple type is going to be programmed into the MAX31856 for linearization of thermovoltage produced and temperature |
DevinAlexander | 6:e1200ae7d6a3 | 305 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 6:e1200ae7d6a3 | 306 | */ |
DevinAlexander | 4:589401418bf0 | 307 | bool setThermocoupleType(uint8_t val); |
DevinAlexander | 4:589401418bf0 | 308 | |
DevinAlexander | 7:2e45068189b1 | 309 | |
DevinAlexander | 7:2e45068189b1 | 310 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 311 | //Functions for register MASK |
DevinAlexander | 7:2e45068189b1 | 312 | //***************************************************************************** |
DevinAlexander | 6:e1200ae7d6a3 | 313 | /** |
DevinAlexander | 7:2e45068189b1 | 314 | * @brief Sets bits in the configuration register one for setting fault masks |
DevinAlexander | 6:e1200ae7d6a3 | 315 | * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected |
DevinAlexander | 6:e1200ae7d6a3 | 316 | */ |
DevinAlexander | 4:589401418bf0 | 317 | bool setFaultMasks(uint8_t val, bool enable); |
DevinAlexander | 7:2e45068189b1 | 318 | |
DevinAlexander | 7:2e45068189b1 | 319 | |
DevinAlexander | 7:2e45068189b1 | 320 | /** |
DevinAlexander | 7:2e45068189b1 | 321 | * @brief Sets bits in the configuration register one for setting thresholds that corespond to the fault mask settings |
DevinAlexander | 7:2e45068189b1 | 322 | * @return return value that was programmed into the the threshold register t |
DevinAlexander | 7:2e45068189b1 | 323 | */ |
DevinAlexander | 4:589401418bf0 | 324 | float setFaultThresholds(uint8_t val, bool enable_mask, float temperature); |
DevinAlexander | 4:589401418bf0 | 325 | |
DevinAlexander | 4:589401418bf0 | 326 | |
DevinAlexander | 7:2e45068189b1 | 327 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 328 | //General Functions |
DevinAlexander | 7:2e45068189b1 | 329 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 330 | /** |
DevinAlexander | 4:589401418bf0 | 331 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 4:589401418bf0 | 332 | * 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 | 333 | * @param read_address - Address of register to read the data before it's changed |
DevinAlexander | 4:589401418bf0 | 334 | * @param write_address - Address of register to rewrite the changed data |
DevinAlexander | 4:589401418bf0 | 335 | * @param clear_bits - Parameter that is |
DevinAlexander | 4:589401418bf0 | 336 | * @param val - Bitfield that contains bits related to function specific settings |
DevinAlexander | 4:589401418bf0 | 337 | * @return 1 on success, and zero on failure |
DevinAlexander | 4:589401418bf0 | 338 | */ |
DevinAlexander | 4:589401418bf0 | 339 | bool registerReadWriteByte(uint8_t read_address, uint8_t write_address, uint8_t clear_bits, uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 340 | |
DevinAlexander | 7:2e45068189b1 | 341 | |
DevinAlexander | 4:589401418bf0 | 342 | /** |
DevinAlexander | 4:589401418bf0 | 343 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 4:589401418bf0 | 344 | * 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 | 345 | * @param read_address - Address of register to read the data before it's changed |
DevinAlexander | 4:589401418bf0 | 346 | * @param write_address - Address of register to rewrite the changed data |
DevinAlexander | 4:589401418bf0 | 347 | * @return 1 on success, and zero on failure |
DevinAlexander | 4:589401418bf0 | 348 | */ |
DevinAlexander | 4:589401418bf0 | 349 | bool registerWriteByte(uint8_t write_address, uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 350 | |
DevinAlexander | 7:2e45068189b1 | 351 | |
DevinAlexander | 4:589401418bf0 | 352 | /** |
DevinAlexander | 4:589401418bf0 | 353 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 4:589401418bf0 | 354 | * 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 | 355 | * @param temp - |
DevinAlexander | 4:589401418bf0 | 356 | * @return 1 on success, and zero on failure |
DevinAlexander | 4:589401418bf0 | 357 | */ |
DevinAlexander | 4:589401418bf0 | 358 | int8_t twosComplimentToSigned8(int8_t temp); |
DevinAlexander | 7:2e45068189b1 | 359 | |
DevinAlexander | 7:2e45068189b1 | 360 | |
DevinAlexander | 4:589401418bf0 | 361 | /** |
DevinAlexander | 4:589401418bf0 | 362 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 4:589401418bf0 | 363 | * 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 | 364 | * @param temp - |
DevinAlexander | 4:589401418bf0 | 365 | * @return 1 on success, and zero on failure |
DevinAlexander | 4:589401418bf0 | 366 | */ |
DevinAlexander | 4:589401418bf0 | 367 | int16_t twosComplimentToSigned16(int16_t temp); |
DevinAlexander | 2:296485923589 | 368 | // void printSetting(string register_bits, string register_info); |
DevinAlexander | 4:589401418bf0 | 369 | |
DevinAlexander | 7:2e45068189b1 | 370 | |
DevinAlexander | 7:2e45068189b1 | 371 | |
DevinAlexander | 7:2e45068189b1 | 372 | private: |
DevinAlexander | 7:2e45068189b1 | 373 | |
DevinAlexander | 7:2e45068189b1 | 374 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 375 | //Private Functions |
DevinAlexander | 7:2e45068189b1 | 376 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 377 | |
DevinAlexander | 7:2e45068189b1 | 378 | /** @brief Writes the chip seleect pin low to begin SPI communications */ |
DevinAlexander | 7:2e45068189b1 | 379 | void spiEnable(); |
DevinAlexander | 7:2e45068189b1 | 380 | |
DevinAlexander | 7:2e45068189b1 | 381 | |
DevinAlexander | 7:2e45068189b1 | 382 | /** @brief Writes the chip seleect pin high to end SPI communications */ |
DevinAlexander | 7:2e45068189b1 | 383 | void spiDisable(); |
DevinAlexander | 7:2e45068189b1 | 384 | |
DevinAlexander | 7:2e45068189b1 | 385 | |
DevinAlexander | 7:2e45068189b1 | 386 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 387 | //Private Members |
DevinAlexander | 7:2e45068189b1 | 388 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 389 | /// SPI object |
DevinAlexander | 7:2e45068189b1 | 390 | SPI& spi; |
DevinAlexander | 7:2e45068189b1 | 391 | |
DevinAlexander | 7:2e45068189b1 | 392 | /// Chip select |
DevinAlexander | 7:2e45068189b1 | 393 | DigitalOut ncs; |
DevinAlexander | 7:2e45068189b1 | 394 | |
DevinAlexander | 7:2e45068189b1 | 395 | /// Number of samples the thermocouple is configured to average |
DevinAlexander | 7:2e45068189b1 | 396 | uint8_t samples; |
DevinAlexander | 7:2e45068189b1 | 397 | |
DevinAlexander | 7:2e45068189b1 | 398 | /// 0=thermocouple is set to one of 8 thermocouple types and 1=Thermocouple is configured to report in voltage mode |
DevinAlexander | 7:2e45068189b1 | 399 | bool voltage_mode; |
DevinAlexander | 7:2e45068189b1 | 400 | |
DevinAlexander | 7:2e45068189b1 | 401 | /// 0=60Hz and 1=50Hz |
DevinAlexander | 7:2e45068189b1 | 402 | bool filter_mode; |
DevinAlexander | 7:2e45068189b1 | 403 | |
DevinAlexander | 7:2e45068189b1 | 404 | /// 0=Always On and converting and 1=MAX31856 is off, so no conversion is taking place currently |
DevinAlexander | 7:2e45068189b1 | 405 | bool conversion_mode; |
DevinAlexander | 7:2e45068189b1 | 406 | |
DevinAlexander | 7:2e45068189b1 | 407 | /// 0=cold junction is disabled and 1=cold junction is enabled |
DevinAlexander | 7:2e45068189b1 | 408 | bool cold_junction_enabled; |
DevinAlexander | 7:2e45068189b1 | 409 | |
DevinAlexander | 4:589401418bf0 | 410 | ///Define a return val for all boolean functions |
DevinAlexander | 4:589401418bf0 | 411 | bool return_val; |
DevinAlexander | 4:589401418bf0 | 412 | |
DevinAlexander | 7:2e45068189b1 | 413 | ///Used to figure out when a new conversion is ready to go |
DevinAlexander | 0:456e9e702d57 | 414 | uint32_t lastReadTime; |
DevinAlexander | 0:456e9e702d57 | 415 | }; |
DevinAlexander | 0:456e9e702d57 | 416 | |
DevinAlexander | 4:589401418bf0 | 417 | #endif /* __MAX31856_H_ */ |