Arduino-OWI
One-Wire Interface (OWI) library for Arduino
DS18B20 Class Reference

#include <DS18B20.h>

Inheritance diagram for DS18B20:
Inheritance graph
Collaboration diagram for DS18B20:
Collaboration graph

Classes

struct  scratchpad_t
 

Public Member Functions

 DS18B20 (OWI &owi, uint8_t *rom=NULL)
 
void resolution (uint8_t bits)
 
void set_trigger (int8_t low, int8_t high)
 
float temperature () const
 
uint8_t resolution () const
 
void get_trigger (int8_t &low, int8_t &high) const
 
bool convert_request (bool broadcast=false)
 
uint16_t conversion_time ()
 
bool convert_ready ()
 
bool convert_await ()
 
bool read_scratchpad (bool match=true)
 
bool write_scratchpad (bool match=true)
 
bool copy_scratchpad (bool match=true)
 
bool recall (bool match=true)
 
void rom (const uint8_t *rom)
 
uint8_t * rom ()
 
void rom_P (const uint8_t *rom)
 

Static Public Attributes

static const uint8_t FAMILY_CODE = 0x28
 
static const uint16_t MAX_CONVERSION_TIME = 750
 

Protected Types

enum  {
  CONVERT_T = 0x44, READ_SCRATCHPAD = 0xBE, WRITE_SCRATCHPAD = 0x4E, COPY_SCRATCHPAD = 0x48,
  RECALL_E = 0xB8, READ_POWER_SUPPLY = 0xB4
}
 

Protected Attributes

scratchpad_t m_scratchpad
 
uint16_t m_start
 
bool m_converting
 
OWIm_owi
 
uint8_t m_rom [ROM_MAX]
 

Static Protected Attributes

static const uint8_t CONFIG_MAX = 3
 

Detailed Description

Driver for the DS18B20 Programmable Resolution 1-Write Digital Thermometer.

Circuit

(VCC)--[4K7]--+ +------------+
(GND)---------)-----1-|GND |\
(Dn)----------+-----2-|DQ | |
(VCC)---------------3-|VDD |/
+------------+

References

  1. Maxim Integrated product description (REV: 042208)

Definition at line 41 of file DS18B20.h.

Member Enumeration Documentation

anonymous enum
protected

DS18B20 Function Commands (Table 3, pp. 12).

Enumerator
CONVERT_T 

Initiate temperature conversion.

READ_SCRATCHPAD 

Read scratchpad including crc byte.

WRITE_SCRATCHPAD 

Write data to scratchpad.

COPY_SCRATCHPAD 

Copy configuration register to EEPROM.

RECALL_E 

Recall configuration data from EEPROM.

READ_POWER_SUPPLY 

Signal power supply mode.

Definition at line 236 of file DS18B20.h.

Constructor & Destructor Documentation

DS18B20::DS18B20 ( OWI owi,
uint8_t *  rom = NULL 
)
inline

Construct a DS18B20 device connected to the given 1-Wire bus. Initiate with default resolution (12-bits) and triggers (70, 75), as hardware reset for device.

Parameters
[in]owibus manager.
[in]romcode (default NULL).

Definition at line 56 of file DS18B20.h.

Member Function Documentation

uint16_t DS18B20::conversion_time ( )
inline

Return remaining conversion time in milliseconds.

Returns
milliseconds remaining.

Definition at line 143 of file DS18B20.h.

bool DS18B20::convert_await ( )
inline

Delay until the temperature conversion is completed by polling the sensors.

Returns
true(1) if successful otherwise false(0).

Definition at line 170 of file DS18B20.h.

bool DS18B20::convert_ready ( )
inline

Check if the temperature conversion is completed.

Returns
true(1) if ready otherwise false(0).

Definition at line 157 of file DS18B20.h.

bool DS18B20::convert_request ( bool  broadcast = false)
inline

Initiate temperature conversion. Call with broadcast parameter true(1) to issue skip_rom() and issue to command to all devices.

Parameters
[in]broadcastflag (default false).
Returns
true(1) if successful otherwise false(0).

Definition at line 125 of file DS18B20.h.

bool DS18B20::copy_scratchpad ( bool  match = true)
inline

