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@8:8723d0006097, 2017-08-01 (annotated)
- Committer:
- DevinAlexander
- Date:
- Tue Aug 01 03:29:15 2017 +0000
- Revision:
- 8:8723d0006097
- Parent:
- 7:2e45068189b1
- Child:
- 9:2d284cc2f65c
One function left to finalize which is setting thresholds;
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 | 8:8723d0006097 | 38 | /* Adding Samples increases the conversion time and reduces noise. |
DevinAlexander | 8:8723d0006097 | 39 | Typical conversion times: |
DevinAlexander | 8:8723d0006097 | 40 | 1-shot or first conversion in Auto mode: |
DevinAlexander | 8:8723d0006097 | 41 | = t_Conversion + (samples-1)*33.33mS (60Hz rejection) |
DevinAlexander | 8:8723d0006097 | 42 | = t_Conversion + (samples-1)*40.00mS (50Hz rejection) |
DevinAlexander | 8:8723d0006097 | 43 | 2 thru n conversions in Auto mode: |
DevinAlexander | 8:8723d0006097 | 44 | = t_Conversion + (samples-1)*16.67mS (60Hz rejection) |
DevinAlexander | 8:8723d0006097 | 45 | = t_Conversion + (samples-1)*20.00mS (50Hz rejection) |
DevinAlexander | 8:8723d0006097 | 46 | */ |
DevinAlexander | 8:8723d0006097 | 47 | |
DevinAlexander | 8:8723d0006097 | 48 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 49 | //Define all the addresses of the registers in the MAX31856 |
DevinAlexander | 8:8723d0006097 | 50 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 51 | #define ADDRESS_CR0_READ 0x00 //Factory Default 00h |
DevinAlexander | 4:589401418bf0 | 52 | #define ADDRESS_CR0_WRITE 0x80 |
DevinAlexander | 4:589401418bf0 | 53 | #define ADDRESS_CR1_READ 0x01 //Factory Default 03h |
DevinAlexander | 4:589401418bf0 | 54 | #define ADDRESS_CR1_WRITE 0x81 |
DevinAlexander | 4:589401418bf0 | 55 | #define ADDRESS_MASK_READ 0x02 //Factory Default FFh |
DevinAlexander | 4:589401418bf0 | 56 | #define ADDRESS_MASK_WRITE 0x82 |
DevinAlexander | 4:589401418bf0 | 57 | #define ADDRESS_CJHF_READ 0x03 //Factory Default 7Fh |
DevinAlexander | 4:589401418bf0 | 58 | #define ADDRESS_CJHF_WRITE 0x83 |
DevinAlexander | 4:589401418bf0 | 59 | #define ADDRESS_CJLF_READ 0x04 //Factory Default C0h |
DevinAlexander | 4:589401418bf0 | 60 | #define ADDRESS_CJLF_WRITE 0x84 |
DevinAlexander | 4:589401418bf0 | 61 | #define ADDRESS_LTHFTH_READ 0x05 //Factory Default 7Fh |
DevinAlexander | 4:589401418bf0 | 62 | #define ADDRESS_LTHFTH_WRITE 0x85 |
DevinAlexander | 4:589401418bf0 | 63 | #define ADDRESS_LTHFTL_READ 0x06 //Factory Default FFh |
DevinAlexander | 4:589401418bf0 | 64 | #define ADDRESS_LTHFTL_WRITE 0x86 |
DevinAlexander | 4:589401418bf0 | 65 | #define ADDRESS_LTLFTH_READ 0x07 //Factory Default 80h |
DevinAlexander | 4:589401418bf0 | 66 | #define ADDRESS_LTLFTH_WRITE 0x87 |
DevinAlexander | 4:589401418bf0 | 67 | #define ADDRESS_LTLFTL_READ 0x08 //Factory Default 00h |
DevinAlexander | 4:589401418bf0 | 68 | #define ADDRESS_LTLFTL_WRITE 0x88 |
DevinAlexander | 4:589401418bf0 | 69 | #define ADDRESS_CJTO_READ 0x09 //Factory Default 00h |
DevinAlexander | 4:589401418bf0 | 70 | #define ADDRESS_CJTO_WRITE 0x89 |
DevinAlexander | 4:589401418bf0 | 71 | #define ADDRESS_CJTH_READ 0x0A //Factory Default 00h |
DevinAlexander | 4:589401418bf0 | 72 | #define ADDRESS_CJTH_WRITE 0x8A |
DevinAlexander | 4:589401418bf0 | 73 | #define ADDRESS_CJTL_READ 0x0B //Factory Default 00h |
DevinAlexander | 4:589401418bf0 | 74 | #define ADDRESS_CJTL_WRITE 0x8B |
DevinAlexander | 4:589401418bf0 | 75 | #define ADDRESS_LTCBH_READ 0x0C |
DevinAlexander | 4:589401418bf0 | 76 | #define ADDRESS_LTCBM_READ 0x0D |
DevinAlexander | 4:589401418bf0 | 77 | #define ADDRESS_LTCBL_READ 0x0E |
DevinAlexander | 4:589401418bf0 | 78 | #define ADDRESS_SR_READ 0x0F |
DevinAlexander | 4:589401418bf0 | 79 | |
DevinAlexander | 8:8723d0006097 | 80 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 81 | //Define parameters for control register zero (CR0) |
DevinAlexander | 8:8723d0006097 | 82 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 83 | #define CR0_CONV_MODE_NORMALLY_OFF 0x00 //Power On Default value |
DevinAlexander | 4:589401418bf0 | 84 | #define CR0_CONV_MODE_NORMALLY_ON 0x80 |
DevinAlexander | 4:589401418bf0 | 85 | |
DevinAlexander | 4:589401418bf0 | 86 | #define CR0_1_SHOT_MODE_NO_CONVERSION 0x00 //defaults to this value |
DevinAlexander | 4:589401418bf0 | 87 | #define CR0_1_SHOT_MODE_ONE_CONVERSION 0x40 //^ |
DevinAlexander | 4:589401418bf0 | 88 | |
DevinAlexander | 4:589401418bf0 | 89 | #define CR0_OC_DETECT_DISABLED 0x00 |
DevinAlexander | 4:589401418bf0 | 90 | #define CR0_OC_DETECT_ENABLED_R_LESS_5k 0x10 |
DevinAlexander | 4:589401418bf0 | 91 | #define CR0_OC_DETECT_ENABLED_TC_LESS_2ms 0x20 |
DevinAlexander | 4:589401418bf0 | 92 | #define CR0_OC_DETECT_ENABLED_TC_MORE_2ms 0x30 |
DevinAlexander | 4:589401418bf0 | 93 | |
DevinAlexander | 4:589401418bf0 | 94 | #define CR0_COLD_JUNC_ENABLE 0x00 //Power On Default value |
DevinAlexander | 4:589401418bf0 | 95 | #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 | 96 | |
DevinAlexander | 4:589401418bf0 | 97 | #define CR0_FAULT_MODE_COMPARATOR 0x00 //Power On Default value |
DevinAlexander | 4:589401418bf0 | 98 | #define CR0_FAULT_MODE_INTERUPT 0x04 |
DevinAlexander | 4:589401418bf0 | 99 | |
DevinAlexander | 4:589401418bf0 | 100 | #define CR0_FAULTCLR_DEFAULT_VAL 0x00 //defaults to this value |
DevinAlexander | 4:589401418bf0 | 101 | #define CR0_FAULTCLR_RETURN_FAULTS_TO_ZERO 0x02 //^ |
DevinAlexander | 4:589401418bf0 | 102 | |
DevinAlexander | 8:8723d0006097 | 103 | #define CR0_FILTER_OUT_60Hz 0x00 //Preset value |
DevinAlexander | 8:8723d0006097 | 104 | #define CR0_FILTER_OUT_50Hz 0x01 //^ |
DevinAlexander | 4:589401418bf0 | 105 | |
DevinAlexander | 4:589401418bf0 | 106 | |
DevinAlexander | 8:8723d0006097 | 107 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 108 | //Define parameters for control register one (CR1) |
DevinAlexander | 8:8723d0006097 | 109 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 110 | #define CR1_AVG_TC_SAMPLES_1 0x00 //Power on default value |
DevinAlexander | 4:589401418bf0 | 111 | #define CR1_AVG_TC_SAMPLES_2 0x10 |
DevinAlexander | 4:589401418bf0 | 112 | #define CR1_AVG_TC_SAMPLES_4 0x20 |
DevinAlexander | 4:589401418bf0 | 113 | #define CR1_AVG_TC_SAMPLES_8 0x30 |
DevinAlexander | 4:589401418bf0 | 114 | #define CR1_AVG_TC_SAMPLES_16 0x40 |
DevinAlexander | 4:589401418bf0 | 115 | |
DevinAlexander | 4:589401418bf0 | 116 | // Define which type of thermocouple the MAX31856 is using. This is for lineariztion purposes |
DevinAlexander | 4:589401418bf0 | 117 | #define CR1_TC_TYPE_B 0x00 |
DevinAlexander | 4:589401418bf0 | 118 | #define CR1_TC_TYPE_E 0x01 |
DevinAlexander | 4:589401418bf0 | 119 | #define CR1_TC_TYPE_J 0x02 |
DevinAlexander | 4:589401418bf0 | 120 | #define CR1_TC_TYPE_K 0x03 //Power on default value |
DevinAlexander | 4:589401418bf0 | 121 | #define CR1_TC_TYPE_N 0x04 |
DevinAlexander | 4:589401418bf0 | 122 | #define CR1_TC_TYPE_R 0x05 |
DevinAlexander | 4:589401418bf0 | 123 | #define CR1_TC_TYPE_S 0x06 |
DevinAlexander | 4:589401418bf0 | 124 | #define CR1_TC_TYPE_T 0x07 |
DevinAlexander | 4:589401418bf0 | 125 | #define CR1_TC_TYPE_VOLT_MODE_GAIN_8 0x08 |
DevinAlexander | 4:589401418bf0 | 126 | #define CR1_TC_TYPE_VOLT_MODE_GAIN_32 0x0C |
DevinAlexander | 4:589401418bf0 | 127 | |
DevinAlexander | 8:8723d0006097 | 128 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 129 | //Define parameters for the mask register (MASK) |
DevinAlexander | 8:8723d0006097 | 130 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 131 | #define MASK_CJ_FAULT_THRESHOLD_HIGH 0x20 |
DevinAlexander | 4:589401418bf0 | 132 | #define MASK_CJ_FAULT_THRESHOLD_LOW 0x10 |
DevinAlexander | 4:589401418bf0 | 133 | #define MASK_TC_FAULT_THRESHOLD_HIGH 0x08 |
DevinAlexander | 4:589401418bf0 | 134 | #define MASK_TC_FAULT_THRESHOLD_LOW 0x04 |
DevinAlexander | 4:589401418bf0 | 135 | #define MASK_OVER_UNDER_VOLT_FAULT 0x02 |
DevinAlexander | 4:589401418bf0 | 136 | #define MASK_OPEN_CIRCUIT_FAULT 0x01 |
DevinAlexander | 4:589401418bf0 | 137 | |
DevinAlexander | 8:8723d0006097 | 138 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 139 | //If these defined values are &= (bitwise ANDed) with the contents of a register, it will reset the bits pertaing to the specific bitfields to zero |
DevinAlexander | 8:8723d0006097 | 140 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 141 | #define CR0_CLEAR_BITS_7 ~0x80 |
DevinAlexander | 4:589401418bf0 | 142 | #define CR0_CLEAR_BITS_6 ~0x40 |
DevinAlexander | 4:589401418bf0 | 143 | #define CR0_CLEAR_BITS_5_4 ~0x30 |
DevinAlexander | 4:589401418bf0 | 144 | #define CR0_CLEAR_BITS_3 ~0x08 |
DevinAlexander | 4:589401418bf0 | 145 | #define CR0_CLEAR_BITS_2 ~0x04 |
DevinAlexander | 4:589401418bf0 | 146 | #define CR0_CLEAR_BITS_1 ~0x02 |
DevinAlexander | 4:589401418bf0 | 147 | #define CR0_CLEAR_BITS_0 ~0x01 |
DevinAlexander | 4:589401418bf0 | 148 | |
DevinAlexander | 4:589401418bf0 | 149 | #define CR1_CLEAR_BITS_6_4 ~0x70 |
DevinAlexander | 4:589401418bf0 | 150 | #define CR1_CLEAR_BITS_3_0 ~0x0F |
DevinAlexander | 4:589401418bf0 | 151 | |
DevinAlexander | 6:e1200ae7d6a3 | 152 | #define MASK_CLEAR_BITS_5 ~0x20 |
DevinAlexander | 6:e1200ae7d6a3 | 153 | #define MASK_CLEAR_BITS_4 ~0x10 |
DevinAlexander | 6:e1200ae7d6a3 | 154 | #define MASK_CLEAR_BITS_3 ~0x08 |
DevinAlexander | 6:e1200ae7d6a3 | 155 | #define MASK_CLEAR_BITS_2 ~0x04 |
DevinAlexander | 6:e1200ae7d6a3 | 156 | #define MASK_CLEAR_BITS_1 ~0x02 |
DevinAlexander | 6:e1200ae7d6a3 | 157 | #define MASK_CLEAR_BITS_0 ~0x01 |
DevinAlexander | 4:589401418bf0 | 158 | |
DevinAlexander | 8:8723d0006097 | 159 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 160 | ///Parameters that are used throughout the library |
DevinAlexander | 8:8723d0006097 | 161 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 162 | #define TC_MAX_VAL_FAULT 1800 |
DevinAlexander | 8:8723d0006097 | 163 | #define TC_MIN_VAL_FAULT -210 |
DevinAlexander | 8:8723d0006097 | 164 | #define CJ_MAX_VAL_FAULT 125 |
DevinAlexander | 8:8723d0006097 | 165 | #define CJ_MIN_VAL_FAULT -55 |
DevinAlexander | 8:8723d0006097 | 166 | |
DevinAlexander | 8:8723d0006097 | 167 | |
DevinAlexander | 4:589401418bf0 | 168 | |
DevinAlexander | 4:589401418bf0 | 169 | /** |
DevinAlexander | 4:589401418bf0 | 170 | * @brief Library for the MAX31856\n |
DevinAlexander | 4:589401418bf0 | 171 | * The MAX30205 temperature sensor accurately measures temperature and provide |
DevinAlexander | 4:589401418bf0 | 172 | * an overtemperature alarm/interrupt/shutdown output. This device converts the |
DevinAlexander | 4:589401418bf0 | 173 | * temperature measurements to digital form using a high-resolution, |
DevinAlexander | 4:589401418bf0 | 174 | * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical |
DevinAlexander | 4:589401418bf0 | 175 | * thermometry specification of the ASTM E1112 when soldered on the final PCB. |
DevinAlexander | 4:589401418bf0 | 176 | * Communication is through an I2C-compatible 2-wire serial interface. |
DevinAlexander | 4:589401418bf0 | 177 | * |
DevinAlexander | 4:589401418bf0 | 178 | * @code |
DevinAlexander | 4:589401418bf0 | 179 | * #include "mbed.h" |
DevinAlexander | 4:589401418bf0 | 180 | * #include "MAX31856.h" |
DevinAlexander | 4:589401418bf0 | 181 | * |
DevinAlexander | 4:589401418bf0 | 182 | * |
DevinAlexander | 8:8723d0006097 | 183 | * // Hardware serial port |
DevinAlexander | 8:8723d0006097 | 184 | * Serial serial(USBTX, USBRX); |
DevinAlexander | 8:8723d0006097 | 185 | * |
DevinAlexander | 8:8723d0006097 | 186 | * //SPI communications |
DevinAlexander | 8:8723d0006097 | 187 | * SPI spi(SPIO MOSI,SPIO MISO,SPIO SCK); |
DevinAlexander | 8:8723d0006097 | 188 | * |
DevinAlexander | 8:8723d0006097 | 189 | * //Thermocouples |
DevinAlexander | 8:8723d0006097 | 190 | * MAX31856 Thermocouple1(spi, CHIPSELECT); |
DevinAlexander | 8:8723d0006097 | 191 | * MAX31856 Thermocouple2(spi, CHIPSELECT); |
DevinAlexander | 8:8723d0006097 | 192 | * |
DevinAlexander | 8:8723d0006097 | 193 | * |
DevinAlexander | 4:589401418bf0 | 194 | * int main(void) |
DevinAlexander | 4:589401418bf0 | 195 | * { |
DevinAlexander | 8:8723d0006097 | 196 | * float temperature_TC_1, temperature_CJ_1; |
DevinAlexander | 8:8723d0006097 | 197 | * while(true) |
DevinAlexander | 8:8723d0006097 | 198 | * { |
DevinAlexander | 8:8723d0006097 | 199 | * temperature_TC_1=Thermocouple1.readTC(); |
DevinAlexander | 8:8723d0006097 | 200 | * temperature_CJ_1=Thermocouple1.readCJ(); |
DevinAlexander | 8:8723d0006097 | 201 | * serial.printf("MAX31856 TC = %f Celsius MAX31856 CJ = %f Celsius \n\r",temperature_TC_1,temperature_CJ_1); |
DevinAlexander | 8:8723d0006097 | 202 | * wait(1.0); |
DevinAlexander | 8:8723d0006097 | 203 | * } |
DevinAlexander | 4:589401418bf0 | 204 | * } |
DevinAlexander | 4:589401418bf0 | 205 | * @endcode |
DevinAlexander | 4:589401418bf0 | 206 | */ |
DevinAlexander | 4:589401418bf0 | 207 | |
DevinAlexander | 4:589401418bf0 | 208 | |
DevinAlexander | 4:589401418bf0 | 209 | |
DevinAlexander | 1:b58719a76fc3 | 210 | /** Please see pages 18-26 in the MAX31856 data sheet to see what register bit masks are needed to be set |
DevinAlexander | 1:b58719a76fc3 | 211 | to achieve functionality desired. The data sheet can be found at |
DevinAlexander | 1:b58719a76fc3 | 212 | |
DevinAlexander | 1:b58719a76fc3 | 213 | *** https://datasheets.maximintegrated.com/en/ds/MAX31856.pdf *** |
DevinAlexander | 1:b58719a76fc3 | 214 | */ |
DevinAlexander | 0:456e9e702d57 | 215 | |
DevinAlexander | 1:b58719a76fc3 | 216 | |
DevinAlexander | 8:8723d0006097 | 217 | /** |
DevinAlexander | 8:8723d0006097 | 218 | * MAX31856 Class |
DevinAlexander | 8:8723d0006097 | 219 | */ |
DevinAlexander | 0:456e9e702d57 | 220 | class MAX31856 |
DevinAlexander | 0:456e9e702d57 | 221 | { |
DevinAlexander | 1:b58719a76fc3 | 222 | |
DevinAlexander | 4:589401418bf0 | 223 | public: |
DevinAlexander | 8:8723d0006097 | 224 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 225 | //Constructor and Destructor for the class |
DevinAlexander | 8:8723d0006097 | 226 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 227 | /** |
DevinAlexander | 8:8723d0006097 | 228 | * @brief Constructor to create MAX31856 object with SPI information as well as preconfiguration parameter settings in configuration registers Zero and One |
DevinAlexander | 4:589401418bf0 | 229 | * @param _spi - Reference to SPI object |
DevinAlexander | 4:589401418bf0 | 230 | * @param _ncs - Chip Select for SPI comunications with the oject |
DevinAlexander | 4:589401418bf0 | 231 | * @param _type - Type of thermocouple used |
DevinAlexander | 4:589401418bf0 | 232 | * @param _fltr - Feature of the MAX31856 to filter out either 50Hz/60Hz from signal |
DevinAlexander | 4:589401418bf0 | 233 | * @param _samples - How many samples are averaged for one conversion |
DevinAlexander | 4:589401418bf0 | 234 | * @param _conversion_mode - Choose between always on and making conversions and off in between requests for a reading |
DevinAlexander | 4:589401418bf0 | 235 | */ |
DevinAlexander | 4:589401418bf0 | 236 | 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 | 237 | |
DevinAlexander | 8:8723d0006097 | 238 | |
DevinAlexander | 7:2e45068189b1 | 239 | /** @brief Destructor */ |
DevinAlexander | 7:2e45068189b1 | 240 | ~MAX31856(void); |
DevinAlexander | 4:589401418bf0 | 241 | |
DevinAlexander | 8:8723d0006097 | 242 | |
DevinAlexander | 7:2e45068189b1 | 243 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 244 | //Temperature Functions |
DevinAlexander | 7:2e45068189b1 | 245 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 246 | /** |
DevinAlexander | 4:589401418bf0 | 247 | * @brief Requests read of the thermocouple temperature |
DevinAlexander | 4:589401418bf0 | 248 | * @return float of the converted thermocouple reading based on current configurations |
DevinAlexander | 4:589401418bf0 | 249 | */ |
DevinAlexander | 4:589401418bf0 | 250 | float readTC(); |
DevinAlexander | 7:2e45068189b1 | 251 | |
DevinAlexander | 7:2e45068189b1 | 252 | |
DevinAlexander | 4:589401418bf0 | 253 | /** |
DevinAlexander | 4:589401418bf0 | 254 | * @brief Requests read of the cold junction temperature |
DevinAlexander | 4:589401418bf0 | 255 | * @return float of the converted artificial cold junction reading based on current configurations |
DevinAlexander | 4:589401418bf0 | 256 | */ |
DevinAlexander | 4:589401418bf0 | 257 | float readCJ(); |
DevinAlexander | 7:2e45068189b1 | 258 | |
DevinAlexander | 4:589401418bf0 | 259 | |
DevinAlexander | 7:2e45068189b1 | 260 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 261 | //Functions for register CR0 |
DevinAlexander | 7:2e45068189b1 | 262 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 263 | /** |
DevinAlexander | 4:589401418bf0 | 264 | * @brief Sets bits in the configuration register zero for setting the rate of conversions |
DevinAlexander | 8:8723d0006097 | 265 | * @param val \li CR0_CONV_MODE_NORMALLY_OFF (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 266 | * \li CR0_CONV_MODE_NORMALLY_ON |
DevinAlexander | 8:8723d0006097 | 267 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 268 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 269 | */ |
DevinAlexander | 4:589401418bf0 | 270 | bool setConversionMode(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 271 | |
DevinAlexander | 7:2e45068189b1 | 272 | |
DevinAlexander | 4:589401418bf0 | 273 | /** |
DevinAlexander | 4:589401418bf0 | 274 | * @brief Sets bits in the configuration register zero for enabling one conversion to take place |
DevinAlexander | 8:8723d0006097 | 275 | * @param val \li CR0_1_SHOT_MODE_NO_CONVERSION (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 276 | * \li CR0_1_SHOT_MODE_ONE_CONVERSION (This bit self clears itself to default back to CR0_1_SHOT_MODE_NO_CONVERSION after singular conversion takes place) |
DevinAlexander | 8:8723d0006097 | 277 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 278 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 279 | */ |
DevinAlexander | 4:589401418bf0 | 280 | bool setOneShotMode(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 281 | |
DevinAlexander | 7:2e45068189b1 | 282 | |
DevinAlexander | 4:589401418bf0 | 283 | /** |
DevinAlexander | 4:589401418bf0 | 284 | * @brief Sets bits in the configuration register zero for configuring open circuit fault detection |
DevinAlexander | 8:8723d0006097 | 285 | * @param val \li CR0_OC_DETECT_DISABLED (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 286 | * \li CR0_OC_DETECT_ENABLED_R_LESS_5k |
DevinAlexander | 8:8723d0006097 | 287 | * \li CR0_OC_DETECT_ENABLED_TC_LESS_2ms |
DevinAlexander | 8:8723d0006097 | 288 | * \li CR0_OC_DETECT_ENABLED_TC_MORE_2ms |
DevinAlexander | 8:8723d0006097 | 289 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 290 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 291 | */ |
DevinAlexander | 4:589401418bf0 | 292 | bool setOpenCircuitFaultDetection(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 293 | |
DevinAlexander | 7:2e45068189b1 | 294 | |
DevinAlexander | 4:589401418bf0 | 295 | /** |
DevinAlexander | 4:589401418bf0 | 296 | * @brief Sets bits in the configuration register zero for disabling or enabling the Cold Junction |
DevinAlexander | 8:8723d0006097 | 297 | * @param val \li CR0_COLD_JUNC_ENABLE (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 298 | * \li CR0_COLD_JUNC_DISABLE |
DevinAlexander | 8:8723d0006097 | 299 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 300 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 301 | */ |
DevinAlexander | 4:589401418bf0 | 302 | bool setColdJunctionDisable(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 303 | |
DevinAlexander | 7:2e45068189b1 | 304 | |
DevinAlexander | 4:589401418bf0 | 305 | /** |
DevinAlexander | 4:589401418bf0 | 306 | * @brief Sets bits in the configuration register zero for setting fault mode status |
DevinAlexander | 8:8723d0006097 | 307 | * @param val \li CR0_FAULT_MODE_COMPARATOR (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 308 | * \li CR0_FAULT_MODE_INTERUPT |
DevinAlexander | 8:8723d0006097 | 309 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 310 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 311 | */ |
DevinAlexander | 4:589401418bf0 | 312 | bool setFaultMode(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 313 | |
DevinAlexander | 7:2e45068189b1 | 314 | |
DevinAlexander | 4:589401418bf0 | 315 | /** |
DevinAlexander | 4:589401418bf0 | 316 | * @brief Sets bits in the configuration register zero for clearing fault status |
DevinAlexander | 8:8723d0006097 | 317 | * @param val \li CR0_FAULTCLR_DEFAULT_VAL (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 318 | * \li CR0_FAULTCLR_RETURN_FAULTS_TO_ZERO (This bit self clears itself to default back to CR0_FAULTCLR_DEFAULT_VAL after fault status is cleared) |
DevinAlexander | 8:8723d0006097 | 319 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 320 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 321 | */ |
DevinAlexander | 4:589401418bf0 | 322 | bool setFaultStatusClear(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 323 | |
DevinAlexander | 7:2e45068189b1 | 324 | |
DevinAlexander | 4:589401418bf0 | 325 | /** |
DevinAlexander | 4:589401418bf0 | 326 | * @brief Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation |
DevinAlexander | 8:8723d0006097 | 327 | * @param val \li CR0_FILTER_OUT_60Hz (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 328 | * \li CR0_FILTER_OUT_50Hz |
DevinAlexander | 8:8723d0006097 | 329 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 330 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 4:589401418bf0 | 331 | */ |
DevinAlexander | 4:589401418bf0 | 332 | bool setEmiFilterFreq(uint8_t val); |
DevinAlexander | 4:589401418bf0 | 333 | |
DevinAlexander | 6:e1200ae7d6a3 | 334 | |
DevinAlexander | 7:2e45068189b1 | 335 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 336 | //Functions for register CR1 |
DevinAlexander | 7:2e45068189b1 | 337 | //***************************************************************************** |
DevinAlexander | 6:e1200ae7d6a3 | 338 | /** |
DevinAlexander | 6:e1200ae7d6a3 | 339 | * @brief Sets bits in the configuration register one for setting how many readings are taken |
DevinAlexander | 8:8723d0006097 | 340 | * @param val \li CR1_AVG_TC_SAMPLES_1 (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 341 | * \li CR1_AVG_TC_SAMPLES_2 |
DevinAlexander | 8:8723d0006097 | 342 | * \li CR1_AVG_TC_SAMPLES_4 |
DevinAlexander | 8:8723d0006097 | 343 | * \li CR1_AVG_TC_SAMPLES_8 |
DevinAlexander | 8:8723d0006097 | 344 | * \li CR1_AVG_TC_SAMPLES_16 |
DevinAlexander | 8:8723d0006097 | 345 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 346 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 6:e1200ae7d6a3 | 347 | */ |
DevinAlexander | 4:589401418bf0 | 348 | bool setNumSamplesAvg(uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 349 | |
DevinAlexander | 7:2e45068189b1 | 350 | |
DevinAlexander | 6:e1200ae7d6a3 | 351 | /** |
DevinAlexander | 7:2e45068189b1 | 352 | * @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 | 8:8723d0006097 | 353 | * @param val \li CR1_TC_TYPE_B |
DevinAlexander | 8:8723d0006097 | 354 | * \li CR1_TC_TYPE_E |
DevinAlexander | 8:8723d0006097 | 355 | * \li CR1_TC_TYPE_J |
DevinAlexander | 8:8723d0006097 | 356 | * \li CR1_TC_TYPE_K (Power On Default value) |
DevinAlexander | 8:8723d0006097 | 357 | * \li CR1_TC_TYPE_N |
DevinAlexander | 8:8723d0006097 | 358 | * \li CR1_TC_TYPE_R |
DevinAlexander | 8:8723d0006097 | 359 | * \li CR1_TC_TYPE_S |
DevinAlexander | 8:8723d0006097 | 360 | * \li CR1_TC_TYPE_T |
DevinAlexander | 8:8723d0006097 | 361 | * \li CR1_TC_TYPE_VOLT_MODE_GAIN_8 |
DevinAlexander | 8:8723d0006097 | 362 | * \li CR1_TC_TYPE_VOLT_MODE_GAIN_32 |
DevinAlexander | 8:8723d0006097 | 363 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 364 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 6:e1200ae7d6a3 | 365 | */ |
DevinAlexander | 4:589401418bf0 | 366 | bool setThermocoupleType(uint8_t val); |
DevinAlexander | 4:589401418bf0 | 367 | |
DevinAlexander | 7:2e45068189b1 | 368 | |
DevinAlexander | 7:2e45068189b1 | 369 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 370 | //Functions for register MASK |
DevinAlexander | 7:2e45068189b1 | 371 | //***************************************************************************** |
DevinAlexander | 6:e1200ae7d6a3 | 372 | /** |
DevinAlexander | 7:2e45068189b1 | 373 | * @brief Sets bits in the configuration register one for setting fault masks |
DevinAlexander | 8:8723d0006097 | 374 | * @param val \li MASK_CJ_FAULT_THRESHOLD_HIGH |
DevinAlexander | 8:8723d0006097 | 375 | * \li MASK_CJ_FAULT_THRESHOLD_LOW |
DevinAlexander | 8:8723d0006097 | 376 | * \li MASK_TC_FAULT_THRESHOLD_HIGH |
DevinAlexander | 8:8723d0006097 | 377 | * \li MASK_TC_FAULT_THRESHOLD_LOW |
DevinAlexander | 8:8723d0006097 | 378 | * \li MASK_OVER_UNDER_VOLT_FAULT |
DevinAlexander | 8:8723d0006097 | 379 | * \li MASK_OPEN_CIRCUIT_FAULT |
DevinAlexander | 8:8723d0006097 | 380 | * @param enable \li 0 for disabling the mask in whichever option is selcted in parameter val |
DevinAlexander | 8:8723d0006097 | 381 | * \li 1 for enabling the mask in whichever option is selcted in parameter val |
DevinAlexander | 8:8723d0006097 | 382 | * @return \li 1 on success |
DevinAlexander | 8:8723d0006097 | 383 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 6:e1200ae7d6a3 | 384 | */ |
DevinAlexander | 4:589401418bf0 | 385 | bool setFaultMasks(uint8_t val, bool enable); |
DevinAlexander | 7:2e45068189b1 | 386 | |
DevinAlexander | 7:2e45068189b1 | 387 | |
DevinAlexander | 7:2e45068189b1 | 388 | /** |
DevinAlexander | 7:2e45068189b1 | 389 | * @brief Sets bits in the configuration register one for setting thresholds that corespond to the fault mask settings |
DevinAlexander | 8:8723d0006097 | 390 | * @param val \li MASK_CJ_FAULT_THRESHOLD_HIGH |
DevinAlexander | 8:8723d0006097 | 391 | * \li MASK_CJ_FAULT_THRESHOLD_LOW |
DevinAlexander | 8:8723d0006097 | 392 | * \li MASK_TC_FAULT_THRESHOLD_HIGH |
DevinAlexander | 8:8723d0006097 | 393 | * \li MASK_TC_FAULT_THRESHOLD_LOW |
DevinAlexander | 8:8723d0006097 | 394 | * \li MASK_OVER_UNDER_VOLT_FAULT |
DevinAlexander | 8:8723d0006097 | 395 | * \li MASK_OPEN_CIRCUIT_FAULT |
DevinAlexander | 8:8723d0006097 | 396 | * @param enable \li 0 for disabling the mask in whichever option is selcted in parameter val |
DevinAlexander | 8:8723d0006097 | 397 | * \li 1 for enabling the mask in whichever option is selcted in parameter val |
DevinAlexander | 8:8723d0006097 | 398 | * @param temperature value that you want to program into a threshold register for temperatre |
DevinAlexander | 8:8723d0006097 | 399 | * @return return value that was programmed into the threshold register |
DevinAlexander | 7:2e45068189b1 | 400 | */ |
DevinAlexander | 8:8723d0006097 | 401 | float setFaultThresholds(uint8_t val, bool enable, float temperature); |
DevinAlexander | 8:8723d0006097 | 402 | |
DevinAlexander | 8:8723d0006097 | 403 | |
DevinAlexander | 8:8723d0006097 | 404 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 405 | //Check Fault Status Functions |
DevinAlexander | 8:8723d0006097 | 406 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 407 | /** |
DevinAlexander | 8:8723d0006097 | 408 | * @brief Check the fault stautus register to see if there is anything wrong with range of thermocouple temperature |
DevinAlexander | 8:8723d0006097 | 409 | * whether outside opperating temperatures or if above/below thresholds that are set |
DevinAlexander | 8:8723d0006097 | 410 | * @return \li 0 if no faults are present |
DevinAlexander | 8:8723d0006097 | 411 | * \li 1 if Thermocouple temp is higher than the threshold |
DevinAlexander | 8:8723d0006097 | 412 | * \li 2 if Thermocouple temp is lower than the threshold |
DevinAlexander | 8:8723d0006097 | 413 | * \li 3 if Thermocouple temp is outside operating range of termocouple type |
DevinAlexander | 8:8723d0006097 | 414 | * \li 4 if Thermocouple temp is higher than the threshold && is outside operating range of termocouple type |
DevinAlexander | 8:8723d0006097 | 415 | * \li 5 if Thermocouple temp is lower than the threshold && is outside operating range of termocouple type |
DevinAlexander | 8:8723d0006097 | 416 | */ |
DevinAlexander | 8:8723d0006097 | 417 | uint8_t checkFaultsThermocoupleThresholds(); |
DevinAlexander | 8:8723d0006097 | 418 | |
DevinAlexander | 8:8723d0006097 | 419 | |
DevinAlexander | 8:8723d0006097 | 420 | /** |
DevinAlexander | 8:8723d0006097 | 421 | * @brief Check the fault stautus register to see if there is anything wrong with range of cold junction temperature |
DevinAlexander | 8:8723d0006097 | 422 | * whether outside opperating temperatures or if above/below thresholds that are set |
DevinAlexander | 8:8723d0006097 | 423 | * @return \li 0 if no faults are present |
DevinAlexander | 8:8723d0006097 | 424 | * \li 1 if Cold Junction temp is higher than the threshold |
DevinAlexander | 8:8723d0006097 | 425 | * \li 2 if Cold Junction temp is lower than the threshold |
DevinAlexander | 8:8723d0006097 | 426 | * \li 3 if Cold Junction temp is outside operating range of termocouple type |
DevinAlexander | 8:8723d0006097 | 427 | * \li 4 if Cold Junction temp is higher than the threshold && is outside operating range of termocouple type |
DevinAlexander | 8:8723d0006097 | 428 | * \li 5 if Cold Junction temp is lower than the threshold && is outside operating range of termocouple type |
DevinAlexander | 8:8723d0006097 | 429 | */ |
DevinAlexander | 8:8723d0006097 | 430 | uint8_t checkFaultsColdJunctionThresholds(); |
DevinAlexander | 8:8723d0006097 | 431 | |
DevinAlexander | 8:8723d0006097 | 432 | |
DevinAlexander | 8:8723d0006097 | 433 | /** |
DevinAlexander | 8:8723d0006097 | 434 | * @brief Check the fault stautus register to see if there is anything wrong with thermocouple connection to the MAX31856 |
DevinAlexander | 8:8723d0006097 | 435 | * @return \li 1 if no faults are present |
DevinAlexander | 8:8723d0006097 | 436 | * \li 0 if there is a fault and there needs to be information printed to the console to help diagnose issues |
DevinAlexander | 8:8723d0006097 | 437 | */ |
DevinAlexander | 8:8723d0006097 | 438 | bool checkFaultsThermocoupleConnection(); |
DevinAlexander | 4:589401418bf0 | 439 | |
DevinAlexander | 4:589401418bf0 | 440 | |
DevinAlexander | 7:2e45068189b1 | 441 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 442 | //General Functions |
DevinAlexander | 7:2e45068189b1 | 443 | //***************************************************************************** |
DevinAlexander | 4:589401418bf0 | 444 | /** |
DevinAlexander | 4:589401418bf0 | 445 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 8:8723d0006097 | 446 | * \li Read the value of a register from contents of register matching the parameter read_address |
DevinAlexander | 8:8723d0006097 | 447 | * \li Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits |
DevinAlexander | 8:8723d0006097 | 448 | * \li Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val |
DevinAlexander | 8:8723d0006097 | 449 | * \li Rewrite to the register with the new 8 bit value to the register with the address with parameter write_address |
DevinAlexander | 4:589401418bf0 | 450 | * @param read_address - Address of register to read the data before it's changed |
DevinAlexander | 4:589401418bf0 | 451 | * @param write_address - Address of register to rewrite the changed data |
DevinAlexander | 4:589401418bf0 | 452 | * @param clear_bits - Parameter that is |
DevinAlexander | 4:589401418bf0 | 453 | * @param val - Bitfield that contains bits related to function specific settings |
DevinAlexander | 8:8723d0006097 | 454 | * @return \li 1 on success |
DevinAlexander | 4:589401418bf0 | 455 | */ |
DevinAlexander | 4:589401418bf0 | 456 | bool registerReadWriteByte(uint8_t read_address, uint8_t write_address, uint8_t clear_bits, uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 457 | |
DevinAlexander | 7:2e45068189b1 | 458 | |
DevinAlexander | 4:589401418bf0 | 459 | /** |
DevinAlexander | 4:589401418bf0 | 460 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 8:8723d0006097 | 461 | * \li Read the value of a register from contents of register matching the parameter read_address |
DevinAlexander | 8:8723d0006097 | 462 | * \li Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits |
DevinAlexander | 8:8723d0006097 | 463 | * \li Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val |
DevinAlexander | 8:8723d0006097 | 464 | * \li Write to the register with the new 8 bit value to the register with the address with parameter write_address |
DevinAlexander | 4:589401418bf0 | 465 | * @param write_address - Address of register to rewrite the changed data |
DevinAlexander | 8:8723d0006097 | 466 | * @param val - Byte of information that is going to be written to the regitser with the address that matches the parameter write_address |
DevinAlexander | 8:8723d0006097 | 467 | * @return \li 1 on success |
DevinAlexander | 4:589401418bf0 | 468 | */ |
DevinAlexander | 4:589401418bf0 | 469 | bool registerWriteByte(uint8_t write_address, uint8_t val); |
DevinAlexander | 7:2e45068189b1 | 470 | |
DevinAlexander | 7:2e45068189b1 | 471 | |
DevinAlexander | 4:589401418bf0 | 472 | /** |
DevinAlexander | 8:8723d0006097 | 473 | * @brief This function is to read current contents of register by passing in the address of the read address and return contents of the register |
DevinAlexander | 8:8723d0006097 | 474 | * @param read_address - Address of register to read data from |
DevinAlexander | 8:8723d0006097 | 475 | * @return \li byte contained in the address |
DevinAlexander | 4:589401418bf0 | 476 | */ |
DevinAlexander | 8:8723d0006097 | 477 | uint8_t registerReadByte(uint8_t read_address); |
DevinAlexander | 8:8723d0006097 | 478 | |
DevinAlexander | 8:8723d0006097 | 479 | |
DevinAlexander | 4:589401418bf0 | 480 | /** |
DevinAlexander | 8:8723d0006097 | 481 | * @brief This function is to read current contents of register by passing in the address of the read address and return contents of the register |
DevinAlexander | 8:8723d0006097 | 482 | * @param temperature - Float of value to offest the value of the cold junction offset by (must be between -8°C to +7.9375°C) |
DevinAlexander | 8:8723d0006097 | 483 | * @return \li 1 on successfully updated coldjunction offset |
DevinAlexander | 8:8723d0006097 | 484 | * \li 0 if parameter temperature does not fall between range -8°C to +7.9375°C |
DevinAlexander | 4:589401418bf0 | 485 | */ |
DevinAlexander | 8:8723d0006097 | 486 | bool coldJunctionOffset(float temperature); |
DevinAlexander | 4:589401418bf0 | 487 | |
DevinAlexander | 7:2e45068189b1 | 488 | |
DevinAlexander | 7:2e45068189b1 | 489 | private: |
DevinAlexander | 7:2e45068189b1 | 490 | |
DevinAlexander | 7:2e45068189b1 | 491 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 492 | //Private Functions |
DevinAlexander | 7:2e45068189b1 | 493 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 494 | /** @brief Writes the chip seleect pin low to begin SPI communications */ |
DevinAlexander | 7:2e45068189b1 | 495 | void spiEnable(); |
DevinAlexander | 7:2e45068189b1 | 496 | |
DevinAlexander | 7:2e45068189b1 | 497 | |
DevinAlexander | 7:2e45068189b1 | 498 | /** @brief Writes the chip seleect pin high to end SPI communications */ |
DevinAlexander | 7:2e45068189b1 | 499 | void spiDisable(); |
DevinAlexander | 7:2e45068189b1 | 500 | |
DevinAlexander | 8:8723d0006097 | 501 | /** @brief Calculates minimum wait time for a conversion to take place */ |
DevinAlexander | 8:8723d0006097 | 502 | void calculateDelayTime(); |
DevinAlexander | 8:8723d0006097 | 503 | |
DevinAlexander | 7:2e45068189b1 | 504 | |
DevinAlexander | 7:2e45068189b1 | 505 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 506 | //Private Members |
DevinAlexander | 7:2e45068189b1 | 507 | //***************************************************************************** |
DevinAlexander | 7:2e45068189b1 | 508 | /// SPI object |
DevinAlexander | 7:2e45068189b1 | 509 | SPI& spi; |
DevinAlexander | 7:2e45068189b1 | 510 | |
DevinAlexander | 8:8723d0006097 | 511 | /// Chip select pin for SPI communications |
DevinAlexander | 7:2e45068189b1 | 512 | DigitalOut ncs; |
DevinAlexander | 7:2e45068189b1 | 513 | |
DevinAlexander | 7:2e45068189b1 | 514 | /// Number of samples the thermocouple is configured to average |
DevinAlexander | 7:2e45068189b1 | 515 | uint8_t samples; |
DevinAlexander | 7:2e45068189b1 | 516 | |
DevinAlexander | 7:2e45068189b1 | 517 | /// 0=thermocouple is set to one of 8 thermocouple types and 1=Thermocouple is configured to report in voltage mode |
DevinAlexander | 7:2e45068189b1 | 518 | bool voltage_mode; |
DevinAlexander | 7:2e45068189b1 | 519 | |
DevinAlexander | 7:2e45068189b1 | 520 | /// 0=60Hz and 1=50Hz |
DevinAlexander | 7:2e45068189b1 | 521 | bool filter_mode; |
DevinAlexander | 7:2e45068189b1 | 522 | |
DevinAlexander | 8:8723d0006097 | 523 | /// 0=MAX31856 is off, so no conversion is taking place currently and 1=Always On and converting |
DevinAlexander | 7:2e45068189b1 | 524 | bool conversion_mode; |
DevinAlexander | 7:2e45068189b1 | 525 | |
DevinAlexander | 7:2e45068189b1 | 526 | /// 0=cold junction is disabled and 1=cold junction is enabled |
DevinAlexander | 7:2e45068189b1 | 527 | bool cold_junction_enabled; |
DevinAlexander | 7:2e45068189b1 | 528 | |
DevinAlexander | 4:589401418bf0 | 529 | ///Define a return val for all boolean functions |
DevinAlexander | 4:589401418bf0 | 530 | bool return_val; |
DevinAlexander | 4:589401418bf0 | 531 | |
DevinAlexander | 7:2e45068189b1 | 532 | ///Used to figure out when a new conversion is ready to go |
DevinAlexander | 0:456e9e702d57 | 533 | uint32_t lastReadTime; |
DevinAlexander | 8:8723d0006097 | 534 | |
DevinAlexander | 8:8723d0006097 | 535 | ///How many conversions have taken place since conversion mode was switched into auto mode |
DevinAlexander | 8:8723d0006097 | 536 | ///Also this value should be 0 if the mode is in oneshot mode |
DevinAlexander | 8:8723d0006097 | 537 | uint32_t thermocouple_conversion_count; |
DevinAlexander | 8:8723d0006097 | 538 | |
DevinAlexander | 8:8723d0006097 | 539 | ///time in milliseconds that is needed minimum for a new conversion to take place |
DevinAlexander | 8:8723d0006097 | 540 | uint32_t conversion_time; |
DevinAlexander | 0:456e9e702d57 | 541 | }; |
DevinAlexander | 0:456e9e702d57 | 542 | |
DevinAlexander | 8:8723d0006097 | 543 | #endif /* __MAX31856_H_ */ |
DevinAlexander | 8:8723d0006097 | 544 | |
DevinAlexander | 8:8723d0006097 | 545 | |
DevinAlexander | 8:8723d0006097 | 546 | |
DevinAlexander | 8:8723d0006097 | 547 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 548 | //EXTRA |
DevinAlexander | 8:8723d0006097 | 549 | //***************************************************************************** |
DevinAlexander | 8:8723d0006097 | 550 | // /** |
DevinAlexander | 8:8723d0006097 | 551 | // * @brief Check the fault stautus register to see if there is anything wrong with thermocouple connections or if there are any faults |
DevinAlexander | 8:8723d0006097 | 552 | // * @return \li 1 if no faults are present |
DevinAlexander | 8:8723d0006097 | 553 | // * \li 0 if there is a fault and there needs to be information printed to the console to help diagnose issues |
DevinAlexander | 8:8723d0006097 | 554 | // */ |
DevinAlexander | 8:8723d0006097 | 555 | // bool checkFaultsAll(); |
DevinAlexander | 8:8723d0006097 | 556 | // |
DevinAlexander | 8:8723d0006097 | 557 | // /** |
DevinAlexander | 8:8723d0006097 | 558 | // * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 8:8723d0006097 | 559 | // * \li Read the value of a register from contents of register matching the parameter read_address |
DevinAlexander | 8:8723d0006097 | 560 | // * \li Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits |
DevinAlexander | 8:8723d0006097 | 561 | // * \li Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val |
DevinAlexander | 8:8723d0006097 | 562 | // * \li Rewrite to the register with the new 8 bit value to the register with the address with parameter write_address |
DevinAlexander | 8:8723d0006097 | 563 | // * @param temp - value to be converted |
DevinAlexander | 8:8723d0006097 | 564 | // * @return \li converted 2's complement value to 8 bit signed integer |
DevinAlexander | 8:8723d0006097 | 565 | // */ |
DevinAlexander | 8:8723d0006097 | 566 | // int8_t twosComplimentToSigned8(int8_t temp); |
DevinAlexander | 8:8723d0006097 | 567 | // |
DevinAlexander | 8:8723d0006097 | 568 | // |
DevinAlexander | 8:8723d0006097 | 569 | // /** |
DevinAlexander | 8:8723d0006097 | 570 | // * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 8:8723d0006097 | 571 | // * \li Read the value of a register from contents of register matching the parameter read_address |
DevinAlexander | 8:8723d0006097 | 572 | // * \li Clear the bits needed to be changed by bitwise ANDing the read value with the 16 bit parameter clear_bits |
DevinAlexander | 8:8723d0006097 | 573 | // * \li Set the bits of interest in the 16 bit value by bitwise ORing the value from step two with parameter val |
DevinAlexander | 8:8723d0006097 | 574 | // * \li Rewrite to the register with the new 16 bit value to the register with the address with parameter write_address |
DevinAlexander | 8:8723d0006097 | 575 | // * @param temp - value to be converted |
DevinAlexander | 8:8723d0006097 | 576 | // * @return \li converted 2's complement value to 16 bit signed integer |
DevinAlexander | 8:8723d0006097 | 577 | // */ |
DevinAlexander | 8:8723d0006097 | 578 | // int16_t twosComplimentToSigned16(int16_t temp); |