DS1820

Driver to control DS1820 1-Wire temperature sensor.

Public Functions

Type

Name

DS1820 (PinName pin) Constructs a generic DS1820 sensor.

DS1820 (char model, PinName pin) Constructs a specific model.

bool

begin (void) Detects and initializes the actual DS1820 model.

bool

isPresent () Informs about presence of a DS1820 sensor.

void

setResolution (uint8_t res) Sets temperature-to-digital conversion resolution.

void

startConversion (void) Starts temperature conversion.

float

read (void) Reads temperature from the chip's Scratchpad.

uint8_t

read (float & temp) Reads temperature from chip's scratchpad.

Public Functions Documentation

function DS1820

DS1820::DS1820 (
    PinName pin
)

Constructs a generic DS1820 sensor.

Note:

begin() must be called to detect and initialize the actual model

Parameters:

  • pin Name of data pin

Return value:

function DS1820

DS1820::DS1820 (
    char model,
    PinName pin
)

Constructs a specific model.

Note:

No need to call begin() to detect and initialize the model

Parameters:

  • model One character model name: 'S', 's', 'B' or 'b' pin: Name of data pin

Return value:

function begin

bool DS1820::begin (
    void 
)

Detects and initializes the actual DS1820 model.

Note:

Parameters:

function isPresent

bool DS1820::isPresent ()

Informs about presence of a DS1820 sensor.

Note:

begin() shall be called before using this function if a generic DS1820 instance was created by the user. No need to call begin() for a specific DS1820 instance.

Parameters:

function setResolution

void DS1820::setResolution (
    uint8_t res
)

Sets temperature-to-digital conversion resolution.

Note:

The configuration register allows the user to set the resolution of the temperature-to-digital conversion to 9, 10, 11, or 12 bits. Defaults to 12-bit resolution for DS18B20. DS18S20 allows only 9-bit resolution.

Parameters:

  • res Resolution of the temperature-to-digital conversion in bits.

Return value:

void DS1820::startConversion (
    void 
)

Starts temperature conversion.

Note:

The time to complete the converion depends on the selected resolution: 9-bit resolution -> max conversion time = 93.75ms 10-bit resolution -> max conversion time = 187.5ms 11-bit resolution -> max conversion time = 375ms 12-bit resolution -> max conversion time = 750ms

Parameters:

function read

float DS1820::read (
    void 
)

Reads temperature from the chip's Scratchpad.

Note:

Parameters:

function read

uint8_t DS1820::read (
    float & temp
)

Reads temperature from chip's scratchpad.

Note:

Verifies data integrity by calculating cyclic redundancy check (CRC). If the calculated CRC dosn't match the one stored in chip's scratchpad register the temperature variable is not updated and CRC error code is returned.

Parameters:

  • temp The temperature variable to be updated by this routine. (It's passed as reference to floating point.)

Return value:

  • error code: 0 - no errors ('temp' contains the temperature measured) 1 - sensor not present ('temp' is not updated) 2 - CRC error ('temp' is not updated)

The documentation for this class was generated from the following file: D:/w/hw-libs/\_libs\_/libraries/DS1820.h

Last updated