From 5558da527abf2a3b0cb5c06d0593981c934f177c Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Wed, 3 Jun 2020 16:09:28 +1000 Subject: [PATCH] Add MAX6675 sensor This is basically a cut down version of MAX31855 without reference temperature reading and lower resolution (only positive, 12bit only). This implements 16bit protocol (31855 uses 32bit). SetOption94 enables the new behavior. Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * treat occasional 0xfff as an error * do not add new sensor pins, use SetOption94 instead --- tasmota/settings.h | 2 +- tasmota/xsns_39_max31855.ino | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 0ad7a3533..1b0cc0951 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -113,7 +113,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t fade_at_startup : 1; // bit 9 (v8.2.0.3) - SetOption91 - Enable light fading at start/power on uint32_t pwm_ct_mode : 1; // bit 10 (v8.2.0.4) - SetOption92 - Set PWM Mode from regular PWM to ColorTemp control (Xiaomi Philips ...) uint32_t compress_rules_cpu : 1; // bit 11 (v8.2.0.6) - SetOption93 - Keep uncompressed rules in memory to avoid CPU load of uncompressing at each tick - uint32_t spare12 : 1; + uint32_t max6675 : 1; // bit 12 (v8.3.1.2) - SetOption94 - Implement simpler MAX6675 protocol instead of MAX31855 uint32_t spare13 : 1; uint32_t spare14 : 1; uint32_t spare15 : 1; diff --git a/tasmota/xsns_39_max31855.ino b/tasmota/xsns_39_max31855.ino index c8cdfc7aa..e80f879c5 100644 --- a/tasmota/xsns_39_max31855.ino +++ b/tasmota/xsns_39_max31855.ino @@ -50,6 +50,20 @@ void MAX31855_Init(void){ * Acquires the raw data via SPI, checks for MAX31855 errors and fills result structure */ void MAX31855_GetResult(void){ + // Controlled via SetOption94 + if (Settings.flag4.max6675) { + int32_t RawData = MAX31855_ShiftIn(16); + int32_t temp = (RawData >> 3) & ((1 << 12) - 1); + + /* Occasionally the sensor returns 0xfff, consider it an error */ + if (temp == ((1 << 12) - 1)) + return; + + MAX31855_Result.ErrorCode = 0; + MAX31855_Result.ReferenceTemperature = NAN; + MAX31855_Result.ProbeTemperature = ConvertTemp(0.25 * temp); + return; + } int32_t RawData = MAX31855_ShiftIn(32); uint8_t probeerror = RawData & 0x7;