COSA
An Object-Oriented Platform for Arduino Programming
DS18B20 Class Reference

#include <DS18B20.hh>

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

Classes

struct  scratchpad_t
 
class  Search
 

Public Types

enum  { FIRST = -1, ERROR = -1, LAST = ROMBITS }
 

Public Member Functions

 DS18B20 (OWI *pin, const char *name=NULL)
 
 DS18B20 (OWI *pin, const uint8_t *rom, const char *name=NULL)
 
bool connect (uint8_t index)
 
void resolution (uint8_t bits)
 
void set_trigger (int8_t low, int8_t high)
 
int16_t temperature () const
 
uint8_t resolution () const
 
void get_trigger (int8_t &low, int8_t &high) const
 
bool convert_request ()
 
bool write_scratchpad ()
 
bool read_scratchpad (bool flag=true)
 
bool copy_scratchpad ()
 
bool recall ()
 
bool read_power_supply ()
 
uint8_t * rom ()
 
bool update_rom ()
 
int8_t search_rom (int8_t last=FIRST)
 
bool read_rom ()
 
bool match_rom ()
 
bool skip_rom ()
 
int8_t alarm_search (int8_t last=FIRST)
 
bool connect (uint8_t family, uint8_t index)
 
virtual void on_alarm ()
 

Static Public Member Functions

static bool convert_request (OWI *owi, uint8_t resolution=12, bool parasite=false)
 
static void print (IOStream &outs, int16_t temp)
 

Public Attributes

str_P NAME
 

Protected Types

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

Protected Member Functions

void power_off ()
 
int8_t search (int8_t last=FIRST)
 

Protected Attributes

scratchpad_t m_scratchpad
 
uint8_t m_parasite
 
uint32_t m_start
 
uint8_t m_converting
 
uint8_t m_rom [ROM_MAX]
 
const uint8_t * ROM
 
Driverm_next
 
OWIm_pin
 

Static Protected Attributes

static const uint8_t CONFIG_MAX = 3
 
static const uint16_t MAX_CONVERSION_TIME = 750
 
static const uint16_t MIN_COPY_PULLUP = 10
 

Friends

IOStreamoperator<< (IOStream &outs, DS18B20 &thermometer)
 

Detailed Description

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

Circuit

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

May use parasite powering (connect DS18B20 VCC to GND) otherwise to VCC.

References

  1. Maxim Integrated product description (REV: 042208)

Definition at line 49 of file DS18B20.hh.

Member Enumeration Documentation

anonymous enum
protected

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

Enumerator
FAMILY_CODE 
CONVERT_T 
READ_SCRATCHPAD 
WRITE_SCRATCHPAD 
COPY_SCRATCHPAD 
RECALL_E 
READ_POWER_SUPPLY 

Definition at line 248 of file DS18B20.hh.

anonymous enum
inherited
Enumerator
FIRST 
ERROR 
LAST 

Definition at line 60 of file OWI.hh.

Constructor & Destructor Documentation

DS18B20::DS18B20 ( OWI pin,
const char *  name = NULL 
)
inline

Construct a DS18B20 device connected to the given 1-Wire bus. Use connect() to lookup, set power supply mode and configuration. Alternatively use read_power_supply() and read_scratchpad() directly if rom address is given.

Parameters
[in]pinone wire bus pin.
[in]nameof device.

Definition at line 80 of file DS18B20.hh.

DS18B20::DS18B20 ( OWI pin,
const uint8_t *  rom,
const char *  name = NULL 
)
inline

Construct a DS18B20 device connected to the given 1-Wire bus and device identity (in EEPROM). Use connect() to lookup, set power supply mode and configuration. Alternatively use read_power_supply() and read_scratchpad() directly if rom address is given.

Parameters
[in]pinone wire bus pin.
[in]romdevice identity.
[in]nameof device. In program memory (default NULL).

Definition at line 97 of file DS18B20.hh.

Member Function Documentation

int8_t OWI::Driver::alarm_search ( int8_t  last = FIRST)
inherited

