A cut-down version of https://os.mbed.com/users/Sissors/code/DS1820/ tweaked for use with the STM32F103. It is all generic Mbed operations though, so should be usable anywhere. Non-essential functions have been removed, as this is intended for use within a tutorial.

Dependencies:   LinkedList

Dependents:   STM32F103C8T6_DS18B20 stm32f103c8t6-ds18b20

Fork of DS1820 by Erik -

Embed: (wiki syntax)

« Back to documentation index

DS1820 Class Reference

DS1820 Class Reference

DS1820 Dallas 1-Wire Temperature Probe. More...

#include <DS1820.h>

Public Member Functions

 DS1820 (PinName data_pin)
 Create a probe object connected to the specified pins.
int convertTemperature (bool wait, devices device=all_devices)
 This routine will initiate the temperature conversion within one or all DS1820 probes.
float temperature (char scale='c')
 This function will return the probe temperature.
bool setResolution (unsigned int resolution)
 This function sets the temperature resolution for the DS18B20 in the configuration register.

Detailed Description

DS1820 Dallas 1-Wire Temperature Probe.

Example:

 #include "mbed.h"
 #include "DS1820.h"

 DS1820 probe(DATA_PIN);
  
 int main() {
     while(1) {
         probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
         printf("It is %3.1foC\r\n", probe.temperature());
         wait(1);
     }
 }

Definition at line 52 of file DS1820.h.


Constructor & Destructor Documentation

DS1820 ( PinName  data_pin )

Create a probe object connected to the specified pins.

Parameters:
data_pinDigitalInOut pin for the data bus

Definition at line 15 of file DS1820.cpp.


Member Function Documentation

int convertTemperature ( bool  wait,
devices  device = all_devices 
)

This routine will initiate the temperature conversion within one or all DS1820 probes.

Parameters:
waitif true or parisitic power is used, waits up to 750 ms for conversion otherwise returns immediatly.
deviceallows the function to apply to a specific device or to all devices on the 1-Wire bus.
Returns:
milliseconds untill conversion will complete.

Definition at line 269 of file DS1820.cpp.

bool setResolution ( unsigned int  resolution )

This function sets the temperature resolution for the DS18B20 in the configuration register.

Parameters:
anumber between 9 and 12 to specify resolution
Returns:
true if successful

Definition at line 301 of file DS1820.cpp.

float temperature ( char  scale = 'c' )

This function will return the probe temperature.

Approximately 10ms per probe to read its RAM, do CRC check and convert temperature on the LPC1768.

Parameters:
scale,maybe either 'c' or 'f'
Returns:
temperature for that scale, or DS1820::invalid_conversion (-1000) if CRC error detected.

Definition at line 326 of file DS1820.cpp.