comparison 1wire.c @ 68:cc998b0b2bae

Handle missing modules in OWGetTemp.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 14 Apr 2013 16:07:29 +0930
parents 969bb070b181
children
comparison
equal deleted inserted replaced
67:dcac5f08f87a 68:cc998b0b2bae
64 /*----------------------------------------------------------------------------- 64 /*-----------------------------------------------------------------------------
65 * Generate a 1-Wire reset, return 0 if presence pulse was found, 1 if it 65 * Generate a 1-Wire reset, return 0 if presence pulse was found, 1 if it
66 * wasn't, or 2 if the line appears to be being held low. 66 * wasn't, or 2 if the line appears to be being held low.
67 * 67 *
68 * (NOTE: Does not handle alarm presence from DS2404/DS1994) 68 * (NOTE: Does not handle alarm presence from DS2404/DS1994)
69 *
70 * XXX: should use #defines
69 */ 71 */
70 uint8_t 72 uint8_t
71 OWTouchReset(void) { 73 OWTouchReset(void) {
72 uint8_t i; 74 uint8_t i;
73 75
199 } 201 }
200 202
201 203
202 /*----------------------------------------------------------------------------- 204 /*-----------------------------------------------------------------------------
203 * Send a 1 wire command to a device, or all if no ROM ID provided 205 * Send a 1 wire command to a device, or all if no ROM ID provided
204 */ 206 * Returns same values as OWTouchReset
205 void 207 */
208 uint8_t
206 OWSendCmd(uint8_t *ROM, uint8_t cmd) { 209 OWSendCmd(uint8_t *ROM, uint8_t cmd) {
207 uint8_t i; 210 uint8_t i;
208 211
209 OWTouchReset(); 212 if ((i = OWTouchReset()) != 0)
213 return i;
210 214
211 if (ROM == NULL) 215 if (ROM == NULL)
212 OWWriteByte(OW_SKIP_ROM_CMD); 216 OWWriteByte(OW_SKIP_ROM_CMD);
213 else { 217 else {
214 OWWriteByte(OW_MATCH_ROM_CMD); 218 OWWriteByte(OW_MATCH_ROM_CMD);
215 for (i = 0; i < 8; i++) 219 for (i = 0; i < 8; i++)
216 OWWriteByte(ROM[i]); 220 OWWriteByte(ROM[i]);
217 } 221 }
218 OWWriteByte(cmd); 222 OWWriteByte(cmd);
223
224 return 0;
219 } 225 }
220 226
221 /*----------------------------------------------------------------------------- 227 /*-----------------------------------------------------------------------------
222 * Search algorithm from App note 187 (and 162) 228 * Search algorithm from App note 187 (and 162)
223 * 229 *
555 int16_t tfrac; 561 int16_t tfrac;
556 562
557 if (ROM[0] != OW_FAMILY_TEMP) 563 if (ROM[0] != OW_FAMILY_TEMP)
558 return OW_TEMP_WRONG_FAM; 564 return OW_TEMP_WRONG_FAM;
559 565
560 OWSendCmd(ROM, OW_CONVERTT_CMD); 566 switch (OWSendCmd(ROM, OW_CONVERTT_CMD)) {
561 567 case 0:
568 break;
569
570 case 1:
571 case 2:
572 return OW_TEMP_NO_ROM;
573 }
574
562 i = 0; 575 i = 0;
563 576
564 /* Wait for the conversion */ 577 /* Wait for the conversion */
565 while (OWReadBit() == 0) 578 while (OWReadBit() == 0)
566 i = 1; 579 i = 1;