Search alarming device given the last position of discrepancy. Negative value for start from the beginning.

Parameters
[in]lastposition of discrepancy.
Returns
position of difference or negative error code.

Definition at line 264 of file OWI.cpp.

bool DS18B20::connect ( uint8_t  index)

Connect to DS18B20 device with given index. Reads configuration, scratchpad, and power supply setting. Returns true(1) if connected, otherwise false(0).

Parameters
[in]indexdevice order.
Returns
true(1) if successful otherwise false(0).

Definition at line 34 of file DS18B20.cpp.

bool OWI::Driver::connect ( uint8_t  family,
uint8_t  index 
)
inherited

Connect to one-wire device with given family code and index.

Parameters
[in]familydevice family code.
[in]indexdevice order.
Returns
true(1) if successful otherwise false(0).

Definition at line 272 of file OWI.cpp.

bool DS18B20::convert_request ( )

Initiate a single temperature conversion. With the default setting 12-bit resolution the max conversion time is 750 ms, MAX_CONVERSION_TIME.

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

Definition at line 50 of file DS18B20.cpp.

bool DS18B20::convert_request ( OWI owi,
uint8_t  resolution = 12,
bool  parasite = false 
)
static

Initiate connected devices to perform a simple temperature conversion (boardcast). With the default setting 12-bit resolution the max conversion time is 750 ms, MAX_CONVERSION_TIME. Give zero(0) as resolution to omit conversion wait. Parasite power by passing true for the mode flag. Returns true(1) if successful otherwise false(0).

Parameters
[in]owione-wire interface pin.
[in]resolutionof conversion.
[in]parasitepower mode flag.
Returns
true(1) if successful otherwise false(0).

Definition at line 60 of file DS18B20.cpp.

bool DS18B20::copy_scratchpad ( )

Copy device scratchpad triggers and configuration data to device EEPROM. An internal delay is issued to allow the data to be written.

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

Definition at line 101 of file DS18B20.cpp.

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

Get alarm trigger values; low and high threshold values. Use connect(), or read_scratchpad() to read values from device.

Parameters
[out]lowthreshold.
[out]highthreshold.

Definition at line 165 of file DS18B20.hh.

bool OWI::Driver::match_rom ( )
inherited

Match device rom. Address the slave device with the rom code. Device specific function command should follow. May be used to verify rom code.

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

Definition at line 244 of file OWI.cpp.

virtual void OWI::Driver::on_alarm ( )
inlinevirtualinherited

Callback on alarm dispatch. Default is empty function.

Definition at line 159 of file OWI.hh.

void DS18B20::power_off ( )
inlineprotected

Turn power off if the device is parasite powered. Call connect() or read_power_supply() to set the parasite mode for the device.

Definition at line 293 of file DS18B20.hh.

void DS18B20::print ( IOStream outs,
int16_t  temp 
)
static

Print temperature reading (fixed point value) to given output stream.

Parameters
[in]outsoutput stream.
[in]temptemperature fixed point number.

Definition at line 128 of file DS18B20.cpp.

bool DS18B20::read_power_supply ( )

Read power supply. Determine if the device requires parasite powering. The information is cached and used in read_scratchpad() and copy_scratchpad() for internal delay timing. The function connect() will call this function automatically.

Returns
true(1) if parasite power is required otherwise false(0).

Definition at line 119 of file DS18B20.cpp.

bool OWI::Driver::read_rom ( )
inherited

Read device rom. This can only be used when there is only one slave on the bus.

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

Definition at line 236 of file OWI.cpp.

bool DS18B20::read_scratchpad ( bool  flag = true)

Read the contents of the scratchpad to local memory. A internal delay will occur if a convert_request() is pending. The delay is at most max conversion time (750 ms). The flag parameter may be used when a device has been addressed with search (alarm).

Parameters
[in]flagto reset before reading (default true).
Returns
true(1) if successful otherwise false(0).

Definition at line 75 of file DS18B20.cpp.

bool DS18B20::recall ( )

Recall the alarm triggers and configuration from device EEPROM.

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

