components/esp32-ds18b20/ds18b20.c

changeset 91
255a75322212
parent 1
ad2c8b13eb88
equal deleted inserted replaced
90:1397fb0b3a9d 91:255a75322212
131 owb_write_rom_code(ds18b20_info->bus, ds18b20_info->rom_code); 131 owb_write_rom_code(ds18b20_info->bus, ds18b20_info->rom_code);
132 } 132 }
133 } 133 }
134 else 134 else
135 { 135 {
136 ESP_LOGE(TAG, "ds18b20 device not responding"); 136 ESP_LOGE(TAG, "ds18b20 no response");
137 } 137 }
138 } 138 }
139 return present; 139 return present;
140 } 140 }
141 141
148 { 148 {
149 float elapsed_time = 0.0f; 149 float elapsed_time = 0.0f;
150 if (_check_resolution(resolution)) 150 if (_check_resolution(resolution))
151 { 151 {
152 int divisor = 1 << (DS18B20_RESOLUTION_12_BIT - resolution); 152 int divisor = 1 << (DS18B20_RESOLUTION_12_BIT - resolution);
153 ESP_LOGD(TAG, "divisor %d", divisor);
154 float max_conversion_time = (float)T_CONV / (float)divisor; 153 float max_conversion_time = (float)T_CONV / (float)divisor;
155 int ticks = ceil(max_conversion_time / portTICK_PERIOD_MS); 154 int ticks = ceil(max_conversion_time / portTICK_PERIOD_MS);
156 ESP_LOGD(TAG, "wait for conversion: %.3f ms, %d ticks", max_conversion_time, ticks);
157 155
158 // wait at least this maximum conversion time 156 // wait at least this maximum conversion time
159 vTaskDelay(ticks); 157 vTaskDelay(ticks);
160 158
161 // TODO: measure elapsed time more accurately 159 // TODO: measure elapsed time more accurately
377 owb_write_byte(bus, DS18B20_FUNCTION_TEMP_CONVERT); 375 owb_write_byte(bus, DS18B20_FUNCTION_TEMP_CONVERT);
378 result = true; 376 result = true;
379 } 377 }
380 else 378 else
381 { 379 {
382 ESP_LOGE(TAG, "ds18b20 device not responding"); 380 ESP_LOGE(TAG, "ds18b20 no response");
383 } 381 }
384 } 382 }
385 return result; 383 return result;
386 } 384 }
387 385
461 err = DS18B20_ERROR_OWB; 459 err = DS18B20_ERROR_OWB;
462 } 460 }
463 } 461 }
464 else 462 else
465 { 463 {
466 ESP_LOGE(TAG, "ds18b20 device not responding"); 464 ESP_LOGE(TAG, "ds18b20 no response");
467 err = DS18B20_ERROR_DEVICE; 465 err = DS18B20_ERROR_DEVICE;
468 } 466 }
469 } 467 }
470 return err; 468 return err;
471 } 469 }

mercurial