Skip to content

Commit f243a01

Browse files
committed
Add ability to retrieve the TC fault cause
1 parent f534edf commit f243a01

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/utility/THERMOCOUPLE/MAX31855.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ float MAX31855Class::readTCTemperature() {
146146
rawword = readSensor();
147147

148148
// Check for reading error
149-
if (rawword & 0x7) {
149+
lastFault = rawword & _faultMask;
150+
if (_lastFault) {
150151
return NAN;
151152
}
153+
152154
// The cold junction temperature is stored in the last 14 word's bits
153155
// whereas the ttermocouple temperature (non linearized) is in the topmost 18 bits
154156
// sent by the Thermocouple-to-Digital Converter
@@ -221,6 +223,15 @@ void MAX31855Class::setColdOffset(float offset) {
221223
_coldOffset = offset;
222224
}
223225

226+
void MAX31855Class::setFaultChecks(uint8_t faults) {
227+
_faultMask = faults & TC_FAULT_ALL;
228+
}
229+
230+
uint8_t MAX31855Class::getLastFault() {
231+
uint8_t tempLastFault = _lastFault;
232+
_lastFault = 0;
233+
return tempLastFault;
234+
}
224235

225236
void MAX31855Class::setTCType(uint8_t type) {
226237
_current_probe_type = type;

src/utility/THERMOCOUPLE/MAX31855.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#define PROBE_J PROBE_TC_J
1515
#define PROBE_T PROBE_TC_T
1616

17+
#define TC_FAULT_NONE (0x00) // Disable all fault checks
18+
#define TC_FAULT_OPEN (0x01) // Enable open circuit fault check
19+
#define TC_FAULT_SHORT_GND (0x02) // Enable short to GND fault check
20+
#define TC_FAULT_SHORT_VCC (0x04) // Enable short to VCC fault check
21+
#define TC_FAULT_ALL (0x07) // Enable all fault checks
22+
1723
class MAX31855Class {
1824
public:
1925
MAX31855Class(PinName cs = MC_TC_CS_PIN, SPIClass& spi = SPI);
@@ -24,11 +30,17 @@ class MAX31855Class {
2430
float readTCTemperature();
2531
float readReferenceTemperature();
2632
void setColdOffset(float offset);
33+
34+
void setFaultChecks(uint8_t faults);
35+
uint8_t getLastFault();
36+
2737
void setTCType(uint8_t type);
2838

2939
private:
3040
uint32_t readSensor();
3141
float _coldOffset;
42+
uint8_t _faultMask = TC_FAULT_ALL;
43+
uint8_t _lastFault = 0;
3244
uint8_t _current_probe_type;
3345
PinName _cs;
3446
SPIClass* _spi;

0 commit comments

Comments
 (0)