Definition at line 111 of file DS18B20.cpp.

void DS18B20::resolution ( uint8_t  bits)

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

Parameters
[in]bitsresolution.

Definition at line 43 of file DS18B20.cpp.

uint8_t DS18B20::resolution ( ) const
inline

Get conversion resolution. Use connect(), or read_scratchpad() to read values from device before calling this method.

Returns
number of bits.

Definition at line 152 of file DS18B20.hh.

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

Return pointer to device rom.

Returns
device rom buffer.

Definition at line 96 of file OWI.hh.

int8_t OWI::Driver::search ( int8_t  last = FIRST)
protectedinherited

Search device rom given the last position of discrepancy. Negative value for start from the beginning.

Parameters
[in]lastposition of discrepancy.
Returns
position of difference or negative error code.

Definition at line 182 of file OWI.cpp.

int8_t OWI::Driver::search_rom ( int8_t  last = FIRST)
inherited

Search device rom given the last position of discrepancy. Negative value for start from the beginning.

Parameters
[in]lastposition of discrepancy.
Returns
position of difference or negative error code.

Definition at line 228 of file OWI.cpp.

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 126 of file DS18B20.hh.

bool OWI::Driver::skip_rom ( )
inherited

Skip device rom for boardcast or single device access. Device specific function command should follow.

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

Definition at line 256 of file OWI.cpp.

int16_t DS18B20::temperature ( ) const
inline

Get the latest temperature reading from the local memory scratchpad. Call convert_request() and read_scratchpad() before accessing the scratchpad. Returns at highest resolution a fixed point<12,4> point number. For 11-bit resolution, bit 0 is undefined, 10-bits bit 1 and 0, and so on (LSB).

Returns
temperature

Definition at line 141 of file DS18B20.hh.

bool OWI::Driver::update_rom ( )
inherited

Update the rom identity (in EEPROM). Return true(1) if successful otherwise false(0). Typically used to save configuration after connect(). return bool.

Definition at line 174 of file OWI.cpp.

bool DS18B20::write_scratchpad ( )

Write the contents of the scratchpad triggers and configuration (3 bytes) to device.

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

Definition at line 93 of file DS18B20.cpp.

Friends And Related Function Documentation

IOStream& operator<< ( IOStream outs,
DS18B20 thermometer 
)
friend

Print the name of the thermometer and latest temperature reading with two decimals to given output stream. The temperature is in Celcius.

Parameters
[in]outsstream to print device information to.
[in]thermometerdevice.
Returns
iostream.

Definition at line 141 of file DS18B20.cpp.

Member Data Documentation

const uint8_t DS18B20::CONFIG_MAX = 3
staticprotected

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

Definition at line 272 of file DS18B20.hh.

uint8_t DS18B20::m_converting
protected

Convert request pending.

Definition at line 281 of file DS18B20.hh.

Driver* OWI::Driver::m_next
protectedinherited

Definition at line 164 of file OWI.hh.

uint8_t DS18B20::m_parasite
protected

Parasite power mode.

Definition at line 275 of file DS18B20.hh.

OWI* OWI::Driver::m_pin
protectedinherited

Definition at line 165 of file OWI.hh.

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

Definition at line 162 of file OWI.hh.

scratchpad_t DS18B20::m_scratchpad
protected

Definition at line 269 of file DS18B20.hh.

uint32_t DS18B20::m_start
protected

Watchdog millis on convert_request().

Definition at line 278 of file DS18B20.hh.

const uint16_t DS18B20::MAX_CONVERSION_TIME = 750
staticprotected

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

Definition at line 284 of file DS18B20.hh.

const uint16_t DS18B20::MIN_COPY_PULLUP = 10
staticprotected

Min copy configuration time in milli-seconds (parasite mode).

Definition at line 287 of file DS18B20.hh.

str_P OWI::Driver::NAME
inherited

Name of device driver instance.

Definition at line 67 of file OWI.hh.

const uint8_t* OWI::Driver::ROM
protectedinherited

Definition at line 163 of file OWI.hh.


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