mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-29 21:56:35 +00:00
Fix DS18S20 temperature calculation
Fix DS18S20 temperature calculation (#5375)
This commit is contained in:
parent
d70ed77f1a
commit
9f42e6dced
@ -2,6 +2,7 @@
|
|||||||
* Add command SetOption37 for RGBCW color mapping (#5326)
|
* Add command SetOption37 for RGBCW color mapping (#5326)
|
||||||
* Add Korean language translations (#5344)
|
* Add Korean language translations (#5344)
|
||||||
* Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373)
|
* Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373)
|
||||||
|
* Fix DS18S20 temperature calculation (#5375)
|
||||||
*
|
*
|
||||||
* 6.4.1.18 20190221
|
* 6.4.1.18 20190221
|
||||||
* Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
|
* Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215)
|
||||||
|
@ -310,9 +310,6 @@ bool Ds18x20Read(uint8_t sensor)
|
|||||||
{
|
{
|
||||||
uint8_t data[9];
|
uint8_t data[9];
|
||||||
int8_t sign = 1;
|
int8_t sign = 1;
|
||||||
uint16_t temp12 = 0;
|
|
||||||
int16_t temp14 = 0;
|
|
||||||
float temp9 = 0.0;
|
|
||||||
|
|
||||||
uint8_t index = ds18x20_sensor[sensor].index;
|
uint8_t index = ds18x20_sensor[sensor].index;
|
||||||
if (ds18x20_sensor[index].valid) { ds18x20_sensor[index].valid--; }
|
if (ds18x20_sensor[index].valid) { ds18x20_sensor[index].valid--; }
|
||||||
@ -325,48 +322,47 @@ bool Ds18x20Read(uint8_t sensor)
|
|||||||
}
|
}
|
||||||
if (OneWireCrc8(data)) {
|
if (OneWireCrc8(data)) {
|
||||||
switch(ds18x20_sensor[index].address[0]) {
|
switch(ds18x20_sensor[index].address[0]) {
|
||||||
case DS18S20_CHIPID:
|
case DS18S20_CHIPID: {
|
||||||
if (data[1] > 0x80) {
|
if (data[1] > 0x80) {
|
||||||
data[0] = (~data[0]) +1;
|
data[0] = (~data[0]) +1;
|
||||||
sign = -1; // App-Note fix possible sign error
|
sign = -1; // App-Note fix possible sign error
|
||||||
|
}
|
||||||
|
float temp9 = (float)(data[0] >> 1) * sign;
|
||||||
|
ds18x20_sensor[index].temperature = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
||||||
|
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (data[0] & 1) {
|
case DS1822_CHIPID:
|
||||||
temp9 = ((data[0] >> 1) + 0.5) * sign;
|
case DS18B20_CHIPID: {
|
||||||
} else {
|
if (data[4] != 0x7F) {
|
||||||
temp9 = (data[0] >> 1) * sign;
|
data[4] = 0x7F; // Set resolution to 12-bit
|
||||||
}
|
OneWireReset();
|
||||||
ds18x20_sensor[index].temperature = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
OneWireSelect(ds18x20_sensor[index].address);
|
||||||
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
OneWireWrite(W1_WRITE_SCRATCHPAD);
|
||||||
return true;
|
OneWireWrite(data[2]); // Th Register
|
||||||
case DS1822_CHIPID:
|
OneWireWrite(data[3]); // Tl Register
|
||||||
case DS18B20_CHIPID:
|
OneWireWrite(data[4]); // Configuration Register
|
||||||
if (data[4] != 0x7F) {
|
OneWireSelect(ds18x20_sensor[index].address);
|
||||||
data[4] = 0x7F; // Set resolution to 12-bit
|
OneWireWrite(W1_WRITE_EEPROM); // Save scratchpad to EEPROM
|
||||||
OneWireReset();
|
|
||||||
OneWireSelect(ds18x20_sensor[index].address);
|
|
||||||
OneWireWrite(W1_WRITE_SCRATCHPAD);
|
|
||||||
OneWireWrite(data[2]); // Th Register
|
|
||||||
OneWireWrite(data[3]); // Tl Register
|
|
||||||
OneWireWrite(data[4]); // Configuration Register
|
|
||||||
OneWireSelect(ds18x20_sensor[index].address);
|
|
||||||
OneWireWrite(W1_WRITE_EEPROM); // Save scratchpad to EEPROM
|
|
||||||
#ifdef W1_PARASITE_POWER
|
#ifdef W1_PARASITE_POWER
|
||||||
w1_power_until = millis() + 10; // 10ms specified duration for EEPROM write
|
w1_power_until = millis() + 10; // 10ms specified duration for EEPROM write
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
uint16_t temp12 = (data[1] << 8) + data[0];
|
||||||
|
if (temp12 > 2047) {
|
||||||
|
temp12 = (~temp12) +1;
|
||||||
|
sign = -1;
|
||||||
|
}
|
||||||
|
ds18x20_sensor[index].temperature = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16
|
||||||
|
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
temp12 = (data[1] << 8) + data[0];
|
case MAX31850_CHIPID: {
|
||||||
if (temp12 > 2047) {
|
int16_t temp14 = (data[1] << 8) + (data[0] & 0xFC);
|
||||||
temp12 = (~temp12) +1;
|
ds18x20_sensor[index].temperature = ConvertTemp(temp14 * 0.0625); // Divide by 16
|
||||||
sign = -1;
|
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
ds18x20_sensor[index].temperature = ConvertTemp(sign * temp12 * 0.0625); // Divide by 16
|
|
||||||
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
|
||||||
return true;
|
|
||||||
case MAX31850_CHIPID:
|
|
||||||
temp14 = (data[1] << 8) + (data[0] & 0xFC);
|
|
||||||
ds18x20_sensor[index].temperature = ConvertTemp(temp14 * 0.0625); // Divide by 16
|
|
||||||
ds18x20_sensor[index].valid = SENSOR_MAX_MISS;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,11 +126,7 @@ bool Ds18x20Read(uint8_t sensor, float &t)
|
|||||||
data[0] = (~data[0]) +1;
|
data[0] = (~data[0]) +1;
|
||||||
sign = -1; // App-Note fix possible sign error
|
sign = -1; // App-Note fix possible sign error
|
||||||
}
|
}
|
||||||
if (data[0] & 1) {
|
temp9 = (float)(data[0] >> 1) * sign;
|
||||||
temp9 = ((data[0] >> 1) + 0.5) * sign;
|
|
||||||
} else {
|
|
||||||
temp9 = (data[0] >> 1) * sign;
|
|
||||||
}
|
|
||||||
t = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
t = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
||||||
break;
|
break;
|
||||||
case DS18B20_CHIPID:
|
case DS18B20_CHIPID:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user