Copy device scratchpad triggers and configuration data to device EEPROM. Call with match parameter false if used with search_rom().

Parameters
[in]matchrom code (default true).
Returns
true(1) if successful otherwise false(0).

Definition at line 212 of file DS18B20.h.

void DS18B20::get_trigger ( int8_t &  low,
int8_t &  high 
) const
inline

Get alarm trigger values; low and high threshold values.

Parameters
[out]lowthreshold.
[out]highthreshold.

Definition at line 113 of file DS18B20.h.

bool DS18B20::read_scratchpad ( bool  match = true)
inline

Read the contents of the scratchpad to local memory. Call convert_ready(), convert_await() or delay with amount from conversion_time() before reading. Call with match parameter false if used with search_rom().

Parameters
[in]matchrom code (default true).
Returns
true(1) if successful otherwise false(0).

Definition at line 185 of file DS18B20.h.

bool DS18B20::recall ( bool  match = true)
inline

Recall the alarm triggers and configuration from device EEPROM. Call with match parameter false if used with search_rom().

Parameters
[in]matchrom code (default true).
Returns
true(1) if successful otherwise false(0).

Definition at line 225 of file DS18B20.h.

void DS18B20::resolution ( uint8_t  bits)
inline

Set conversion resolution from 9..12 bits. Use write_scratchpad() and copy_scratchpad() to update device.

Parameters
[in]bitsresolution.

Definition at line 70 of file DS18B20.h.

uint8_t DS18B20::resolution ( ) const
inline

Get conversion resolution.

Returns
number of bits.

Definition at line 103 of file DS18B20.h.

void OWI::Device::rom ( const uint8_t *  rom)
inlineinherited

Set device rom code.

Parameters
[in]romcode.

Definition at line 303 of file OWI.h.

uint8_t* OWI::Device::rom ( )
inlineinherited

Get device rom code.

Returns
rom code.

Definition at line 333 of file OWI.h.

void OWI::Device::rom_P ( const uint8_t *  rom)
inlineinherited

Set device rom code.

Parameters
[in]romcode in program memory.

Definition at line 318 of file OWI.h.

void DS18B20::set_trigger ( int8_t  low,
int8_t  high 
)
inline

Set alarm trigger values; low and high threshold values. Use write_scratchpad() and copy_scratchpad() to update device.

Parameters
[in]lowthreshold.
[in]highthreshold.

Definition at line 82 of file DS18B20.h.

float DS18B20::temperature ( ) const
inline

Get the latest temperature reading from the scratchpad copy. Call convert_request(), convert_await() and read_scratchpad() before accessing the scratchpad.

Returns
temperature

Definition at line 94 of file DS18B20.h.

bool DS18B20::write_scratchpad ( bool  match = true)
inline

Write the contents of the scratchpad triggers and configuration (3 bytes) to device. Call with match parameter false if used with search_rom().

Parameters
[in]matchrom code (default true).
Returns
true(1) if successful otherwise false(0).

Definition at line 199 of file DS18B20.h.

Member Data Documentation

const uint8_t DS18B20::CONFIG_MAX = 3
staticprotected

Size of configuration; high/low trigger and configuration byte.

Definition at line 259 of file DS18B20.h.

const uint8_t DS18B20::FAMILY_CODE = 0x28
static

Device family code.

Definition at line 44 of file DS18B20.h.

bool DS18B20::m_converting
protected

Convert request pending.

Definition at line 265 of file DS18B20.h.

OWI& OWI::Device::m_owi
protectedinherited

One-Wire Bus Manager.

Definition at line 340 of file OWI.h.

uint8_t OWI::Device::m_rom[ROM_MAX]
protectedinherited

Device rom idenity code.

Definition at line 343 of file OWI.h.

scratchpad_t DS18B20::m_scratchpad
protected

Definition at line 256 of file DS18B20.h.

uint16_t DS18B20::m_start
protected

Watchdog millis on convert_request().

Definition at line 262 of file DS18B20.h.

const uint16_t DS18B20::MAX_CONVERSION_TIME = 750
static

Max conversion time for 12-bit conversion in milli-seconds.

Definition at line 47 of file DS18B20.h.


The documentation for this class was generated from the following file: