comparison 1wire.c @ 14:d8002c716678

- Actually wait after reading like the spec says. - Add debug item to show a device was found in the search. - Re-enable test for broken bus.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 08 Feb 2012 10:35:13 +1030
parents 6f8f7b87d2f1
children 0876867347de
comparison
equal deleted inserted replaced
13:6f8f7b87d2f1 14:d8002c716678
67 * 67 *
68 * (NOTE: Does not handle alarm presence from DS2404/DS1994) 68 * (NOTE: Does not handle alarm presence from DS2404/DS1994)
69 */ 69 */
70 uint8_t 70 uint8_t
71 OWTouchReset(void) { 71 OWTouchReset(void) {
72 uint8_t i;
73
72 OWDELAY_G; 74 OWDELAY_G;
73 75
74 /* Check the bus isn't being held low (ie it's broken) Do it after 76 /* Check the bus isn't being held low (ie it's broken) Do it after
75 * the delay so we guarantee we don't see a slave from a previous 77 * the delay so we guarantee we don't see a slave from a previous
76 * comms attempt 78 * comms attempt
77 */ 79 */
80 #if 1
78 OWSETREAD(); 81 OWSETREAD();
79 if(OWREADBUS() == 0) 82 if(OWREADBUS() == 0)
80 return 2; 83 return 2;
84 #endif
81 85
82 OWSETBUSLOW(); 86 OWSETBUSLOW();
83 OWDELAY_H; 87 OWDELAY_H;
84 OWSETBUSHIGH(); 88 OWSETBUSHIGH();
85 OWDELAY_I; 89 OWDELAY_I;
86 90
87 OWSETREAD(); 91 OWSETREAD();
88 return(OWREADBUS()); 92 i = OWREADBUS();
93
94 OWDELAY_J;
95 return(i);
89 } 96 }
90 97
91 /*----------------------------------------------------------------------------- 98 /*-----------------------------------------------------------------------------
92 * Send a 1-wire write bit. 99 * Send a 1-wire write bit.
93 */ 100 */
111 /*----------------------------------------------------------------------------- 118 /*-----------------------------------------------------------------------------
112 * Read a bit from the 1-wire bus and return it. 119 * Read a bit from the 1-wire bus and return it.
113 */ 120 */
114 uint8_t 121 uint8_t
115 OWReadBit(void) { 122 OWReadBit(void) {
123 uint8_t i;
124
116 OWDELAY_I; 125 OWDELAY_I;
117 126
118 OWSETBUSLOW(); 127 OWSETBUSLOW();
119 OWDELAY_A; 128 OWDELAY_A;
120 OWSETBUSHIGH(); 129 OWSETBUSHIGH();
121 OWDELAY_E; 130 OWDELAY_E;
122 OWSETREAD(); 131 OWSETREAD();
123 return(OWREADBUS()); 132 i = OWREADBUS();
133 OWDELAY_F;
134 return(i);
124 } 135 }
125 136
126 /*----------------------------------------------------------------------------- 137 /*-----------------------------------------------------------------------------
127 * Write a byte to the 1-wire bus 138 * Write a byte to the 1-wire bus
128 */ 139 */
252 /* reset the 1-wire 263 /* reset the 1-wire
253 * if there are no parts on 1-wire, return 0 */ 264 * if there are no parts on 1-wire, return 0 */
254 OWPUTSP(PSTR("Resetting\r\n")); 265 OWPUTSP(PSTR("Resetting\r\n"));
255 switch (OWTouchReset()) { 266 switch (OWTouchReset()) {
256 case 0: 267 case 0:
268 OWPUTSP(PSTR("Found device(s)\r\n"));
257 break; 269 break;
258 270
259 case 1: 271 case 1:
260 /* reset the search */ 272 /* reset the search */
261 OW_LastDiscrepancy = 0; 273 OW_LastDiscrepancy = 0;