summaryrefslogtreecommitdiff
path: root/lib/ds1820.h
blob: 64a0089f0f1888e4b7c29546616a5800c3565b6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 *  spreadspace avr utils - usb-1wire example
 *
 *
 *  Copyright (C) 2013-2014 Bernhard Tittelbach <xro@realraum.at>
 *  based on code from:
 *   http://www.pjrc.com/teensy/td_libs_OneWire.html
 *
 *  This file is part of spreadspace avr utils.
 *
 *  spreadspace avr utils is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  spreadspace avr utils is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __DS1820__
#define __DS1820__

#include	<stdint.h>

#define DS1820_FAMILY_ID                0x10
#define DS1820_START_CONVERSION         0x44
#define DS1820_READ_SCRATCHPAD          0xbe
#define DS1820_WRITE_SCRATCHPAD          0x4e
#define DS1820_ERROR                    -1000   // Return code. Outside temperature range.
#define DS1820_RESOLUTION_9BITS  0x00
#define DS1820_RESOLUTION_10BITS  0x20
#define DS1820_RESOLUTION_11BITS  0x40
#define DS1820_RESOLUTION_12BITS  0x60
#define DS1820_TCONV_MS_9BITS  96
#define DS1820_TCONV_MS_10BITS  195
#define DS1820_TCONV_MS_11BITS  390
#define DS1820_TCONV_MS_12BITS  800

#define DS2890_FAMILY_ID                0x2c
#define DS2890_WRITE_CONTROL_REGISTER   0X55
#define DS2890_RELEASE_CODE             0x96
#define DS2890_WRITE_POSITION           0x0f

#ifndef MAX_OWI_DEVICES
#define MAX_OWI_DEVICES 8
#endif

uint8_t ds1820_discover(void);
void ds1820_set_resolution(uint8_t d, uint8_t bits);
void ds1820_start_measuring(uint8_t d);
uint16_t ds1820_get_conversion_time_ms(uint8_t bits);
void ds1820_wait_conversion_time(uint8_t bits);
int16_t ds1820_read_temperature(uint8_t d);
float ds1820_raw_temp_to_celsius(int16_t t);

#endif