v5.12.0e - Fix MAX31850 higher temperatures

5.12.0e
 * Fix MAX31850 higher temperatures (#1269)
This commit is contained in:
Theo Arends 2018-03-11 17:44:58 +01:00
parent fa25b8c043
commit 9a421ab6a2
3 changed files with 39 additions and 15 deletions

View File

@ -4,6 +4,7 @@
* Add additional time offset to Wifi Retry based on device mac address (#2089)
* Add command Color6 RRGGBB for Clock hour marker color and command Rotation pixels for Clock rotation (#2092)
* Add HTML language header in local language (#2123)
* Fix MAX31850 higher temperatures (#1269)
*
* 5.12.0d
* Add support for optional MQTT drivers to be selected in user_config.h (#1992)

View File

@ -287,6 +287,8 @@ boolean Ds18x20Read(uint8_t sensor, float &t)
{
uint8_t data[9];
int8_t sign = 1;
uint16_t temp12 = 0;
int16_t temp14 = 0;
float temp9 = 0.0;
t = NAN;
@ -315,23 +317,30 @@ boolean Ds18x20Read(uint8_t sensor, float &t)
case DS1822_CHIPID:
case DS18B20_CHIPID:
if (data[4] != 0x7F) {
data[4] = 0x7F; // Set resolution to 12-bit
data[4] = 0x7F; // Set resolution to 12-bit
OneWireReset();
OneWireSelect(ds18x20_address[ds18x20_index[sensor]]);
OneWireWrite(W1_WRITE_SCRATCHPAD);
OneWireWrite(data[2]); // Th Register
OneWireWrite(data[3]); // Tl Register
OneWireWrite(data[4]); // Configuration Register
OneWireWrite(data[2]); // Th Register
OneWireWrite(data[3]); // Tl Register
OneWireWrite(data[4]); // Configuration Register
OneWireSelect(ds18x20_address[ds18x20_index[sensor]]);
OneWireWrite(W1_WRITE_EEPROM); // Save scratchpad to EEPROM
OneWireWrite(W1_WRITE_EEPROM); // Save scratchpad to EEPROM
}
case MAX31850_CHIPID:
uint16_t temp12 = (data[1] << 8) + data[0];
temp12 = (data[1] << 8) + data[0];
if (temp12 > 2047) {
temp12 = (~temp12) +1;
sign = -1;
}
t = ConvertTemp(sign * temp12 * 0.0625);
t = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16
break;
case MAX31850_CHIPID:
temp14 = (data[1] << 8) + (data[0] & 0xFC);
if (temp14 < 0) {
temp14 = (~temp14) +1;
sign = -1;
}
t = ConvertTemp(sign * temp14 * 0.0625); // Divide by 16
break;
}
}
@ -404,8 +413,13 @@ boolean Xsns05(byte function)
case FUNC_INIT:
Ds18x20Init();
break;
// case FUNC_EVERY_SECOND:
// if ((Settings.tele_period - tele_period) &3 == 3) {
// Ds18x20Convert(); // Start conversion every four seconds, takes up to one second
// }
// break;
case FUNC_PREP_BEFORE_TELEPERIOD:
Ds18x20Convert(); // Start conversion, takes up to one second
Ds18x20Convert(); // Start conversion, takes up to one second
break;
case FUNC_JSON_APPEND:
Ds18x20Show(1);
@ -413,7 +427,7 @@ boolean Xsns05(byte function)
#ifdef USE_WEBSERVER
case FUNC_WEB_APPEND:
Ds18x20Show(0);
Ds18x20Convert(); // Start conversion, takes up to one second
Ds18x20Convert(); // Start conversion, takes up to one second
break;
#endif // USE_WEBSERVER
}

View File

@ -103,6 +103,8 @@ boolean Ds18x20Read(uint8_t sensor, float &t)
{
byte data[12];
int8_t sign = 1;
uint16_t temp12 = 0;
int16_t temp14 = 0;
float temp9 = 0.0;
uint8_t present = 0;
@ -117,7 +119,7 @@ boolean Ds18x20Read(uint8_t sensor, float &t)
}
if (OneWire::crc8(data, 8) == data[8]) {
switch(ds18x20_address[ds18x20_index[sensor]][0]) {
case DS18S20_CHIPID: // DS18S20
case DS18S20_CHIPID:
if (data[1] > 0x80) {
data[0] = (~data[0]) +1;
sign = -1; // App-Note fix possible sign error
@ -129,14 +131,21 @@ boolean Ds18x20Read(uint8_t sensor, float &t)
}
t = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
break;
case DS18B20_CHIPID: // DS18B20
case MAX31850_CHIPID: // MAX31850
uint16_t temp12 = (data[1] << 8) + data[0];
case DS18B20_CHIPID:
temp12 = (data[1] << 8) + data[0];
if (temp12 > 2047) {
temp12 = (~temp12) +1;
sign = -1;
}
t = ConvertTemp(sign * temp12 * 0.0625);
t = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16
break;
case MAX31850_CHIPID:
temp14 = (data[1] << 8) + (data[0] & 0xFC);
if (temp14 < 0) {
temp14 = (~temp14) +1;
sign = -1;
}
t = ConvertTemp(sign * temp14 * 0.0625); // Divide by 16
break;
}
}