|
|
@@ -28,24 +28,29 @@ void gettemp(void){
|
|
|
|
|
|
_delay_ms(1);
|
|
|
|
|
|
+ /* No presence pulse (bus short, or no sensor at all): skip straight to
|
|
|
+ * the error accounting below instead of returning here - an early
|
|
|
+ * return would skip re-arming System.timers.owire at the end of this
|
|
|
+ * function, so with no sensor ever connected, this whole function would
|
|
|
+ * run on every single main loop pass (never gated by the timer again)
|
|
|
+ * instead of the intended once-per-4s poll. */
|
|
|
+ if(_1WireInit() == 1){
|
|
|
+ _1WireWriteByte(0xcc);
|
|
|
+ _1WireWriteByte(0xbe);
|
|
|
|
|
|
- if(_1WireInit() != 1){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _1WireWriteByte(0xcc);
|
|
|
- _1WireWriteByte(0xbe);
|
|
|
-
|
|
|
- for(i=0;i<9;i++){
|
|
|
- tmp = _1WireReadByte();
|
|
|
- t.owbuffer[i] = tmp;
|
|
|
- crc = _crc_ibutton_update(crc, tmp);
|
|
|
- }
|
|
|
- if(!crc){
|
|
|
- if(t.owbuffer[0] != 0x50 || t.owbuffer[1] != 0x05 || t.owbuffer[5] != 0xff || t.owbuffer[7] != 0x10){
|
|
|
- temp = (float)t.t*0.0625;
|
|
|
- System.temperature = temp;
|
|
|
- temp_ok_out = 1;
|
|
|
+ for(i=0;i<9;i++){
|
|
|
+ tmp = _1WireReadByte();
|
|
|
+ t.owbuffer[i] = tmp;
|
|
|
+ crc = _crc_ibutton_update(crc, tmp);
|
|
|
+ }
|
|
|
+ if(!crc){
|
|
|
+ /* Reject the power-on-reset scratchpad default (85.0C) still in
|
|
|
+ * place if a conversion never actually completed. */
|
|
|
+ if(t.owbuffer[0] != 0x50 || t.owbuffer[1] != 0x05 || t.owbuffer[5] != 0xff || t.owbuffer[7] != 0x10){
|
|
|
+ temp = (float)t.t*0.0625;
|
|
|
+ System.temperature = temp;
|
|
|
+ temp_ok_out = 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -59,9 +64,10 @@ void gettemp(void){
|
|
|
error_cnt = 0;
|
|
|
System.temperature_ok = 1;
|
|
|
}
|
|
|
-
|
|
|
- _1WireInit();
|
|
|
- _1WireWriteByte(0xcc);
|
|
|
- _1WireWriteBytePR(0x44);
|
|
|
+
|
|
|
+ if(_1WireInit() == 1){
|
|
|
+ _1WireWriteByte(0xcc);
|
|
|
+ _1WireWriteBytePR(0x44);
|
|
|
+ }
|
|
|
atomic_set_uint(&System.timers.owire, ms(4000));
|
|
|
}
|