comparison old/ds18x20.h @ 511:cf52d5817709

merge
author Matt Johnston <matt@ucc.asn.au>
date Thu, 26 Jun 2014 23:03:32 +0800
parents 95043860e437
children
comparison
equal deleted inserted replaced
505:ad846b9bdd10 511:cf52d5817709
1 #ifndef DS18X20_H_
2 #define DS18X20_H_
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <stdlib.h>
9 #include <stdint.h>
10
11 // DS18x20 EERPROM support disabled(0) or enabled(1) :
12 #define DS18X20_EEPROMSUPPORT 1
13 // decicelsius functions disabled(0) or enabled(1):
14 #define DS18X20_DECICELSIUS 1
15 // max. resolution functions disabled(0) or enabled(1):
16 #define DS18X20_MAX_RESOLUTION 1
17 // extended output via UART disabled(0) or enabled(1) :
18 #define DS18X20_VERBOSE 1
19
20
21 /* return values */
22 #define DS18X20_OK 0x00
23 #define DS18X20_ERROR 0x01
24 #define DS18X20_START_FAIL 0x02
25 #define DS18X20_ERROR_CRC 0x03
26
27 #define DS18X20_INVALID_DECICELSIUS 2000
28
29 #define DS18X20_POWER_PARASITE 0x00
30 #define DS18X20_POWER_EXTERN 0x01
31
32 #define DS18X20_CONVERSION_DONE 0x00
33 #define DS18X20_CONVERTING 0x01
34
35 /* DS18X20 specific values (see datasheet) */
36 #define DS18S20_FAMILY_CODE 0x10
37 #define DS18B20_FAMILY_CODE 0x28
38 #define DS1822_FAMILY_CODE 0x22
39
40 #define DS18X20_CONVERT_T 0x44
41 #define DS18X20_READ 0xBE
42 #define DS18X20_WRITE 0x4E
43 #define DS18X20_EE_WRITE 0x48
44 #define DS18X20_EE_RECALL 0xB8
45 #define DS18X20_READ_POWER_SUPPLY 0xB4
46
47 #define DS18B20_CONF_REG 4
48 #define DS18B20_9_BIT 0
49 #define DS18B20_10_BIT (1<<5)
50 #define DS18B20_11_BIT (1<<6)
51 #define DS18B20_12_BIT ((1<<6)|(1<<5))
52 #define DS18B20_RES_MASK ((1<<6)|(1<<5))
53
54 // undefined bits in LSB if 18B20 != 12bit
55 #define DS18B20_9_BIT_UNDF ((1<<0)|(1<<1)|(1<<2))
56 #define DS18B20_10_BIT_UNDF ((1<<0)|(1<<1))
57 #define DS18B20_11_BIT_UNDF ((1<<0))
58 #define DS18B20_12_BIT_UNDF 0
59
60 // conversion times in milliseconds
61 #define DS18B20_TCONV_12BIT 750
62 #define DS18B20_TCONV_11BIT DS18B20_TCONV_12_BIT/2
63 #define DS18B20_TCONV_10BIT DS18B20_TCONV_12_BIT/4
64 #define DS18B20_TCONV_9BIT DS18B20_TCONV_12_BIT/8
65 #define DS18S20_TCONV DS18B20_TCONV_12_BIT
66
67 // constant to convert the fraction bits to cel*(10^-4)
68 #define DS18X20_FRACCONV 625
69
70 // scratchpad size in bytes
71 #define DS18X20_SP_SIZE 9
72
73 // DS18X20 EEPROM-Support
74 #define DS18X20_WRITE_SCRATCHPAD 0x4E
75 #define DS18X20_COPY_SCRATCHPAD 0x48
76 #define DS18X20_RECALL_E2 0xB8
77 #define DS18X20_COPYSP_DELAY 10 /* ms */
78 #define DS18X20_TH_REG 2
79 #define DS18X20_TL_REG 3
80
81 #define DS18X20_DECIMAL_CHAR '.'
82
83
84 extern uint8_t DS18X20_find_sensor(uint8_t *diff,
85 uint8_t id[]);
86 extern uint8_t DS18X20_get_power_status(uint8_t id[]);
87 extern uint8_t DS18X20_start_meas( uint8_t with_external,
88 uint8_t id[]);
89 // returns 1 if conversion is in progress, 0 if finished
90 // not available when parasite powered
91 extern uint8_t DS18X20_conversion_in_progress(void);
92
93
94 #if DS18X20_DECICELSIUS
95 extern uint8_t DS18X20_read_decicelsius( uint8_t id[],
96 int16_t *decicelsius );
97 extern uint8_t DS18X20_read_decicelsius_single( uint8_t familycode,
98 int16_t *decicelsius );
99 extern uint8_t DS18X20_format_from_decicelsius( int16_t decicelsius,
100 char s[], uint8_t n);
101 #endif /* DS18X20_DECICELSIUS */
102
103
104 #if DS18X20_MAX_RESOLUTION
105 // temperature unit for max. resolution is �C * 10e-4
106 // examples: -250625 -> -25.0625�C, 1250000 -> 125.0000 �C
107 extern uint8_t DS18X20_read_maxres( uint8_t id[],
108 int32_t *temperaturevalue );
109 extern uint8_t DS18X20_read_maxres_single( uint8_t familycode,
110 int32_t *temperaturevalue );
111 extern uint8_t DS18X20_format_from_maxres( int32_t temperaturevalue,
112 char s[], uint8_t n);
113 #endif /* DS18X20_MAX_RESOLUTION */
114
115
116 #if DS18X20_EEPROMSUPPORT
117 // write th, tl and config-register to scratchpad (config ignored on DS18S20)
118 uint8_t DS18X20_write_scratchpad( uint8_t id[],
119 uint8_t th, uint8_t tl, uint8_t conf);
120 // read scratchpad into array SP
121 uint8_t DS18X20_read_scratchpad( uint8_t id[], uint8_t sp[], uint8_t n);
122 // copy values int scratchpad into DS18x20 eeprom
123 uint8_t DS18X20_scratchpad_to_eeprom( uint8_t with_power_extern,
124 uint8_t id[] );
125 // copy values from DS18x20 eeprom into scratchpad
126 uint8_t DS18X20_eeprom_to_scratchpad( uint8_t id[] );
127 #endif /* DS18X20_EEPROMSUPPORT */
128
129
130 #if DS18X20_VERBOSE
131 extern void DS18X20_show_id_uart( uint8_t *id, size_t n );
132 extern uint8_t DS18X20_read_meas_all_verbose( void );
133 #endif /* DS18X20_VERBOSE */
134
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif