Fork of DS1820 that can function with the data and parasite power pin being the same.
Dependents: AutonomousDAQ AutonomousDAQ
Fork of DS1820 by
Revision 7:aceafdd78b28, committed 2014-10-30
- Comitter:
- uci1
- Date:
- Thu Oct 30 05:55:15 2014 +0000
- Parent:
- 6:c78fb487c397
- Child:
- 8:7f64569563ea
- Commit message:
- allow use of parasite power to be switched on and off
Changed in this revision
DS1820.cpp | Show annotated file Show diff for this revision Revisions of this file |
DS1820.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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();
--- a/DS1820.h Mon Sep 22 00:38:39 2014 +0000 +++ b/DS1820.h Thu Oct 30 05:55:15 2014 +0000 @@ -89,7 +89,8 @@ * @param data_pin DigitalInOut pin for the data bus * @param power_pin DigitalOut pin to control the power MOSFET */ - DS1820(PinName data_pin, PinName power_pin); // Constructor with parasite power pin + DS1820(PinName data_pin, PinName power_pin, + const bool useParasitePwr=true); // Constructor with parasite power pin /** Create a probe object connected to the specified pin * this is used when all probes are externally powered @@ -247,21 +248,6 @@ * returns false if the device (or ANY device) is parasite powered. */ bool read_power_supply(devices device=this_device); - - /** Allow the parasite pin to be set at any time. If it is set - * to "NC", then parasite mode is turned off. It is ok if this - * pin is the same as the datapin. - * - * @param parasitePin The pin to use for parasite power, or NC for - * external power - * @returns true if the parasite power is set to a connected pin - * false if parasite power is not connected (external power) - */ - bool set_parasite_pin(DigitalInOut parasitePin) { - _parasitepin = parasitePin; - _parasite_power = (NC!=parasitePin); - return _parasite_power; - } /** Check if parasite power is being used. * @@ -270,8 +256,26 @@ */ bool is_on_parasite_power() const { return _parasite_power; } + /** Allow use of parasite power to be switched on or off + * + * @param pwr Specify whether to use the parasite pin for power (true) + * or not (false). + * @return true if using parasite power + * false if not (i.e. parasite mode requested, but no parasite pin) + */ + bool set_use_parasite_power(const bool pwr) { + if (pwr && (_parasite_power_pn!=NC)) { + _parasite_power = true; + } else { + _parasite_power = false; + } + return _parasite_power; + } + private: bool _parasite_power; + PinName _parasite_power_pn; + char CRC_byte (char CRC, char byte ); bool onewire_reset(); void match_ROM();