10 static const char *
const TAG =
"max31865";
16 if (faults & 0b11111100) {
17 if (faults & (1 << 2)) {
18 ESP_LOGW(TAG,
"Overvoltage/undervoltage fault between measurements");
20 if (faults & (1 << 3)) {
21 ESP_LOGW(TAG,
"RTDIN- < 0.85 x V_BIAS (FORCE- open) between measurements");
23 if (faults & (1 << 4)) {
24 ESP_LOGW(TAG,
"REFIN- < 0.85 x V_BIAS (FORCE- open) between measurements");
26 if (faults & (1 << 5)) {
27 ESP_LOGW(TAG,
"REFIN- > 0.85 x V_BIAS between measurements");
30 if (faults & (1 << 6)) {
31 ESP_LOGW(TAG,
"RTD Low Threshold between measurements");
33 if (faults & (1 << 7)) {
34 ESP_LOGW(TAG,
"RTD High Threshold between measurements");
42 const uint32_t start_time =
micros();
44 uint32_t fault_detect_time;
47 fault_detect_time =
micros() - start_time;
48 if ((fault_detect_time >= 6000) && (config & 0b00001100)) {
50 "Fault detection incomplete (0x%02X) after %" PRIu32
"μs (datasheet spec is 600μs max)! Aborting read.",
51 config, fault_detect_time);
56 }
while (config & 0b00001100);
57 ESP_LOGV(TAG,
"Fault detection completed in %" PRIu32
"μs.", fault_detect_time);
68 ESP_LOGCONFIG(TAG,
"Setting up MAX31865Sensor '%s'...", this->
name_.
c_str());
83 LOG_SENSOR(
"",
"MAX31865",
this);
84 LOG_PIN(
" CS Pin: ", this->
cs_);
85 LOG_UPDATE_INTERVAL(
this);
88 ESP_LOGCONFIG(TAG,
" Mains Filter: %s",
100 if (rtd_resistance_register == 0b0000000000000000 || rtd_resistance_register == 0b1111111111111111) {
101 ESP_LOGE(TAG,
"SPI bus read all 0 or all 1 (0x%04X), check MAX31865 wiring & power.", rtd_resistance_register);
111 if (faults & (1 << 2)) {
112 ESP_LOGE(TAG,
"Overvoltage/undervoltage fault");
114 if (faults & (1 << 3)) {
115 ESP_LOGE(TAG,
"RTDIN- < 0.85 x V_BIAS (FORCE- open)");
117 if (faults & (1 << 4)) {
118 ESP_LOGE(TAG,
"REFIN- < 0.85 x V_BIAS (FORCE- open)");
120 if (faults & (1 << 5)) {
121 ESP_LOGE(TAG,
"REFIN- > 0.85 x V_BIAS");
131 if (faults & (1 << 6)) {
132 ESP_LOGW(TAG,
"RTD Low Threshold");
134 if (faults & (1 << 7)) {
135 ESP_LOGW(TAG,
"RTD High Threshold");
143 if (rtd_resistance_register & 0x0001) {
144 ESP_LOGW(TAG,
"RTD Resistance Registers fault bit set! (0x%04X)", rtd_resistance_register);
147 const float rtd_ratio =
static_cast<float>(rtd_resistance_register >> 1) / static_cast<float>((1 << 15) - 1);
149 ESP_LOGV(TAG,
"RTD read complete. %.5f (ratio) * %.1fΩ (reference) = %.2fΩ --> %.2f°C", rtd_ratio,
158 value |= (bits << start_position);
168 ESP_LOGVV(TAG,
"write_register_ 0x%02X: 0x%02X", reg, value);
176 ESP_LOGVV(TAG,
"read_register_ 0x%02X: 0x%02X", reg, value);
186 const uint16_t value((msb << 8) | lsb);
187 ESP_LOGVV(TAG,
"read_register_16_ 0x%02X: 0x%04X", reg, value);
196 const float a = 3.9083e-3;
197 const float b = -5.775e-7;
199 const float z2 = a * a - 4 * b;
201 const float z4 = 2 * b;
206 const float pos_temp = (z1 + std::sqrt(z2 + (z3 * rtd_resistance))) / z4;
215 rtd_resistance *= 100;
217 float rpoly = rtd_resistance;
218 float neg_temp = -242.02f;
219 neg_temp += 2.2228f * rpoly;
220 rpoly *= rtd_resistance;
221 neg_temp += 2.5859e-3f * rpoly;
222 rpoly *= rtd_resistance;
223 neg_temp -= 4.8260e-6f * rpoly;
224 rpoly *= rtd_resistance;
225 neg_temp -= 2.8183e-8f * rpoly;
226 rpoly *= rtd_resistance;
227 neg_temp += 1.5243e-10f * rpoly;
const float DATA
For components that import data from directly connected sensors like DHT.
uint16_t read_register_16_(uint8_t reg)
void status_set_warning(const char *message="unspecified")
void spi_setup() override
float get_setup_priority() const override
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void write_byte(uint8_t data)
uint32_t IRAM_ATTR HOT micros()
void write_register_(uint8_t reg, uint8_t value)
void status_set_error(const char *message="unspecified")
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
float rtd_nominal_resistance_
float calc_temperature_(float rtd_ratio)
void write_config_(uint8_t mask, uint8_t bits, uint8_t start_position=0)
constexpr const char * c_str() const
MAX31865ConfigFilter filter_
void status_clear_error()
uint8_t read_register_(uint8_t reg)
Implementation of SPI Controller mode.
void dump_config() override
float reference_resistance_