Version of Richard Lane's library, with #define CABLE_EXT_DELAYS to extend reset() settling delays for extension cable
Fork of DS18B20_1wire by
DS18B20 Class Reference
A DS18B20 Dallas 1-wire digital thermometer interface. More...
#include <DS18B20.h>
Data Structures | |
union | ROM_Code_t |
Holds 8-byte internal ROM. More... | |
struct | ScratchPad_t |
Device onboard register layout (for reference only, not currently used) More... | |
Public Types | |
enum | |
Value to return when Reset() fails. More... | |
enum | RESOLUTION { RES_9_BIT = 0x1f, RES_10_BIT = 0x3f, RES_11_BIT = 0x5f, RES_12_BIT = 0x7f } |
Temperature conversion dit width resolutions. More... | |
Public Member Functions | |
DS18B20 (PinName pin, unsigned resolution) | |
Create a Dallas DS18B20 1-wire interface. | |
~DS18B20 () | |
Destructor. | |
float | GetTemperature () |
Performs conversion in DS18B20 and then reads and converts returned temperature to floating point. | |
unsigned | DoConversion () |
Performs conversion but does not read back temperature. | |
int | RawTemperature () |
The method that GetTemperature() calls to do all the conversion and reading but this method returns a 32-bit signed integer. | |
int | ReadROM (ROM_Code_t *ROM_Code) |
Reads and returns the 8-byte internal ROM. | |
unsigned | SetResolution (unsigned resolution) |
Sets the conversion resolution with RESOLUTION enum (9-12 bits signed) |
Detailed Description
A DS18B20 Dallas 1-wire digital thermometer interface.
25 March,2014 added larger DELAY values to allow extra 1-bit bus settling time accommodating 3ft extension cable with higher parasitic capacitance.
Currently supports 9, 10, 11 or 12-bit conversions. Fewer bits require less conversion time from 93.75ms to 750ms. Also supports reading back the 8-byte internal ROM. Orignal code copied from DS18B20 C program by Niall Cooling (thanks!) and wrapped in C++ class by this library.
modified delay values to allow extra 1-bit bus settling time accommodating 3ft extension cable (with higher parasitic capacitance) define CABLE_EXT_DELAYS // extend reset() settling delays for extension cable
#include "mbed.h" #include <stdint.h> #include "DS18B20.h" #define CABLE_EXT_DELAYS //longer reset() settling delays if extension cable Serial pc(USBTX, USBRX); // serial comms over usb back to console DS18B20 thermom(p16, DS18B20::RES_12_BIT); // Dallas 1-wire int main() { pc.printf("DS18B20 Configuration\n\r"); DS18B20::ROM_Code_t ROM_Code; thermom.ReadROM(&ROM_Code); pc.printf("Family code: 0x%X\n\r", ROM_Code.BYTES.familyCode); pc.printf("Serial Number: "); for (unsigned i = 6; i != 0; --i) { pc.printf("%02X%s", ROM_Code.BYTES.serialNo[i-1], (i != 1)?":":"\r\n"); } pc.printf("CRC: 0x%X\r\n", ROM_Code.BYTES.CRC); pc.printf("\n\rRunning temperature conversion...\n\r"); while (1) { pc.printf("Temperature is: %.4fC\n\r", thermom.GetTemperature()); wait(10); } }
Definition at line 58 of file DS18B20.h.
Member Enumeration Documentation
enum RESOLUTION |
Constructor & Destructor Documentation
DS18B20 | ( | PinName | pin, |
unsigned | resolution | ||
) |
Create a Dallas DS18B20 1-wire interface.
- Parameters:
-
pin Pin to use for 1-wire interface (bidirectional I/O) resolution Sets the conversion bit width (using RESOLUTION enum)
Definition at line 3 of file DS18B20.cpp.
~DS18B20 | ( | ) |
Destructor.
Definition at line 8 of file DS18B20.cpp.
Member Function Documentation
unsigned DoConversion | ( | ) |
Performs conversion but does not read back temperature.
Not needed if GetTemperature() is used as this calls DoConversion() itself.
Definition at line 84 of file DS18B20.cpp.
float GetTemperature | ( | ) |
Performs conversion in DS18B20 and then reads and converts returned temperature to floating point.
For many applications this is the only required method that needs to be used.
Definition at line 117 of file DS18B20.cpp.
int RawTemperature | ( | ) |
The method that GetTemperature() calls to do all the conversion and reading but this method returns a 32-bit signed integer.
The integer contains 4 fractional LSBs. Sometimes referred to as s28.4 format.
Definition at line 97 of file DS18B20.cpp.
int ReadROM | ( | DS18B20::ROM_Code_t * | ROM_Code ) |
Reads and returns the 8-byte internal ROM.
Definition at line 123 of file DS18B20.cpp.
unsigned SetResolution | ( | unsigned | resolution ) |
Sets the conversion resolution with RESOLUTION enum (9-12 bits signed)
Definition at line 70 of file DS18B20.cpp.
Generated on Tue Jul 12 2022 15:34:25 by 1.7.2