Simple cpp wrapper of a ds18b20, onewire 'c' library. Supports multiple sensors.

Dependencies:   mbed

Dependents:   LPC11U68_DS18B20Sensor

Fork of DS18B20Sensor by Steve Spence

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DS18X20.h Source File

DS18X20.h

00001 /* DS18X20 specific values (see datasheet www.maxim-ic.com/datasheet/index.mvp/id/2812) */
00002 #ifndef _DS18X20_
00003 #define _DS18X20_
00004 #define DS18S20_ID 0x10
00005 #define DS18B20_ID 0x28
00006 
00007 #define DS18X20_POWER_PARASITE 0x00
00008 #define DS18X20_POWER_EXTERN   0x01
00009 #define DS18X20_CONVERT_T    0x44
00010 #define DS18X20_READ        0xBE
00011 #define DS18X20_WRITE        0x4E
00012 #define DS18X20_EE_WRITE    0x48
00013 #define DS18X20_EE_RECALL    0xB8
00014 #define DS18X20_READ_POWER_SUPPLY 0xB4
00015 
00016 #define DS18X20_OK          0x00
00017 #define DS18X20_ERROR       0x01
00018 #define DS18X20_START_FAIL  0x02
00019 #define DS18X20_ERROR_CRC   0x03
00020 
00021 #define DS18B20_CONF_REG    4
00022 #define DS18B20_9_BIT       0
00023 #define DS18B20_10_BIT      (1<<5)
00024 #define DS18B20_11_BIT      (1<<6)
00025 #define DS18B20_12_BIT      ((1<<6)|(1<<5))
00026 
00027 // indefined bits in LSB if 18B20 != 12bit
00028 #define DS18B20_9_BIT_UNDF       ((1<<0)|(1<<1)|(1<<2))
00029 #define DS18B20_10_BIT_UNDF      ((1<<0)|(1<<1))
00030 #define DS18B20_11_BIT_UNDF      ((1<<0))
00031 #define DS18B20_12_BIT_UNDF      0
00032 
00033 // conversion times in ms
00034 #define DS18B20_TCONV_12BIT      750
00035 #define DS18B20_TCONV_11BIT      DS18B20_TCONV_12_BIT/2
00036 #define DS18B20_TCONV_10BIT      DS18B20_TCONV_12_BIT/4
00037 #define DS18B20_TCONV_9BIT       DS18B20_TCONV_12_BIT/8
00038 #define DS18S20_TCONV            DS18B20_TCONV_12_BIT
00039 
00040 // constant to convert the fraction bits to cel*(10^-4)
00041 #define DS18X20_FRACCONV         625
00042 
00043 #define DS18X20_SP_SIZE  9
00044 
00045 // DS18X20 EEPROM-Support
00046 #define DS18X20_WRITE_SCRATCHPAD  0x4E
00047 #define DS18X20_COPY_SCRATCHPAD   0x48
00048 #define DS18X20_RECALL_E2         0xB8
00049 #define DS18X20_COPYSP_DELAY      10 /* ms */
00050 #define DS18X20_TH_REG      2
00051 #define DS18X20_TL_REG      3
00052                           
00053 uint8_t DS18X20_get_power_status(uint8_t id[]); 
00054 uint8_t DS18X20_start_meas( uint8_t with_external, uint8_t id[]);
00055 uint8_t DS18X20_read_meas(uint8_t id[], uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
00056 uint8_t DS18X20_read_meas_single(uint8_t familycode, uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
00057 uint8_t DS18X20_meas_to_cel( uint8_t fc, uint8_t *sp, uint8_t* subzero, uint8_t* cel, uint8_t* cel_frac_bits);
00058 uint16_t DS18X20_temp_to_decicel(uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits);
00059 int8_t DS18X20_temp_cmp(uint8_t subzero1, uint16_t cel1, uint8_t subzero2, uint16_t cel2);
00060 #endif