From 03944e6cd8858f42ab0cf730d8e1dbddd559aa81 Mon Sep 17 00:00:00 2001 From: DAVe3283 Date: Tue, 7 Jun 2022 15:58:32 -0600 Subject: [PATCH] Fix bogus reading on no communication with MAX31865 (#3505) --- CODEOWNERS | 1 + esphome/components/max31865/max31865.cpp | 8 ++++++++ esphome/components/max31865/sensor.py | 3 +++ 3 files changed, 12 insertions(+) diff --git a/CODEOWNERS b/CODEOWNERS index d5ce5e6920..3cb38fce06 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -103,6 +103,7 @@ esphome/components/lilygo_t5_47/touchscreen/* @jesserockz esphome/components/lock/* @esphome/core esphome/components/logger/* @esphome/core esphome/components/ltr390/* @sjtrny +esphome/components/max31865/* @DAVe3283 esphome/components/max44009/* @berfenger esphome/components/max7219digit/* @rspaargaren esphome/components/max9611/* @mckaymatthew diff --git a/esphome/components/max31865/max31865.cpp b/esphome/components/max31865/max31865.cpp index 126915dc15..152d7b340b 100644 --- a/esphome/components/max31865/max31865.cpp +++ b/esphome/components/max31865/max31865.cpp @@ -94,6 +94,14 @@ void MAX31865Sensor::read_data_() { const uint16_t rtd_resistance_register = this->read_register_16_(RTD_RESISTANCE_MSB_REG); this->write_config_(0b11000000, 0b00000000); + // Check for bad connection + if (rtd_resistance_register == 0b0000000000000000 || rtd_resistance_register == 0b1111111111111111) { + ESP_LOGE(TAG, "SPI bus read all 0 or all 1 (0x%04X), check MAX31865 wiring & power.", rtd_resistance_register); + this->publish_state(NAN); + this->status_set_error(); + return; + } + // Check faults const uint8_t faults = this->read_register_(FAULT_STATUS_REG); if ((has_fault_ = faults & 0b00111100)) { diff --git a/esphome/components/max31865/sensor.py b/esphome/components/max31865/sensor.py index 6eb8bd400d..704f945171 100644 --- a/esphome/components/max31865/sensor.py +++ b/esphome/components/max31865/sensor.py @@ -11,6 +11,9 @@ from esphome.const import ( UNIT_CELSIUS, ) +CODEOWNERS = ["@DAVe3283"] +DEPENDENCIES = ["spi"] + max31865_ns = cg.esphome_ns.namespace("max31865") MAX31865Sensor = max31865_ns.class_( "MAX31865Sensor", sensor.Sensor, cg.PollingComponent, spi.SPIDevice