Fork of DS1820 that can function with the data and parasite power pin being the same.
Dependents: AutonomousDAQ AutonomousDAQ
Fork of DS1820 by
Diff: DS1820.cpp
- Revision:
- 7:aceafdd78b28
- Parent:
- 5:00539fbc6d79
- Child:
- 8:7f64569563ea
--- a/DS1820.cpp Mon Sep 22 00:38:39 2014 +0000 +++ b/DS1820.cpp Thu Oct 30 05:55:15 2014 +0000 @@ -7,17 +7,20 @@ char DS1820_search_ROM[8]; -DS1820::DS1820 (PinName data_pin, PinName power_pin) : _datapin(data_pin), _parasitepin(power_pin) { +DS1820::DS1820 (PinName data_pin, PinName power_pin, const bool useParasitePwr) : + _parasite_power(useParasitePwr), + _parasite_power_pn(power_pin), + _datapin(data_pin), _parasitepin(power_pin) { int byte_counter; - _parasite_power = true; for(byte_counter=0;byte_counter<8;byte_counter++) ROM[byte_counter] = 0xFF; for(byte_counter=0;byte_counter<9;byte_counter++) RAM[byte_counter] = 0x00; } -DS1820::DS1820 (PinName data_pin) : _datapin(data_pin), _parasitepin(NC) { +DS1820::DS1820 (PinName data_pin) : _parasite_power(false), + _parasite_power_pn(NC), + _datapin(data_pin), _parasitepin(NC) { int byte_counter; - _parasite_power = false; for(byte_counter=0;byte_counter<8;byte_counter++) ROM[byte_counter] = 0xFF; for(byte_counter=0;byte_counter<9;byte_counter++) @@ -164,6 +167,7 @@ } void DS1820::search_ROM_setup() { + _datapin.mode(PullUp); extern bool DS1820_done_flag; extern int DS1820_last_descrepancy; extern char DS1820_search_ROM[8]; @@ -250,6 +254,7 @@ } int DS1820::convert_temperature(bool wait, devices device) { + _datapin.mode(PullUp); // Convert temperature into scratchpad RAM for all devices at once int delay_time = 750; // Default delay time char resolution; @@ -371,6 +376,7 @@ // this allowed an expanded resolution of 1/150th of a deg C. I wouldn't rely on this // being super acurate, but it does allow for a smooth display in the 1/10ths of a // deg C or F scales. + _datapin.mode(PullUp); float answer, remaining_count, count_per_degree; int reading; read_RAM();