annotate ds18x20.h @ 8:03da5ff767e9

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