Merge pull request #295 from sheinz/fix/ds18b20_negative_temp

ds18b20 fix for temperature below zero
This commit is contained in:
Ruslan V. Uss 2016-11-26 04:25:18 +06:00 committed by GitHub
commit 4d00566421

View file

@ -33,7 +33,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
uint8_t sensor_id = 0;
onewire_search_start(&search);
while ((addr = onewire_search_next(&search, pin)) != ONEWIRE_NONE) {
uint8_t crc = onewire_crc8((uint8_t *)&addr, 7);
if (crc != (addr >> 56)){
@ -44,10 +44,10 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
onewire_reset(pin);
onewire_select(pin, addr);
onewire_write(pin, DS18B20_CONVERT_T);
onewire_power(pin);
vTaskDelay(750 / portTICK_PERIOD_MS);
onewire_reset(pin);
onewire_select(pin, addr);
onewire_write(pin, DS18B20_READ_SCRATCHPAD);
@ -57,7 +57,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
for (int k=0;k<9;k++){
get[k]=onewire_read(pin);
}
//debug("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);
crc = onewire_crc8(get, 8);
@ -69,7 +69,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
uint8_t temp_msb = get[1]; // Sign byte + lsbit
uint8_t temp_lsb = get[0]; // Temp data plus lsb
uint16_t temp = temp_msb << 8 | temp_lsb;
float temperature;
temperature = (temp * 625.0)/10000;
@ -82,7 +82,7 @@ uint8_t ds18b20_read_all(uint8_t pin, ds_sensor_t *result) {
}
float ds18b20_read_single(uint8_t pin) {
onewire_reset(pin);
onewire_skip_rom(pin);
onewire_write(pin, DS18B20_CONVERT_T);
@ -93,13 +93,13 @@ float ds18b20_read_single(uint8_t pin) {
onewire_reset(pin);
onewire_skip_rom(pin);
onewire_write(pin, DS18B20_READ_SCRATCHPAD);
uint8_t get[10];
for (int k=0;k<9;k++){
get[k]=onewire_read(pin);
}
//debug("\n ScratchPAD DATA = %X %X %X %X %X %X %X %X %X\n",get[8],get[7],get[6],get[5],get[4],get[3],get[2],get[1],get[0]);
uint8_t crc = onewire_crc8(get, 8);
@ -110,9 +110,9 @@ float ds18b20_read_single(uint8_t pin) {
uint8_t temp_msb = get[1]; // Sign byte + lsbit
uint8_t temp_lsb = get[0]; // Temp data plus lsb
uint16_t temp = temp_msb << 8 | temp_lsb;
float temperature;
temperature = (temp * 625.0)/10000;
@ -157,7 +157,7 @@ bool ds18b20_read_scratchpad(int pin, ds18b20_addr_t addr, uint8_t *buffer) {
onewire_select(pin, addr);
}
onewire_write(pin, DS18B20_READ_SCRATCHPAD);
for (int i = 0; i < 8; i++) {
buffer[i] = onewire_read(pin);
}
@ -174,7 +174,7 @@ bool ds18b20_read_scratchpad(int pin, ds18b20_addr_t addr, uint8_t *buffer) {
float ds18b20_read_temperature(int pin, ds18b20_addr_t addr) {
uint8_t scratchpad[8];
int temp;
int16_t temp;
if (!ds18b20_read_scratchpad(pin, addr, scratchpad)) {
return NAN;