Library for the MAX31856 Precision Thermocouple to Digital Converter with Linearization
Dependents: MAX31856_example_program
Fork of MAX31856 by
MAX31856 Class Reference
Library for the MAX31856
The MAX31856 thermocouple temperature sensor accurately measures temperature and provides a vast amount of features such as: //FEATURE //FEATURE //FEATURE //FEATURE //FEATURE //FEATURE Communication is through an SPI-compatible interface.
More...
#include <MAX31856.h>
Public Member Functions | |
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) | |
Constructor to create MAX31856 object with SPI information as well as preconfiguration parameter settings in configuration registers Zero and One. | |
~MAX31856 (void) | |
Destructor. | |
float | readTC () |
Requests read of the thermocouple temperature. | |
float | readCJ () |
Requests read of the cold junction temperature. | |
bool | setConversionMode (uint8_t val) |
Sets bits in the configuration register zero for setting the rate of conversions. | |
bool | setOneShotMode (uint8_t val) |
Sets bits in the configuration register zero for enabling one conversion to take place. | |
bool | setOpenCircuitFaultDetection (uint8_t val) |
Sets bits in the configuration register zero for configuring open circuit fault detection. | |
bool | setColdJunctionDisable (uint8_t val) |
Sets bits in the configuration register zero for disabling or enabling the Cold Junction. | |
bool | setFaultMode (uint8_t val) |
Sets bits in the configuration register zero for setting fault mode status. | |
bool | setFaultStatusClear (uint8_t val) |
Sets bits in the configuration register zero for clearing fault status. | |
bool | setEmiFilterFreq (uint8_t val) |
Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation. | |
bool | setNumSamplesAvg (uint8_t val) |
Sets bits in the configuration register one for setting how many readings are taken. | |
bool | setThermocoupleType (uint8_t val) |
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. | |
bool | setFaultMasks (uint8_t val, bool enable) |
Sets bits in the configuration register one for setting fault masks. | |
bool | setFaultThresholds (uint8_t val, float temperature) |
Sets bits in the configuration register one for setting thresholds that corespond to the fault mask settings. | |
uint8_t | checkFaultsThermocoupleThresholds () |
Check the fault stautus register to see if there is anything wrong with range of thermocouple temperature whether outside opperating temperatures or if above/below thresholds that are set. | |
uint8_t | checkFaultsColdJunctionThresholds () |
Check the fault stautus register to see if there is anything wrong with range of cold junction temperature whether outside opperating temperatures or if above/below thresholds that are set. | |
bool | checkFaultsThermocoupleConnection () |
Check the fault stautus register to see if there is anything wrong with thermocouple connection to the MAX31856. | |
bool | registerReadWriteByte (uint8_t read_address, uint8_t write_address, int clear_bits, uint8_t val) |
This function is to read current contents of register, manipulate the contents, then rewrite the specific register . | |
bool | registerWriteByte (uint8_t write_address, uint8_t val) |
This function is to read current contents of register, manipulate the contents, then rewrite the specific register . | |
uint8_t | registerReadByte (uint8_t read_address) |
This function is to read current contents of register by passing in the address of the read address and return contents of the register. | |
bool | coldJunctionOffset (float temperature) |
This function is to read current contents of register by passing in the address of the read address and return contents of the register. |
Detailed Description
Library for the MAX31856
The MAX31856 thermocouple temperature sensor accurately measures temperature and provides a vast amount of features such as: //FEATURE //FEATURE //FEATURE //FEATURE //FEATURE //FEATURE Communication is through an SPI-compatible interface.
#include "mbed.h" #include "MAX31856.h" // Hardware serial port Serial serial(USBTX, USBRX); //SPI communications SPI spi(SPIO MOSI,SPIO MISO,SPIO SCK); //Thermocouples MAX31856 Thermocouple1(spi, CHIPSELECT); int main(void) { float temperature_TC_1, temperature_CJ_1; while(true) { temperature_TC_1=Thermocouple1.readTC(); temperature_CJ_1=Thermocouple1.readCJ(); serial.printf("MAX31856 TC = %f Celsius MAX31856 CJ = %f Celsius \n\r",temperature_TC_1,temperature_CJ_1); wait(1.0); } }
Please see pages 18-26 in the MAX31856 data sheet to see what register bit masks are needed to be set to achieve functionality desired. The data sheet can be found at
https://datasheets.maximintegrated.com/en/ds/MAX31856.pdf *** MAX31856 Class
Definition at line 227 of file MAX31856.h.
Constructor & Destructor Documentation
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 |
||
) |
Constructor to create MAX31856 object with SPI information as well as preconfiguration parameter settings in configuration registers Zero and One.
- Parameters:
-
_spi - Reference to SPI object _ncs - Chip Select for SPI comunications with the oject _type - Type of thermocouple used _fltr - Feature of the MAX31856 to filter out either 50Hz/60Hz from signal _samples - How many samples are averaged for one conversion _conversion_mode - Choose between always on and making conversions and off in between requests for a reading
Definition at line 54 of file MAX31856.cpp.
~MAX31856 | ( | void | ) |
Destructor.
Definition at line 659 of file MAX31856.cpp.
Member Function Documentation
uint8_t checkFaultsColdJunctionThresholds | ( | ) |
Check the fault stautus register to see if there is anything wrong with range of cold junction temperature whether outside opperating temperatures or if above/below thresholds that are set.
- Returns:
- 0 if no faults are present
- 1 if Cold Junction temp is higher than the threshold
- 2 if Cold Junction temp is lower than the threshold
- 3 if Cold Junction temp is outside operating range of termocouple type
- 4 if Cold Junction temp is higher than the threshold && is outside operating range of termocouple type
- 5 if Cold Junction temp is lower than the threshold && is outside operating range of termocouple type
Definition at line 170 of file MAX31856.cpp.
bool checkFaultsThermocoupleConnection | ( | ) |
Check the fault stautus register to see if there is anything wrong with thermocouple connection to the MAX31856.
- Returns:
- 1 if no faults are present
- 0 if there is a fault and there needs to be information printed to the console to help diagnose issues
Definition at line 209 of file MAX31856.cpp.
uint8_t checkFaultsThermocoupleThresholds | ( | ) |
Check the fault stautus register to see if there is anything wrong with range of thermocouple temperature whether outside opperating temperatures or if above/below thresholds that are set.
- Returns:
- 0 if no faults are present
- 1 if Thermocouple temp is higher than the threshold
- 2 if Thermocouple temp is lower than the threshold
- 3 if Thermocouple temp is outside operating range of termocouple type
- 4 if Thermocouple temp is higher than the threshold && is outside operating range of termocouple type
- 5 if Thermocouple temp is lower than the threshold && is outside operating range of termocouple type
Definition at line 131 of file MAX31856.cpp.
bool coldJunctionOffset | ( | float | temperature ) |
This function is to read current contents of register by passing in the address of the read address and return contents of the register.
- Parameters:
-
temperature - Float of value to offest the value of the cold junction offset by (must be between -8°C to +7.9375°C)
- Returns:
- 1 on successfully updated coldjunction offset
- 0 if parameter temperature does not fall between range -8°C to +7.9375°C
Definition at line 558 of file MAX31856.cpp.
float readCJ | ( | ) |
Requests read of the cold junction temperature.
- Returns:
- float of the converted artificial cold junction reading based on current configurations
Definition at line 108 of file MAX31856.cpp.
float readTC | ( | ) |
Requests read of the thermocouple temperature.
- Returns:
- float of the converted thermocouple reading based on current configurations
Definition at line 64 of file MAX31856.cpp.
uint8_t registerReadByte | ( | uint8_t | read_address ) |
This function is to read current contents of register by passing in the address of the read address and return contents of the register.
- Parameters:
-
read_address - Address of register to read data from
- Returns:
- byte contained in the address
Definition at line 625 of file MAX31856.cpp.
bool registerReadWriteByte | ( | uint8_t | read_address, |
uint8_t | write_address, | ||
int | clear_bits, | ||
uint8_t | val | ||
) |
This function is to read current contents of register, manipulate the contents, then rewrite the specific register
.
- Read the value of a register from contents of register matching the parameter read_address
- Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits
- Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val
- Rewrite to the register with the new 8 bit value to the register with the address with parameter write_address
- Parameters:
-
read_address - Address of register to read the data before it's changed write_address - Address of register to rewrite the changed data clear_bits - Parameter that is val - Bitfield that contains bits related to function specific settings
- Returns:
- 1 on success
Definition at line 588 of file MAX31856.cpp.
bool registerWriteByte | ( | uint8_t | write_address, |
uint8_t | val | ||
) |
This function is to read current contents of register, manipulate the contents, then rewrite the specific register
.
- Read the value of a register from contents of register matching the parameter read_address
- Clear the bits needed to be changed by bitwise ANDing the read value with the 8 bit parameter clear_bits
- Set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter val
- Write to the register with the new 8 bit value to the register with the address with parameter write_address
- Parameters:
-
write_address - Address of register to rewrite the changed data val - Byte of information that is going to be written to the regitser with the address that matches the parameter write_address
- Returns:
- 1 on success
Definition at line 614 of file MAX31856.cpp.
bool setColdJunctionDisable | ( | uint8_t | val ) |
Sets bits in the configuration register zero for disabling or enabling the Cold Junction.
- Parameters:
-
val - CR0_COLD_JUNC_ENABLE (Power On Default value)
- CR0_COLD_JUNC_DISABLE
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 301 of file MAX31856.cpp.
bool setConversionMode | ( | uint8_t | val ) |
Sets bits in the configuration register zero for setting the rate of conversions.
- Parameters:
-
val - CR0_CONV_MODE_NORMALLY_OFF (Power On Default value)
- CR0_CONV_MODE_NORMALLY_ON
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 235 of file MAX31856.cpp.
bool setEmiFilterFreq | ( | uint8_t | val ) |
Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation.
- Parameters:
-
val - CR0_FILTER_OUT_60Hz (Power On Default value)
- CR0_FILTER_OUT_50Hz
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 363 of file MAX31856.cpp.
bool setFaultMasks | ( | uint8_t | val, |
bool | enable | ||
) |
Sets bits in the configuration register one for setting fault masks.
- Parameters:
-
val - MASK_CJ_FAULT_THRESHOLD_HIGH
- MASK_CJ_FAULT_THRESHOLD_LOW
- MASK_TC_FAULT_THRESHOLD_HIGH
- MASK_TC_FAULT_THRESHOLD_LOW
- MASK_OVER_UNDER_VOLT_FAULT
- MASK_OPEN_CIRCUIT_FAULT
enable - 0 for disabling the mask in whichever option is selcted in parameter val
- 1 for enabling the mask in whichever option is selcted in parameter val
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 484 of file MAX31856.cpp.
bool setFaultMode | ( | uint8_t | val ) |
Sets bits in the configuration register zero for setting fault mode status.
- Parameters:
-
val - CR0_FAULT_MODE_COMPARATOR (Power On Default value)
- CR0_FAULT_MODE_INTERUPT
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 323 of file MAX31856.cpp.
bool setFaultStatusClear | ( | uint8_t | val ) |
Sets bits in the configuration register zero for clearing fault status.
- Parameters:
-
val - CR0_FAULTCLR_DEFAULT_VAL (Power On Default value)
- CR0_FAULTCLR_RETURN_FAULTS_TO_ZERO (This bit self clears itself to default back to CR0_FAULTCLR_DEFAULT_VAL after fault status is cleared)
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 343 of file MAX31856.cpp.
bool setFaultThresholds | ( | uint8_t | val, |
float | temperature | ||
) |
Sets bits in the configuration register one for setting thresholds that corespond to the fault mask settings.
- Parameters:
-
val - MASK_CJ_FAULT_THRESHOLD_HIGH
- MASK_CJ_FAULT_THRESHOLD_LOW
- MASK_TC_FAULT_THRESHOLD_HIGH
- MASK_TC_FAULT_THRESHOLD_LOW
temperature value that you want to program into a threshold register for temperatre
- Returns:
- return value that was programmed into the threshold register
Definition at line 522 of file MAX31856.cpp.
bool setNumSamplesAvg | ( | uint8_t | val ) |
Sets bits in the configuration register one for setting how many readings are taken.
- Parameters:
-
val - CR1_AVG_TC_SAMPLES_1 (Power On Default value)
- CR1_AVG_TC_SAMPLES_2
- CR1_AVG_TC_SAMPLES_4
- CR1_AVG_TC_SAMPLES_8
- CR1_AVG_TC_SAMPLES_16
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 385 of file MAX31856.cpp.
bool setOneShotMode | ( | uint8_t | val ) |
Sets bits in the configuration register zero for enabling one conversion to take place.
- Parameters:
-
val - CR0_1_SHOT_MODE_NO_CONVERSION (Power On Default value)
- 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)
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 257 of file MAX31856.cpp.
bool setOpenCircuitFaultDetection | ( | uint8_t | val ) |
Sets bits in the configuration register zero for configuring open circuit fault detection.
- Parameters:
-
val - CR0_OC_DETECT_DISABLED (Power On Default value)
- CR0_OC_DETECT_ENABLED_R_LESS_5k
- CR0_OC_DETECT_ENABLED_TC_LESS_2ms
- CR0_OC_DETECT_ENABLED_TC_MORE_2ms
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 273 of file MAX31856.cpp.
bool setThermocoupleType | ( | uint8_t | val ) |
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.
- Parameters:
-
val - CR1_TC_TYPE_B
- CR1_TC_TYPE_E
- CR1_TC_TYPE_J
- CR1_TC_TYPE_K (Power On Default value)
- CR1_TC_TYPE_N
- CR1_TC_TYPE_R
- CR1_TC_TYPE_S
- CR1_TC_TYPE_T
- CR1_TC_TYPE_VOLT_MODE_GAIN_8
- CR1_TC_TYPE_VOLT_MODE_GAIN_32
- Returns:
- 1 on success
- 0 if there is an incorrect parameter that is passed in as parameter val
Definition at line 422 of file MAX31856.cpp.
Generated on Tue Jul 12 2022 21:14:23 by 1.7.2