From 8b011b8773c3ca52ddb57affdb113607940bc0eb Mon Sep 17 00:00:00 2001 From: AnHardt Date: Thu, 12 Mar 2020 02:33:56 +0100 Subject: [PATCH] Add Selftest Using code from #5 --- Adafruit_MAX31865.cpp | 19 +++++++++++++++++++ Adafruit_MAX31865.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Adafruit_MAX31865.cpp b/Adafruit_MAX31865.cpp index 30b2b05..6067939 100644 --- a/Adafruit_MAX31865.cpp +++ b/Adafruit_MAX31865.cpp @@ -103,6 +103,25 @@ uint8_t Adafruit_MAX31865::readFault(void) { return readRegister8(MAX31856_FAULTSTAT_REG); } +/**************************************************************************/ +/*! + @brief Read the raw 8-bit FAULTSTAT register + @param b If true perform a automatic fault-detection cycle + @return The raw unsigned 8-bit FAULT status register +*/ +/**************************************************************************/ +uint8_t Adafruit_MAX31865::readFault(boolean b) { + uint8_t t = readRegister8(MAX31856_CONFIG_REG); + if (b) { + t |= MAX31856_CONFIG_FAULTDETCYCLE; // trigger automatic fault-detection cycle + writeRegister8(MAX31856_CONFIG_REG, t); + delay(5); // wait for 5ms + } + + return readRegister8(MAX31856_FAULTSTAT_REG); +} + + /**************************************************************************/ /*! @brief Clear all faults in FAULTSTAT diff --git a/Adafruit_MAX31865.h b/Adafruit_MAX31865.h index e30bed8..e9cfd79 100644 --- a/Adafruit_MAX31865.h +++ b/Adafruit_MAX31865.h @@ -24,6 +24,7 @@ #define MAX31856_CONFIG_1SHOT 0x20 #define MAX31856_CONFIG_3WIRE 0x10 #define MAX31856_CONFIG_24WIRE 0x00 +#define MAX31865_CONFIG_FAULTDETCYCLE 0x84 #define MAX31856_CONFIG_FAULTSTAT 0x02 #define MAX31856_CONFIG_FILT50HZ 0x01 #define MAX31856_CONFIG_FILT60HZ 0x00 @@ -68,6 +69,7 @@ class Adafruit_MAX31865 { bool begin(max31865_numwires_t x = MAX31865_2WIRE); uint8_t readFault(void); + uint8_t readFault(boolean b); void clearFault(void); uint16_t readRTD();