Skip to content

Commit

Permalink
Merge pull request #40 from caternuson/iss5_faults
Browse files Browse the repository at this point in the history
Add fault check cycle modes
  • Loading branch information
caternuson authored Oct 24, 2022
2 parents 6875f69 + efced8a commit 0e08be5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
24 changes: 23 additions & 1 deletion Adafruit_MAX31865.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,32 @@ bool Adafruit_MAX31865::begin(max31865_numwires_t wires) {
/**************************************************************************/
/*!
@brief Read the raw 8-bit FAULTSTAT register
@param fault_cycle The fault cycle type to run. Can be MAX31865_FAULT_NONE,
MAX31865_FAULT_AUTO, MAX31865_FAULT_MANUAL_RUN, or
MAX31865_FAULT_MANUAL_FINISH
@return The raw unsigned 8-bit FAULT status register
*/
/**************************************************************************/
uint8_t Adafruit_MAX31865::readFault(void) {
uint8_t Adafruit_MAX31865::readFault(max31865_fault_cycle_t fault_cycle) {
if (fault_cycle) {
uint8_t cfg_reg = readRegister8(MAX31865_CONFIG_REG);
cfg_reg &= 0x11; // mask out wire and filter bits
switch (fault_cycle) {
case MAX31865_FAULT_AUTO:
writeRegister8(MAX31865_CONFIG_REG, (cfg_reg | 0b10000100));
delay(1);
break;
case MAX31865_FAULT_MANUAL_RUN:
writeRegister8(MAX31865_CONFIG_REG, (cfg_reg | 0b10001000));
return 0;
case MAX31865_FAULT_MANUAL_FINISH:
writeRegister8(MAX31865_CONFIG_REG, (cfg_reg | 0b10001100));
return 0;
case MAX31865_FAULT_NONE:
default:
break;
}
}
return readRegister8(MAX31865_FAULTSTAT_REG);
}

Expand Down
9 changes: 8 additions & 1 deletion Adafruit_MAX31865.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ typedef enum max31865_numwires {
MAX31865_4WIRE = 0
} max31865_numwires_t;

typedef enum {
MAX31865_FAULT_NONE = 0,
MAX31865_FAULT_AUTO,
MAX31865_FAULT_MANUAL_RUN,
MAX31865_FAULT_MANUAL_FINISH
} max31865_fault_cycle_t;

/*! Interface class for the MAX31865 RTD Sensor reader */
class Adafruit_MAX31865 {
public:
Expand All @@ -69,7 +76,7 @@ class Adafruit_MAX31865 {

bool begin(max31865_numwires_t x = MAX31865_2WIRE);

uint8_t readFault(void);
uint8_t readFault(max31865_fault_cycle_t fault_cycle = MAX31865_FAULT_AUTO);
void clearFault(void);
uint16_t readRTD();

Expand Down

0 comments on commit 0e08be5

Please sign in to comment.