Library for the MAX31856 Precision Thermocouple to Digital Converter with Linearization
Dependents: MAX31856_example_program
Fork of MAX31856 by
MAX31856.h@1:a1bbb5c254f2, 2017-09-14 (annotated)
- Committer:
- DevinAlexander
- Date:
- Thu Sep 14 18:08:20 2017 +0000
- Revision:
- 1:a1bbb5c254f2
- Parent:
- 0:b714c6a7c969
Final first revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DevinAlexander | 1:a1bbb5c254f2 | 1 | /******************************************************************//** |
DevinAlexander | 1:a1bbb5c254f2 | 2 | * @file MAX31856.h |
DevinAlexander | 1:a1bbb5c254f2 | 3 | * |
DevinAlexander | 1:a1bbb5c254f2 | 4 | * @author Devin Alexander |
DevinAlexander | 1:a1bbb5c254f2 | 5 | * |
DevinAlexander | 1:a1bbb5c254f2 | 6 | * @version 1.0 |
DevinAlexander | 1:a1bbb5c254f2 | 7 | * |
DevinAlexander | 1:a1bbb5c254f2 | 8 | * Started: SEPTEMBER 14th 2017 |
DevinAlexander | 1:a1bbb5c254f2 | 9 | * |
DevinAlexander | 1:a1bbb5c254f2 | 10 | * Updated: |
DevinAlexander | 1:a1bbb5c254f2 | 11 | * |
DevinAlexander | 1:a1bbb5c254f2 | 12 | * @brief Header file for MAX31856 class |
DevinAlexander | 1:a1bbb5c254f2 | 13 | * |
DevinAlexander | 1:a1bbb5c254f2 | 14 | *********************************************************************** |
DevinAlexander | 1:a1bbb5c254f2 | 15 | * |
DevinAlexander | 1:a1bbb5c254f2 | 16 | * @copyright |
DevinAlexander | 1:a1bbb5c254f2 | 17 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
DevinAlexander | 1:a1bbb5c254f2 | 18 | * |
DevinAlexander | 1:a1bbb5c254f2 | 19 | * Permission is hereby granted, free of charge, to any person obtaining a |
DevinAlexander | 1:a1bbb5c254f2 | 20 | * copy of this software and associated documentation files (the "Software"), |
DevinAlexander | 1:a1bbb5c254f2 | 21 | * to deal in the Software without restriction, including without limitation |
DevinAlexander | 1:a1bbb5c254f2 | 22 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
DevinAlexander | 1:a1bbb5c254f2 | 23 | * and/or sell copies of the Software, and to permit persons to whom the |
DevinAlexander | 1:a1bbb5c254f2 | 24 | * Software is furnished to do so, subject to the following conditions: |
DevinAlexander | 1:a1bbb5c254f2 | 25 | * |
DevinAlexander | 1:a1bbb5c254f2 | 26 | * The above copyright notice and this permission notice shall be included |
DevinAlexander | 1:a1bbb5c254f2 | 27 | * in all copies or substantial portions of the Software. |
DevinAlexander | 1:a1bbb5c254f2 | 28 | * |
DevinAlexander | 1:a1bbb5c254f2 | 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
DevinAlexander | 1:a1bbb5c254f2 | 30 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
DevinAlexander | 1:a1bbb5c254f2 | 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
DevinAlexander | 1:a1bbb5c254f2 | 32 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
DevinAlexander | 1:a1bbb5c254f2 | 33 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
DevinAlexander | 1:a1bbb5c254f2 | 34 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
DevinAlexander | 1:a1bbb5c254f2 | 35 | * OTHER DEALINGS IN THE SOFTWARE. |
DevinAlexander | 1:a1bbb5c254f2 | 36 | * |
DevinAlexander | 1:a1bbb5c254f2 | 37 | * Except as contained in this notice, the name of Maxim Integrated |
DevinAlexander | 1:a1bbb5c254f2 | 38 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
DevinAlexander | 1:a1bbb5c254f2 | 39 | * Products, Inc. Branding Policy. |
DevinAlexander | 1:a1bbb5c254f2 | 40 | * |
DevinAlexander | 1:a1bbb5c254f2 | 41 | * The mere transfer of this software does not imply any licenses |
DevinAlexander | 1:a1bbb5c254f2 | 42 | * of trade secrets, proprietary technology, copyrights, patents, |
DevinAlexander | 1:a1bbb5c254f2 | 43 | * trademarks, maskwork rights, or any other form of intellectual |
DevinAlexander | 1:a1bbb5c254f2 | 44 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
DevinAlexander | 1:a1bbb5c254f2 | 45 | * ownership rights. |
DevinAlexander | 1:a1bbb5c254f2 | 46 | **********************************************************************/ |
DevinAlexander | 1:a1bbb5c254f2 | 47 | |
DevinAlexander | 1:a1bbb5c254f2 | 48 | |
DevinAlexander | 0:b714c6a7c969 | 49 | #ifndef MAX31856_h |
DevinAlexander | 0:b714c6a7c969 | 50 | #define MAX31856_h |
DevinAlexander | 0:b714c6a7c969 | 51 | #include "mbed.h" |
DevinAlexander | 0:b714c6a7c969 | 52 | |
DevinAlexander | 0:b714c6a7c969 | 53 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 54 | //Define all the addresses of the registers in the MAX31856 |
DevinAlexander | 0:b714c6a7c969 | 55 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 56 | #define ADDRESS_CR0_READ 0x00 //Factory Default 00h |
DevinAlexander | 0:b714c6a7c969 | 57 | #define ADDRESS_CR0_WRITE 0x80 |
DevinAlexander | 0:b714c6a7c969 | 58 | #define ADDRESS_CR1_READ 0x01 //Factory Default 03h |
DevinAlexander | 0:b714c6a7c969 | 59 | #define ADDRESS_CR1_WRITE 0x81 |
DevinAlexander | 0:b714c6a7c969 | 60 | #define ADDRESS_MASK_READ 0x02 //Factory Default FFh |
DevinAlexander | 0:b714c6a7c969 | 61 | #define ADDRESS_MASK_WRITE 0x82 |
DevinAlexander | 0:b714c6a7c969 | 62 | #define ADDRESS_CJHF_READ 0x03 //Factory Default 7Fh |
DevinAlexander | 0:b714c6a7c969 | 63 | #define ADDRESS_CJHF_WRITE 0x83 |
DevinAlexander | 0:b714c6a7c969 | 64 | #define ADDRESS_CJLF_READ 0x04 //Factory Default C0h |
DevinAlexander | 0:b714c6a7c969 | 65 | #define ADDRESS_CJLF_WRITE 0x84 |
DevinAlexander | 0:b714c6a7c969 | 66 | #define ADDRESS_LTHFTH_READ 0x05 //Factory Default 7Fh |
DevinAlexander | 0:b714c6a7c969 | 67 | #define ADDRESS_LTHFTH_WRITE 0x85 |
DevinAlexander | 0:b714c6a7c969 | 68 | #define ADDRESS_LTHFTL_READ 0x06 //Factory Default FFh |
DevinAlexander | 0:b714c6a7c969 | 69 | #define ADDRESS_LTHFTL_WRITE 0x86 |
DevinAlexander | 0:b714c6a7c969 | 70 | #define ADDRESS_LTLFTH_READ 0x07 //Factory Default 80h |
DevinAlexander | 0:b714c6a7c969 | 71 | #define ADDRESS_LTLFTH_WRITE 0x87 |
DevinAlexander | 0:b714c6a7c969 | 72 | #define ADDRESS_LTLFTL_READ 0x08 //Factory Default 00h |
DevinAlexander | 0:b714c6a7c969 | 73 | #define ADDRESS_LTLFTL_WRITE 0x88 |
DevinAlexander | 0:b714c6a7c969 | 74 | #define ADDRESS_CJTO_READ 0x09 //Factory Default 00h |
DevinAlexander | 0:b714c6a7c969 | 75 | #define ADDRESS_CJTO_WRITE 0x89 |
DevinAlexander | 0:b714c6a7c969 | 76 | #define ADDRESS_CJTH_READ 0x0A //Factory Default 00h |
DevinAlexander | 0:b714c6a7c969 | 77 | #define ADDRESS_CJTH_WRITE 0x8A |
DevinAlexander | 0:b714c6a7c969 | 78 | #define ADDRESS_CJTL_READ 0x0B //Factory Default 00h |
DevinAlexander | 0:b714c6a7c969 | 79 | #define ADDRESS_CJTL_WRITE 0x8B |
DevinAlexander | 0:b714c6a7c969 | 80 | #define ADDRESS_LTCBH_READ 0x0C |
DevinAlexander | 0:b714c6a7c969 | 81 | #define ADDRESS_LTCBM_READ 0x0D |
DevinAlexander | 0:b714c6a7c969 | 82 | #define ADDRESS_LTCBL_READ 0x0E |
DevinAlexander | 0:b714c6a7c969 | 83 | #define ADDRESS_SR_READ 0x0F |
DevinAlexander | 0:b714c6a7c969 | 84 | |
DevinAlexander | 0:b714c6a7c969 | 85 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 86 | //Define parameters for control register zero (CR0) |
DevinAlexander | 0:b714c6a7c969 | 87 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 88 | #define CR0_CONV_MODE_NORMALLY_OFF 0x00 //Power On Default value |
DevinAlexander | 0:b714c6a7c969 | 89 | #define CR0_CONV_MODE_NORMALLY_ON 0x80 |
DevinAlexander | 0:b714c6a7c969 | 90 | |
DevinAlexander | 0:b714c6a7c969 | 91 | #define CR0_1_SHOT_MODE_NO_CONVERSION 0x00 //defaults to this value |
DevinAlexander | 0:b714c6a7c969 | 92 | #define CR0_1_SHOT_MODE_ONE_CONVERSION 0x40 //^ |
DevinAlexander | 0:b714c6a7c969 | 93 | |
DevinAlexander | 0:b714c6a7c969 | 94 | #define CR0_OC_DETECT_DISABLED 0x00 |
DevinAlexander | 0:b714c6a7c969 | 95 | #define CR0_OC_DETECT_ENABLED_R_LESS_5k 0x10 |
DevinAlexander | 0:b714c6a7c969 | 96 | #define CR0_OC_DETECT_ENABLED_TC_LESS_2ms 0x20 |
DevinAlexander | 0:b714c6a7c969 | 97 | #define CR0_OC_DETECT_ENABLED_TC_MORE_2ms 0x30 |
DevinAlexander | 0:b714c6a7c969 | 98 | |
DevinAlexander | 0:b714c6a7c969 | 99 | #define CR0_COLD_JUNC_ENABLE 0x00 //Power On Default value |
DevinAlexander | 0:b714c6a7c969 | 100 | #define CR0_COLD_JUNC_DISABLE 0x08 //speed of conversion is sped up by 25ms when this optionis selected (Disable the cold junc) |
DevinAlexander | 0:b714c6a7c969 | 101 | |
DevinAlexander | 0:b714c6a7c969 | 102 | #define CR0_FAULT_MODE_COMPARATOR 0x00 //Power On Default value |
DevinAlexander | 0:b714c6a7c969 | 103 | #define CR0_FAULT_MODE_INTERUPT 0x04 |
DevinAlexander | 0:b714c6a7c969 | 104 | |
DevinAlexander | 0:b714c6a7c969 | 105 | #define CR0_FAULTCLR_DEFAULT_VAL 0x00 //defaults to this value |
DevinAlexander | 0:b714c6a7c969 | 106 | #define CR0_FAULTCLR_RETURN_FAULTS_TO_ZERO 0x02 //^ |
DevinAlexander | 0:b714c6a7c969 | 107 | |
DevinAlexander | 0:b714c6a7c969 | 108 | #define CR0_FILTER_OUT_60Hz 0x00 //Preset value |
DevinAlexander | 0:b714c6a7c969 | 109 | #define CR0_FILTER_OUT_50Hz 0x01 //^ |
DevinAlexander | 0:b714c6a7c969 | 110 | |
DevinAlexander | 0:b714c6a7c969 | 111 | |
DevinAlexander | 0:b714c6a7c969 | 112 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 113 | //Define parameters for control register one (CR1) |
DevinAlexander | 0:b714c6a7c969 | 114 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 115 | #define CR1_AVG_TC_SAMPLES_1 0x00 //Power on default value |
DevinAlexander | 0:b714c6a7c969 | 116 | #define CR1_AVG_TC_SAMPLES_2 0x10 |
DevinAlexander | 0:b714c6a7c969 | 117 | #define CR1_AVG_TC_SAMPLES_4 0x20 |
DevinAlexander | 0:b714c6a7c969 | 118 | #define CR1_AVG_TC_SAMPLES_8 0x30 |
DevinAlexander | 0:b714c6a7c969 | 119 | #define CR1_AVG_TC_SAMPLES_16 0x40 |
DevinAlexander | 0:b714c6a7c969 | 120 | |
DevinAlexander | 0:b714c6a7c969 | 121 | // Define which type of thermocouple the MAX31856 is using. This is for lineariztion purposes |
DevinAlexander | 0:b714c6a7c969 | 122 | #define CR1_TC_TYPE_B 0x00 |
DevinAlexander | 0:b714c6a7c969 | 123 | #define CR1_TC_TYPE_E 0x01 |
DevinAlexander | 0:b714c6a7c969 | 124 | #define CR1_TC_TYPE_J 0x02 |
DevinAlexander | 0:b714c6a7c969 | 125 | #define CR1_TC_TYPE_K 0x03 //Power on default value |
DevinAlexander | 0:b714c6a7c969 | 126 | #define CR1_TC_TYPE_N 0x04 |
DevinAlexander | 0:b714c6a7c969 | 127 | #define CR1_TC_TYPE_R 0x05 |
DevinAlexander | 0:b714c6a7c969 | 128 | #define CR1_TC_TYPE_S 0x06 |
DevinAlexander | 0:b714c6a7c969 | 129 | #define CR1_TC_TYPE_T 0x07 |
DevinAlexander | 0:b714c6a7c969 | 130 | #define CR1_TC_TYPE_VOLT_MODE_GAIN_8 0x08 |
DevinAlexander | 0:b714c6a7c969 | 131 | #define CR1_TC_TYPE_VOLT_MODE_GAIN_32 0x0C |
DevinAlexander | 0:b714c6a7c969 | 132 | |
DevinAlexander | 0:b714c6a7c969 | 133 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 134 | //Define parameters for the mask register (MASK) |
DevinAlexander | 0:b714c6a7c969 | 135 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 136 | #define MASK_CJ_FAULT_THRESHOLD_HIGH 0x20 |
DevinAlexander | 0:b714c6a7c969 | 137 | #define MASK_CJ_FAULT_THRESHOLD_LOW 0x10 |
DevinAlexander | 0:b714c6a7c969 | 138 | #define MASK_TC_FAULT_THRESHOLD_HIGH 0x08 |
DevinAlexander | 0:b714c6a7c969 | 139 | #define MASK_TC_FAULT_THRESHOLD_LOW 0x04 |
DevinAlexander | 0:b714c6a7c969 | 140 | #define MASK_OVER_UNDER_VOLT_FAULT 0x02 |
DevinAlexander | 0:b714c6a7c969 | 141 | #define MASK_OPEN_CIRCUIT_FAULT 0x01 |
DevinAlexander | 0:b714c6a7c969 | 142 | |
DevinAlexander | 0:b714c6a7c969 | 143 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 144 | //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 | 0:b714c6a7c969 | 145 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 146 | #define CR0_CLEAR_BITS_7 ~(0x80) |
DevinAlexander | 0:b714c6a7c969 | 147 | #define CR0_CLEAR_BITS_6 ~(0x40) |
DevinAlexander | 0:b714c6a7c969 | 148 | #define CR0_CLEAR_BITS_5_4 ~(0x30) |
DevinAlexander | 0:b714c6a7c969 | 149 | #define CR0_CLEAR_BITS_3 ~(0x08) |
DevinAlexander | 0:b714c6a7c969 | 150 | #define CR0_CLEAR_BITS_2 ~(0x04) |
DevinAlexander | 0:b714c6a7c969 | 151 | #define CR0_CLEAR_BITS_1 ~(0x02) |
DevinAlexander | 0:b714c6a7c969 | 152 | #define CR0_CLEAR_BITS_0 ~(0x01) |
DevinAlexander | 0:b714c6a7c969 | 153 | |
DevinAlexander | 0:b714c6a7c969 | 154 | #define CR1_CLEAR_BITS_6_4 ~(0x70) |
DevinAlexander | 0:b714c6a7c969 | 155 | #define CR1_CLEAR_BITS_3_0 ~(0x0F) |
DevinAlexander | 0:b714c6a7c969 | 156 | |
DevinAlexander | 0:b714c6a7c969 | 157 | #define MASK_CLEAR_BITS_5 ~(0x20) |
DevinAlexander | 0:b714c6a7c969 | 158 | #define MASK_CLEAR_BITS_4 ~(0x10) |
DevinAlexander | 0:b714c6a7c969 | 159 | #define MASK_CLEAR_BITS_3 ~(0x08) |
DevinAlexander | 0:b714c6a7c969 | 160 | #define MASK_CLEAR_BITS_2 ~(0x04) |
DevinAlexander | 0:b714c6a7c969 | 161 | #define MASK_CLEAR_BITS_1 ~(0x02) |
DevinAlexander | 0:b714c6a7c969 | 162 | #define MASK_CLEAR_BITS_0 ~(0x01) |
DevinAlexander | 0:b714c6a7c969 | 163 | |
DevinAlexander | 0:b714c6a7c969 | 164 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 165 | ///Parameters that are used throughout the library |
DevinAlexander | 0:b714c6a7c969 | 166 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 167 | #define TC_MAX_VAL_FAULT 1800 |
DevinAlexander | 0:b714c6a7c969 | 168 | #define TC_MIN_VAL_FAULT -210 |
DevinAlexander | 0:b714c6a7c969 | 169 | #define CJ_MAX_VAL_FAULT 125 |
DevinAlexander | 0:b714c6a7c969 | 170 | #define CJ_MIN_VAL_FAULT -55 |
DevinAlexander | 0:b714c6a7c969 | 171 | |
DevinAlexander | 0:b714c6a7c969 | 172 | |
DevinAlexander | 0:b714c6a7c969 | 173 | |
DevinAlexander | 0:b714c6a7c969 | 174 | /** |
DevinAlexander | 0:b714c6a7c969 | 175 | * @brief Library for the MAX31856\n |
DevinAlexander | 0:b714c6a7c969 | 176 | * The MAX31856 thermocouple temperature sensor accurately measures temperature |
DevinAlexander | 0:b714c6a7c969 | 177 | * and provides a vast amount of features such as: |
DevinAlexander | 0:b714c6a7c969 | 178 | * //FEATURE |
DevinAlexander | 0:b714c6a7c969 | 179 | * //FEATURE |
DevinAlexander | 0:b714c6a7c969 | 180 | * //FEATURE |
DevinAlexander | 0:b714c6a7c969 | 181 | * //FEATURE |
DevinAlexander | 0:b714c6a7c969 | 182 | * //FEATURE |
DevinAlexander | 0:b714c6a7c969 | 183 | * //FEATURE |
DevinAlexander | 0:b714c6a7c969 | 184 | * Communication is through an SPI-compatible interface. |
DevinAlexander | 0:b714c6a7c969 | 185 | * |
DevinAlexander | 0:b714c6a7c969 | 186 | * @code |
DevinAlexander | 0:b714c6a7c969 | 187 | * #include "mbed.h" |
DevinAlexander | 0:b714c6a7c969 | 188 | * #include "MAX31856.h" |
DevinAlexander | 0:b714c6a7c969 | 189 | * |
DevinAlexander | 0:b714c6a7c969 | 190 | * |
DevinAlexander | 0:b714c6a7c969 | 191 | * // Hardware serial port |
DevinAlexander | 0:b714c6a7c969 | 192 | * Serial serial(USBTX, USBRX); |
DevinAlexander | 0:b714c6a7c969 | 193 | * |
DevinAlexander | 0:b714c6a7c969 | 194 | * //SPI communications |
DevinAlexander | 0:b714c6a7c969 | 195 | * SPI spi(SPIO MOSI,SPIO MISO,SPIO SCK); |
DevinAlexander | 0:b714c6a7c969 | 196 | * |
DevinAlexander | 0:b714c6a7c969 | 197 | * //Thermocouples |
DevinAlexander | 0:b714c6a7c969 | 198 | * MAX31856 Thermocouple1(spi, CHIPSELECT); |
DevinAlexander | 0:b714c6a7c969 | 199 | * |
DevinAlexander | 0:b714c6a7c969 | 200 | * |
DevinAlexander | 0:b714c6a7c969 | 201 | * int main(void) |
DevinAlexander | 0:b714c6a7c969 | 202 | * { |
DevinAlexander | 0:b714c6a7c969 | 203 | * float temperature_TC_1, temperature_CJ_1; |
DevinAlexander | 0:b714c6a7c969 | 204 | * while(true) |
DevinAlexander | 0:b714c6a7c969 | 205 | * { |
DevinAlexander | 0:b714c6a7c969 | 206 | * temperature_TC_1=Thermocouple1.readTC(); |
DevinAlexander | 0:b714c6a7c969 | 207 | * temperature_CJ_1=Thermocouple1.readCJ(); |
DevinAlexander | 0:b714c6a7c969 | 208 | * serial.printf("MAX31856 TC = %f Celsius MAX31856 CJ = %f Celsius \n\r",temperature_TC_1,temperature_CJ_1); |
DevinAlexander | 0:b714c6a7c969 | 209 | * wait(1.0); |
DevinAlexander | 0:b714c6a7c969 | 210 | * } |
DevinAlexander | 0:b714c6a7c969 | 211 | * } |
DevinAlexander | 0:b714c6a7c969 | 212 | * @endcode |
DevinAlexander | 0:b714c6a7c969 | 213 | */ |
DevinAlexander | 0:b714c6a7c969 | 214 | |
DevinAlexander | 0:b714c6a7c969 | 215 | |
DevinAlexander | 0:b714c6a7c969 | 216 | |
DevinAlexander | 0:b714c6a7c969 | 217 | /** Please see pages 18-26 in the MAX31856 data sheet to see what register bit masks are needed to be set |
DevinAlexander | 0:b714c6a7c969 | 218 | to achieve functionality desired. The data sheet can be found at |
DevinAlexander | 0:b714c6a7c969 | 219 | |
DevinAlexander | 0:b714c6a7c969 | 220 | *** https://datasheets.maximintegrated.com/en/ds/MAX31856.pdf *** |
DevinAlexander | 0:b714c6a7c969 | 221 | */ |
DevinAlexander | 0:b714c6a7c969 | 222 | |
DevinAlexander | 0:b714c6a7c969 | 223 | |
DevinAlexander | 0:b714c6a7c969 | 224 | /** |
DevinAlexander | 0:b714c6a7c969 | 225 | * MAX31856 Class |
DevinAlexander | 0:b714c6a7c969 | 226 | */ |
DevinAlexander | 0:b714c6a7c969 | 227 | class MAX31856 |
DevinAlexander | 0:b714c6a7c969 | 228 | { |
DevinAlexander | 0:b714c6a7c969 | 229 | |
DevinAlexander | 0:b714c6a7c969 | 230 | public: |
DevinAlexander | 0:b714c6a7c969 | 231 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 232 | //Constructor and Destructor for the class |
DevinAlexander | 0:b714c6a7c969 | 233 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 234 | /** |
DevinAlexander | 0:b714c6a7c969 | 235 | * @brief Constructor to create MAX31856 object with SPI information as well as preconfiguration parameter settings in configuration registers Zero and One |
DevinAlexander | 0:b714c6a7c969 | 236 | * @param _spi - Reference to SPI object |
DevinAlexander | 0:b714c6a7c969 | 237 | * @param _ncs - Chip Select for SPI comunications with the oject |
DevinAlexander | 0:b714c6a7c969 | 238 | * @param _type - Type of thermocouple used |
DevinAlexander | 0:b714c6a7c969 | 239 | * @param _fltr - Feature of the MAX31856 to filter out either 50Hz/60Hz from signal |
DevinAlexander | 0:b714c6a7c969 | 240 | * @param _samples - How many samples are averaged for one conversion |
DevinAlexander | 0:b714c6a7c969 | 241 | * @param _conversion_mode - Choose between always on and making conversions and off in between requests for a reading |
DevinAlexander | 0:b714c6a7c969 | 242 | */ |
DevinAlexander | 0:b714c6a7c969 | 243 | 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:b714c6a7c969 | 244 | |
DevinAlexander | 0:b714c6a7c969 | 245 | |
DevinAlexander | 0:b714c6a7c969 | 246 | /** @brief Destructor */ |
DevinAlexander | 0:b714c6a7c969 | 247 | ~MAX31856(void); |
DevinAlexander | 0:b714c6a7c969 | 248 | |
DevinAlexander | 0:b714c6a7c969 | 249 | |
DevinAlexander | 0:b714c6a7c969 | 250 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 251 | //Temperature Functions |
DevinAlexander | 0:b714c6a7c969 | 252 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 253 | /** |
DevinAlexander | 0:b714c6a7c969 | 254 | * @brief Requests read of the thermocouple temperature |
DevinAlexander | 0:b714c6a7c969 | 255 | * @return float of the converted thermocouple reading based on current configurations |
DevinAlexander | 0:b714c6a7c969 | 256 | */ |
DevinAlexander | 0:b714c6a7c969 | 257 | float readTC(); |
DevinAlexander | 0:b714c6a7c969 | 258 | |
DevinAlexander | 0:b714c6a7c969 | 259 | |
DevinAlexander | 0:b714c6a7c969 | 260 | /** |
DevinAlexander | 0:b714c6a7c969 | 261 | * @brief Requests read of the cold junction temperature |
DevinAlexander | 0:b714c6a7c969 | 262 | * @return float of the converted artificial cold junction reading based on current configurations |
DevinAlexander | 0:b714c6a7c969 | 263 | */ |
DevinAlexander | 0:b714c6a7c969 | 264 | float readCJ(); |
DevinAlexander | 0:b714c6a7c969 | 265 | |
DevinAlexander | 0:b714c6a7c969 | 266 | |
DevinAlexander | 0:b714c6a7c969 | 267 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 268 | //Functions for register CR0 |
DevinAlexander | 0:b714c6a7c969 | 269 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 270 | /** |
DevinAlexander | 0:b714c6a7c969 | 271 | * @brief Sets bits in the configuration register zero for setting the rate of conversions |
DevinAlexander | 0:b714c6a7c969 | 272 | * @param val \li CR0_CONV_MODE_NORMALLY_OFF (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 273 | * \li CR0_CONV_MODE_NORMALLY_ON |
DevinAlexander | 0:b714c6a7c969 | 274 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 275 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 276 | */ |
DevinAlexander | 0:b714c6a7c969 | 277 | bool setConversionMode(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 278 | |
DevinAlexander | 0:b714c6a7c969 | 279 | |
DevinAlexander | 0:b714c6a7c969 | 280 | /** |
DevinAlexander | 0:b714c6a7c969 | 281 | * @brief Sets bits in the configuration register zero for enabling one conversion to take place |
DevinAlexander | 0:b714c6a7c969 | 282 | * @param val \li CR0_1_SHOT_MODE_NO_CONVERSION (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 283 | * \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 | 0:b714c6a7c969 | 284 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 285 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 286 | */ |
DevinAlexander | 0:b714c6a7c969 | 287 | bool setOneShotMode(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 288 | |
DevinAlexander | 0:b714c6a7c969 | 289 | |
DevinAlexander | 0:b714c6a7c969 | 290 | /** |
DevinAlexander | 0:b714c6a7c969 | 291 | * @brief Sets bits in the configuration register zero for configuring open circuit fault detection |
DevinAlexander | 0:b714c6a7c969 | 292 | * @param val \li CR0_OC_DETECT_DISABLED (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 293 | * \li CR0_OC_DETECT_ENABLED_R_LESS_5k |
DevinAlexander | 0:b714c6a7c969 | 294 | * \li CR0_OC_DETECT_ENABLED_TC_LESS_2ms |
DevinAlexander | 0:b714c6a7c969 | 295 | * \li CR0_OC_DETECT_ENABLED_TC_MORE_2ms |
DevinAlexander | 0:b714c6a7c969 | 296 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 297 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 298 | */ |
DevinAlexander | 0:b714c6a7c969 | 299 | bool setOpenCircuitFaultDetection(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 300 | |
DevinAlexander | 0:b714c6a7c969 | 301 | |
DevinAlexander | 0:b714c6a7c969 | 302 | /** |
DevinAlexander | 0:b714c6a7c969 | 303 | * @brief Sets bits in the configuration register zero for disabling or enabling the Cold Junction |
DevinAlexander | 0:b714c6a7c969 | 304 | * @param val \li CR0_COLD_JUNC_ENABLE (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 305 | * \li CR0_COLD_JUNC_DISABLE |
DevinAlexander | 0:b714c6a7c969 | 306 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 307 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 308 | */ |
DevinAlexander | 0:b714c6a7c969 | 309 | bool setColdJunctionDisable(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 310 | |
DevinAlexander | 0:b714c6a7c969 | 311 | |
DevinAlexander | 0:b714c6a7c969 | 312 | /** |
DevinAlexander | 0:b714c6a7c969 | 313 | * @brief Sets bits in the configuration register zero for setting fault mode status |
DevinAlexander | 0:b714c6a7c969 | 314 | * @param val \li CR0_FAULT_MODE_COMPARATOR (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 315 | * \li CR0_FAULT_MODE_INTERUPT |
DevinAlexander | 0:b714c6a7c969 | 316 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 317 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 318 | */ |
DevinAlexander | 0:b714c6a7c969 | 319 | bool setFaultMode(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 320 | |
DevinAlexander | 0:b714c6a7c969 | 321 | |
DevinAlexander | 0:b714c6a7c969 | 322 | /** |
DevinAlexander | 0:b714c6a7c969 | 323 | * @brief Sets bits in the configuration register zero for clearing fault status |
DevinAlexander | 0:b714c6a7c969 | 324 | * @param val \li CR0_FAULTCLR_DEFAULT_VAL (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 325 | * \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 | 0:b714c6a7c969 | 326 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 327 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 328 | */ |
DevinAlexander | 0:b714c6a7c969 | 329 | bool setFaultStatusClear(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 330 | |
DevinAlexander | 0:b714c6a7c969 | 331 | |
DevinAlexander | 0:b714c6a7c969 | 332 | /** |
DevinAlexander | 0:b714c6a7c969 | 333 | * @brief Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation |
DevinAlexander | 0:b714c6a7c969 | 334 | * @param val \li CR0_FILTER_OUT_60Hz (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 335 | * \li CR0_FILTER_OUT_50Hz |
DevinAlexander | 0:b714c6a7c969 | 336 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 337 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 338 | */ |
DevinAlexander | 0:b714c6a7c969 | 339 | bool setEmiFilterFreq(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 340 | |
DevinAlexander | 0:b714c6a7c969 | 341 | |
DevinAlexander | 0:b714c6a7c969 | 342 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 343 | //Functions for register CR1 |
DevinAlexander | 0:b714c6a7c969 | 344 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 345 | /** |
DevinAlexander | 0:b714c6a7c969 | 346 | * @brief Sets bits in the configuration register one for setting how many readings are taken |
DevinAlexander | 0:b714c6a7c969 | 347 | * @param val \li CR1_AVG_TC_SAMPLES_1 (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 348 | * \li CR1_AVG_TC_SAMPLES_2 |
DevinAlexander | 0:b714c6a7c969 | 349 | * \li CR1_AVG_TC_SAMPLES_4 |
DevinAlexander | 0:b714c6a7c969 | 350 | * \li CR1_AVG_TC_SAMPLES_8 |
DevinAlexander | 0:b714c6a7c969 | 351 | * \li CR1_AVG_TC_SAMPLES_16 |
DevinAlexander | 0:b714c6a7c969 | 352 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 353 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 354 | */ |
DevinAlexander | 0:b714c6a7c969 | 355 | bool setNumSamplesAvg(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 356 | |
DevinAlexander | 0:b714c6a7c969 | 357 | |
DevinAlexander | 0:b714c6a7c969 | 358 | /** |
DevinAlexander | 0:b714c6a7c969 | 359 | * @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 | 0:b714c6a7c969 | 360 | * @param val \li CR1_TC_TYPE_B |
DevinAlexander | 0:b714c6a7c969 | 361 | * \li CR1_TC_TYPE_E |
DevinAlexander | 0:b714c6a7c969 | 362 | * \li CR1_TC_TYPE_J |
DevinAlexander | 0:b714c6a7c969 | 363 | * \li CR1_TC_TYPE_K (Power On Default value) |
DevinAlexander | 0:b714c6a7c969 | 364 | * \li CR1_TC_TYPE_N |
DevinAlexander | 0:b714c6a7c969 | 365 | * \li CR1_TC_TYPE_R |
DevinAlexander | 0:b714c6a7c969 | 366 | * \li CR1_TC_TYPE_S |
DevinAlexander | 0:b714c6a7c969 | 367 | * \li CR1_TC_TYPE_T |
DevinAlexander | 0:b714c6a7c969 | 368 | * \li CR1_TC_TYPE_VOLT_MODE_GAIN_8 |
DevinAlexander | 0:b714c6a7c969 | 369 | * \li CR1_TC_TYPE_VOLT_MODE_GAIN_32 |
DevinAlexander | 0:b714c6a7c969 | 370 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 371 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 372 | */ |
DevinAlexander | 0:b714c6a7c969 | 373 | bool setThermocoupleType(uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 374 | |
DevinAlexander | 0:b714c6a7c969 | 375 | |
DevinAlexander | 0:b714c6a7c969 | 376 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 377 | //Functions for register MASK |
DevinAlexander | 0:b714c6a7c969 | 378 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 379 | /** |
DevinAlexander | 0:b714c6a7c969 | 380 | * @brief Sets bits in the configuration register one for setting fault masks |
DevinAlexander | 0:b714c6a7c969 | 381 | * @param val \li MASK_CJ_FAULT_THRESHOLD_HIGH |
DevinAlexander | 0:b714c6a7c969 | 382 | * \li MASK_CJ_FAULT_THRESHOLD_LOW |
DevinAlexander | 0:b714c6a7c969 | 383 | * \li MASK_TC_FAULT_THRESHOLD_HIGH |
DevinAlexander | 0:b714c6a7c969 | 384 | * \li MASK_TC_FAULT_THRESHOLD_LOW |
DevinAlexander | 0:b714c6a7c969 | 385 | * \li MASK_OVER_UNDER_VOLT_FAULT |
DevinAlexander | 0:b714c6a7c969 | 386 | * \li MASK_OPEN_CIRCUIT_FAULT |
DevinAlexander | 0:b714c6a7c969 | 387 | * @param enable \li 0 for disabling the mask in whichever option is selcted in parameter val |
DevinAlexander | 0:b714c6a7c969 | 388 | * \li 1 for enabling the mask in whichever option is selcted in parameter val |
DevinAlexander | 0:b714c6a7c969 | 389 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 390 | * \li 0 if there is an incorrect parameter that is passed in as parameter val |
DevinAlexander | 0:b714c6a7c969 | 391 | */ |
DevinAlexander | 0:b714c6a7c969 | 392 | bool setFaultMasks(uint8_t val, bool enable); |
DevinAlexander | 0:b714c6a7c969 | 393 | |
DevinAlexander | 0:b714c6a7c969 | 394 | |
DevinAlexander | 0:b714c6a7c969 | 395 | /** |
DevinAlexander | 0:b714c6a7c969 | 396 | * @brief Sets bits in the configuration register one for setting thresholds that corespond to the fault mask settings |
DevinAlexander | 0:b714c6a7c969 | 397 | * @param val \li MASK_CJ_FAULT_THRESHOLD_HIGH |
DevinAlexander | 0:b714c6a7c969 | 398 | * \li MASK_CJ_FAULT_THRESHOLD_LOW |
DevinAlexander | 0:b714c6a7c969 | 399 | * \li MASK_TC_FAULT_THRESHOLD_HIGH |
DevinAlexander | 0:b714c6a7c969 | 400 | * \li MASK_TC_FAULT_THRESHOLD_LOW |
DevinAlexander | 0:b714c6a7c969 | 401 | * @param temperature value that you want to program into a threshold register for temperatre |
DevinAlexander | 0:b714c6a7c969 | 402 | * @return return value that was programmed into the threshold register |
DevinAlexander | 0:b714c6a7c969 | 403 | */ |
DevinAlexander | 0:b714c6a7c969 | 404 | bool setFaultThresholds(uint8_t val, float temperature); |
DevinAlexander | 0:b714c6a7c969 | 405 | |
DevinAlexander | 0:b714c6a7c969 | 406 | |
DevinAlexander | 0:b714c6a7c969 | 407 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 408 | //Check Fault Status Functions |
DevinAlexander | 0:b714c6a7c969 | 409 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 410 | /** |
DevinAlexander | 0:b714c6a7c969 | 411 | * @brief Check the fault stautus register to see if there is anything wrong with range of thermocouple temperature |
DevinAlexander | 0:b714c6a7c969 | 412 | * whether outside opperating temperatures or if above/below thresholds that are set |
DevinAlexander | 0:b714c6a7c969 | 413 | * @return \li 0 if no faults are present |
DevinAlexander | 0:b714c6a7c969 | 414 | * \li 1 if Thermocouple temp is higher than the threshold |
DevinAlexander | 0:b714c6a7c969 | 415 | * \li 2 if Thermocouple temp is lower than the threshold |
DevinAlexander | 0:b714c6a7c969 | 416 | * \li 3 if Thermocouple temp is outside operating range of termocouple type |
DevinAlexander | 0:b714c6a7c969 | 417 | * \li 4 if Thermocouple temp is higher than the threshold && is outside operating range of termocouple type |
DevinAlexander | 0:b714c6a7c969 | 418 | * \li 5 if Thermocouple temp is lower than the threshold && is outside operating range of termocouple type |
DevinAlexander | 0:b714c6a7c969 | 419 | */ |
DevinAlexander | 0:b714c6a7c969 | 420 | uint8_t checkFaultsThermocoupleThresholds(); |
DevinAlexander | 0:b714c6a7c969 | 421 | |
DevinAlexander | 0:b714c6a7c969 | 422 | |
DevinAlexander | 0:b714c6a7c969 | 423 | /** |
DevinAlexander | 0:b714c6a7c969 | 424 | * @brief Check the fault stautus register to see if there is anything wrong with range of cold junction temperature |
DevinAlexander | 0:b714c6a7c969 | 425 | * whether outside opperating temperatures or if above/below thresholds that are set |
DevinAlexander | 0:b714c6a7c969 | 426 | * @return \li 0 if no faults are present |
DevinAlexander | 0:b714c6a7c969 | 427 | * \li 1 if Cold Junction temp is higher than the threshold |
DevinAlexander | 0:b714c6a7c969 | 428 | * \li 2 if Cold Junction temp is lower than the threshold |
DevinAlexander | 0:b714c6a7c969 | 429 | * \li 3 if Cold Junction temp is outside operating range of termocouple type |
DevinAlexander | 0:b714c6a7c969 | 430 | * \li 4 if Cold Junction temp is higher than the threshold && is outside operating range of termocouple type |
DevinAlexander | 0:b714c6a7c969 | 431 | * \li 5 if Cold Junction temp is lower than the threshold && is outside operating range of termocouple type |
DevinAlexander | 0:b714c6a7c969 | 432 | */ |
DevinAlexander | 0:b714c6a7c969 | 433 | uint8_t checkFaultsColdJunctionThresholds(); |
DevinAlexander | 0:b714c6a7c969 | 434 | |
DevinAlexander | 0:b714c6a7c969 | 435 | |
DevinAlexander | 0:b714c6a7c969 | 436 | /** |
DevinAlexander | 0:b714c6a7c969 | 437 | * @brief Check the fault stautus register to see if there is anything wrong with thermocouple connection to the MAX31856 |
DevinAlexander | 0:b714c6a7c969 | 438 | * @return \li 1 if no faults are present |
DevinAlexander | 0:b714c6a7c969 | 439 | * \li 0 if there is a fault and there needs to be information printed to the console to help diagnose issues |
DevinAlexander | 0:b714c6a7c969 | 440 | */ |
DevinAlexander | 0:b714c6a7c969 | 441 | bool checkFaultsThermocoupleConnection(); |
DevinAlexander | 0:b714c6a7c969 | 442 | |
DevinAlexander | 0:b714c6a7c969 | 443 | |
DevinAlexander | 0:b714c6a7c969 | 444 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 445 | //General Functions |
DevinAlexander | 0:b714c6a7c969 | 446 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 447 | /** |
DevinAlexander | 0:b714c6a7c969 | 448 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 0:b714c6a7c969 | 449 | * \li Read the value of a register from contents of register matching the parameter read_address |
DevinAlexander | 0:b714c6a7c969 | 450 | * \li Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits |
DevinAlexander | 0:b714c6a7c969 | 451 | * \li Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val |
DevinAlexander | 0:b714c6a7c969 | 452 | * \li Rewrite to the register with the new 8 bit value to the register with the address with parameter write_address |
DevinAlexander | 0:b714c6a7c969 | 453 | * @param read_address - Address of register to read the data before it's changed |
DevinAlexander | 0:b714c6a7c969 | 454 | * @param write_address - Address of register to rewrite the changed data |
DevinAlexander | 0:b714c6a7c969 | 455 | * @param clear_bits - Parameter that is |
DevinAlexander | 0:b714c6a7c969 | 456 | * @param val - Bitfield that contains bits related to function specific settings |
DevinAlexander | 0:b714c6a7c969 | 457 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 458 | */ |
DevinAlexander | 0:b714c6a7c969 | 459 | bool registerReadWriteByte(uint8_t read_address, uint8_t write_address, int clear_bits, uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 460 | |
DevinAlexander | 0:b714c6a7c969 | 461 | |
DevinAlexander | 0:b714c6a7c969 | 462 | /** |
DevinAlexander | 0:b714c6a7c969 | 463 | * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n |
DevinAlexander | 0:b714c6a7c969 | 464 | * \li Read the value of a register from contents of register matching the parameter read_address |
DevinAlexander | 0:b714c6a7c969 | 465 | * \li Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits |
DevinAlexander | 0:b714c6a7c969 | 466 | * \li Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val |
DevinAlexander | 0:b714c6a7c969 | 467 | * \li Write to the register with the new 8 bit value to the register with the address with parameter write_address |
DevinAlexander | 0:b714c6a7c969 | 468 | * @param write_address - Address of register to rewrite the changed data |
DevinAlexander | 0:b714c6a7c969 | 469 | * @param val - Byte of information that is going to be written to the regitser with the address that matches the parameter write_address |
DevinAlexander | 0:b714c6a7c969 | 470 | * @return \li 1 on success |
DevinAlexander | 0:b714c6a7c969 | 471 | */ |
DevinAlexander | 0:b714c6a7c969 | 472 | bool registerWriteByte(uint8_t write_address, uint8_t val); |
DevinAlexander | 0:b714c6a7c969 | 473 | |
DevinAlexander | 0:b714c6a7c969 | 474 | |
DevinAlexander | 0:b714c6a7c969 | 475 | /** |
DevinAlexander | 0:b714c6a7c969 | 476 | * @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 | 0:b714c6a7c969 | 477 | * @param read_address - Address of register to read data from |
DevinAlexander | 0:b714c6a7c969 | 478 | * @return \li byte contained in the address |
DevinAlexander | 0:b714c6a7c969 | 479 | */ |
DevinAlexander | 0:b714c6a7c969 | 480 | uint8_t registerReadByte(uint8_t read_address); |
DevinAlexander | 0:b714c6a7c969 | 481 | |
DevinAlexander | 0:b714c6a7c969 | 482 | |
DevinAlexander | 0:b714c6a7c969 | 483 | /** |
DevinAlexander | 0:b714c6a7c969 | 484 | * @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 | 0:b714c6a7c969 | 485 | * @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 | 0:b714c6a7c969 | 486 | * @return \li 1 on successfully updated coldjunction offset |
DevinAlexander | 0:b714c6a7c969 | 487 | * \li 0 if parameter temperature does not fall between range -8°C to +7.9375°C |
DevinAlexander | 0:b714c6a7c969 | 488 | */ |
DevinAlexander | 0:b714c6a7c969 | 489 | bool coldJunctionOffset(float temperature); |
DevinAlexander | 0:b714c6a7c969 | 490 | |
DevinAlexander | 0:b714c6a7c969 | 491 | |
DevinAlexander | 0:b714c6a7c969 | 492 | private: |
DevinAlexander | 0:b714c6a7c969 | 493 | |
DevinAlexander | 0:b714c6a7c969 | 494 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 495 | //Private Functions |
DevinAlexander | 0:b714c6a7c969 | 496 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 497 | /** @brief Writes the chip seleect pin low to begin SPI communications */ |
DevinAlexander | 0:b714c6a7c969 | 498 | void spiEnable(); |
DevinAlexander | 0:b714c6a7c969 | 499 | |
DevinAlexander | 0:b714c6a7c969 | 500 | |
DevinAlexander | 0:b714c6a7c969 | 501 | /** @brief Writes the chip seleect pin high to end SPI communications */ |
DevinAlexander | 0:b714c6a7c969 | 502 | void spiDisable(); |
DevinAlexander | 0:b714c6a7c969 | 503 | |
DevinAlexander | 0:b714c6a7c969 | 504 | /** @brief Calculates minimum wait time for a conversion to take place */ |
DevinAlexander | 0:b714c6a7c969 | 505 | void calculateDelayTime(); |
DevinAlexander | 0:b714c6a7c969 | 506 | |
DevinAlexander | 0:b714c6a7c969 | 507 | |
DevinAlexander | 0:b714c6a7c969 | 508 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 509 | //Private Members |
DevinAlexander | 0:b714c6a7c969 | 510 | //***************************************************************************** |
DevinAlexander | 0:b714c6a7c969 | 511 | /// SPI object |
DevinAlexander | 0:b714c6a7c969 | 512 | SPI& spi; |
DevinAlexander | 0:b714c6a7c969 | 513 | |
DevinAlexander | 0:b714c6a7c969 | 514 | /// Chip select pin for SPI communications |
DevinAlexander | 0:b714c6a7c969 | 515 | DigitalOut ncs; |
DevinAlexander | 0:b714c6a7c969 | 516 | |
DevinAlexander | 0:b714c6a7c969 | 517 | /// Number of samples the thermocouple is configured to average |
DevinAlexander | 0:b714c6a7c969 | 518 | uint8_t samples; |
DevinAlexander | 0:b714c6a7c969 | 519 | |
DevinAlexander | 0:b714c6a7c969 | 520 | /// 0=thermocouple is set to one of 8 thermocouple types and 1=Thermocouple is configured to report in voltage mode |
DevinAlexander | 0:b714c6a7c969 | 521 | bool voltage_mode; |
DevinAlexander | 0:b714c6a7c969 | 522 | |
DevinAlexander | 0:b714c6a7c969 | 523 | /// 0=60Hz and 1=50Hz |
DevinAlexander | 0:b714c6a7c969 | 524 | bool filter_mode; |
DevinAlexander | 0:b714c6a7c969 | 525 | |
DevinAlexander | 0:b714c6a7c969 | 526 | /// 0=MAX31856 is off, so no conversion is taking place currently and 1=Always On and converting |
DevinAlexander | 0:b714c6a7c969 | 527 | bool conversion_mode; |
DevinAlexander | 0:b714c6a7c969 | 528 | |
DevinAlexander | 0:b714c6a7c969 | 529 | /// 0=cold junction is disabled and 1=cold junction is enabled |
DevinAlexander | 0:b714c6a7c969 | 530 | bool cold_junction_enabled; |
DevinAlexander | 0:b714c6a7c969 | 531 | |
DevinAlexander | 0:b714c6a7c969 | 532 | ///Define a return val for all boolean functions |
DevinAlexander | 0:b714c6a7c969 | 533 | bool return_val; |
DevinAlexander | 0:b714c6a7c969 | 534 | |
DevinAlexander | 0:b714c6a7c969 | 535 | ///Used to figure out when a new conversion is ready to go |
DevinAlexander | 0:b714c6a7c969 | 536 | uint32_t lastReadTime; |
DevinAlexander | 0:b714c6a7c969 | 537 | |
DevinAlexander | 0:b714c6a7c969 | 538 | ///How many conversions have taken place since conversion mode was switched into auto mode |
DevinAlexander | 0:b714c6a7c969 | 539 | ///Also this value should be 0 if the mode is in oneshot mode |
DevinAlexander | 0:b714c6a7c969 | 540 | uint32_t thermocouple_conversion_count; |
DevinAlexander | 0:b714c6a7c969 | 541 | |
DevinAlexander | 0:b714c6a7c969 | 542 | ///time in milliseconds that is needed minimum for a new conversion to take place |
DevinAlexander | 0:b714c6a7c969 | 543 | uint32_t conversion_time; |
DevinAlexander | 0:b714c6a7c969 | 544 | }; |
DevinAlexander | 0:b714c6a7c969 | 545 | |
DevinAlexander | 0:b714c6a7c969 | 546 | #endif /* __MAX31856_H_ */ |