annotate simple_ds18b20.c @ 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 // Matt Johnston 2012
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 // Based on ds18x20.c by Martin Thomas, in turn based on code by
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 // Peter // Dannegger and others.
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 //
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 #include <stdio.h>
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 #include <avr/pgmspace.h>
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 "ds18x20.h"
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 #include "onewire.h"
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 #include "crc8.h"
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 #include "simple_ds18b20.h"
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 uint8_t
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 simple_ds18b20_start_meas(uint8_t id[])
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 uint8_t ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 ow_reset();
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 if( ow_input_pin_state() ) { // only send if bus is "idle" = high
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 ow_command_with_parasite_enable(DS18X20_CONVERT_T, id);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 ret = DS18X20_OK;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 else {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 ret = DS18X20_START_FAIL;
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
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 return ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 static uint8_t
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 read_scratchpad( uint8_t id[], uint8_t sp[], uint8_t n )
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 uint8_t i;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 uint8_t ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 ow_command( DS18X20_READ, id );
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 for ( i = 0; i < n; i++ ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 sp[i] = ow_byte_rd();
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 if ( crc8( &sp[0], DS18X20_SP_SIZE ) ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 ret = DS18X20_ERROR_CRC;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 } else {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 ret = DS18X20_OK;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 }
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 return ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 int16_t
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 ds18b20_raw16_to_decicelsius(uint16_t measure)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 uint8_t negative;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 int16_t decicelsius;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 uint16_t fract;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 // check for negative
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 if ( measure & 0x8000 ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 negative = 1; // mark negative
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 measure ^= 0xffff; // convert to positive => (twos complement)++
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 measure++;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 else {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 negative = 0;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 }
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 decicelsius = (measure >> 4);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 decicelsius *= 10;
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 // decicelsius += ((measure & 0x000F) * 640 + 512) / 1024;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 // 625/1000 = 640/1024
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 fract = ( measure & 0x000F ) * 640;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 if ( !negative ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 fract += 512;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 fract /= 1024;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 decicelsius += fract;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 if ( negative ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 decicelsius = -decicelsius;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 }
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 if ( decicelsius == 850 || decicelsius < -550 || decicelsius > 1250 ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 return DS18X20_INVALID_DECICELSIUS;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 } else {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 return decicelsius;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 uint8_t
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 simple_ds18b20_read_decicelsius( uint8_t id[], int16_t *decicelsius )
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 uint16_t reading;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 uint8_t ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 ret = simple_ds18b20_read_raw(id, &reading);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 if (ret == DS18X20_OK)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 *decicelsius = ds18b20_raw16_to_decicelsius(reading);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 return ret;
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 uint8_t
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 simple_ds18b20_read_raw( uint8_t id[], uint16_t *reading )
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 uint8_t sp[DS18X20_SP_SIZE];
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 uint8_t ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 if (id)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 ow_reset();
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 ret = read_scratchpad( id, sp, DS18X20_SP_SIZE );
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 if ( ret == DS18X20_OK ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 *reading = sp[0] | (sp[1] << 8);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 return ret;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 static void
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 printhex_nibble(const unsigned char b, FILE *stream)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 unsigned char c = b & 0x0f;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 if ( c > 9 ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 c += 'A'-10;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 else {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 c += '0';
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 fputc(c, stream);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 void
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 printhex_byte(const unsigned char b, FILE *stream)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 printhex_nibble( b >> 4, stream);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 printhex_nibble( b, stream);
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
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 void
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 printhex(uint8_t *id, uint8_t n, FILE *stream)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 for (uint8_t i = 0; i < n; i++)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 if (i > 0)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 fputc(' ', stream);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 printhex_byte(id[i], stream);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 uint8_t
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 simple_ds18b20_read_all()
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 uint8_t id[OW_ROMCODE_SIZE];
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 for( uint8_t diff = OW_SEARCH_FIRST; diff != OW_LAST_DEVICE; )
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 diff = ow_rom_search( diff, &id[0] );
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 if( diff == OW_PRESENCE_ERR ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 printf_P( PSTR("No Sensor found\r") );
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 return OW_PRESENCE_ERR; // <--- early exit!
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 if( diff == OW_DATA_ERR ) {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 printf_P( PSTR("Bus Error\r") );
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 return OW_DATA_ERR; // <--- early exit!
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 int16_t decicelsius;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 uint8_t ret = simple_ds18b20_read_decicelsius(NULL, &decicelsius);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 if (ret != DS18X20_OK)
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 printf_P(PSTR("Failed reading\r"));
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 return OW_DATA_ERR;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 printf_P(PSTR("DS18B20 %d: "), diff);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 if (crc8(id, OW_ROMCODE_SIZE))
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 {
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 printf_P(PSTR("CRC fail"));
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 printhex(id, OW_ROMCODE_SIZE, stdout);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 printf_P(PSTR(" %d.%d ÂșC\n"), decicelsius/10, decicelsius % 10);
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 printf_P(PSTR("Done sensors\n"));
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 return DS18X20_OK;
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 }
8705acff2494 lots of stuff
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192