Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Klipper3d/klipper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2022-09-19 20:28:45 +0300
committerKevin O'Connor <kevin@koconnor.net>2022-09-23 18:55:43 +0300
commit4e930294b80966a41c69a6343353828a166ff226 (patch)
tree313f5b3e96f49793c2c882d7e7cdb0f97fcb72b2
parentddb59440a88d74f3cc10dc22978ee6f93a69fc71 (diff)
thermocouple: Report fault information in fault field
Send the fault information explicitly in the query_thermocouple fault field for max6675, max31855, and max31865. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/extras/spi_temperature.py12
-rw-r--r--src/thermocouple.c18
2 files changed, 12 insertions, 18 deletions
diff --git a/klippy/extras/spi_temperature.py b/klippy/extras/spi_temperature.py
index 1a45a6246..be8cc11e8 100644
--- a/klippy/extras/spi_temperature.py
+++ b/klippy/extras/spi_temperature.py
@@ -193,11 +193,11 @@ class MAX31855(SensorBase):
def __init__(self, config):
SensorBase.__init__(self, config, "MAX31855", spi_mode=0)
def calc_temp(self, adc, fault):
- if adc & 0x1:
+ if fault & 0x1:
self.fault("MAX31855 : Open Circuit")
- if adc & 0x2:
+ if fault & 0x2:
self.fault("MAX31855 : Short to GND")
- if adc & 0x4:
+ if fault & 0x4:
self.fault("MAX31855 : Short to Vcc")
adc = adc >> MAX31855_SCALE
# Fix sign bit:
@@ -222,9 +222,9 @@ class MAX6675(SensorBase):
def __init__(self, config):
SensorBase.__init__(self, config, "MAX6675", spi_mode=0)
def calc_temp(self, adc, fault):
- if adc & 0x02:
+ if fault & 0x02:
self.fault("Max6675 : Device ID error")
- if adc & 0x04:
+ if fault & 0x04:
self.fault("Max6675 : Thermocouple Open Fault")
adc = adc >> MAX6675_SCALE
# Fix sign bit:
@@ -293,7 +293,7 @@ class MAX31865(SensorBase):
self.fault("Max31865 VRTD- is less than 0.85 * VBIAS, FORCE- open")
if fault & 0x04:
self.fault("Max31865 Overvoltage or undervoltage fault")
- if fault & 0x03:
+ if not fault & 0xfc:
self.fault("Max31865 Unspecified error")
adc = adc >> 1 # remove fault bit
R_div_nominal = adc * self.adc_to_resist_div_nominal
diff --git a/src/thermocouple.c b/src/thermocouple.c
index 412317fbe..2022686af 100644
--- a/src/thermocouple.c
+++ b/src/thermocouple.c
@@ -90,6 +90,8 @@ thermocouple_respond(struct thermocouple_spi *spi, uint32_t next_begin_time
/* check the result and stop if below or above allowed range */
if (value < spi->min_value || value > spi->max_value)
try_shutdown("Thermocouple ADC out of range");
+ if (fault)
+ try_shutdown("Thermocouple reader fault");
}
static void
@@ -101,10 +103,7 @@ thermocouple_handle_max31855(struct thermocouple_spi *spi
uint32_t value;
memcpy(&value, msg, sizeof(value));
value = be32_to_cpu(value);
- thermocouple_respond(spi, next_begin_time, value, 0, oid);
- // Kill after data send, host decode an error
- if (value & 0x04)
- try_shutdown("Thermocouple reader fault");
+ thermocouple_respond(spi, next_begin_time, value, value & 0x07, oid);
}
#define MAX31856_LTCBH_REG 0x0C
@@ -142,10 +141,8 @@ thermocouple_handle_max31865(struct thermocouple_spi *spi
msg[0] = MAX31865_FAULTSTAT_REG;
msg[1] = 0x00;
spidev_transfer(spi->spi, 1, 2, msg);
- thermocouple_respond(spi, next_begin_time, value, msg[1], oid);
- // Kill after data send, host decode an error
- if (value & 0x0001)
- try_shutdown("Thermocouple reader fault");
+ uint8_t fault = (msg[1] & ~0x03) | (value & 0x0001);
+ thermocouple_respond(spi, next_begin_time, value, fault, oid);
}
static void
@@ -157,10 +154,7 @@ thermocouple_handle_max6675(struct thermocouple_spi *spi
uint16_t value;
memcpy(&value, msg, sizeof(msg));
value = be16_to_cpu(value);
- thermocouple_respond(spi, next_begin_time, value, 0, oid);
- // Kill after data send, host decode an error
- if (value & 0x04)
- try_shutdown("Thermocouple reader fault");
+ thermocouple_respond(spi, next_begin_time, value, value & 0x06, oid);
}
// task to read thermocouple and send response