]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/sht11/SensirionSht11LogicP.nc
sht11: correct measurement timeout values
[tinyos-2.x.git] / tos / chips / sht11 / SensirionSht11LogicP.nc
index ce4aa6ca68f7f46bfb54696af6d250853abdb7b4..84a903cfaaa7375a5ce1e9db97490f8e00d7c2ff 100644 (file)
@@ -57,6 +57,7 @@ generic module SensirionSht11LogicP() {
   uses interface GeneralIO as CLOCK;
   uses interface GpioInterrupt as InterruptDATA;
 
+  uses interface BusyWait<TMicro, uint8_t>;
   uses interface Timer<TMilli>;
 
   uses interface Leds;
@@ -73,9 +74,14 @@ implementation {
 
   enum {
     TIMEOUT_RESET = 11,
-    TIMEOUT_14BIT = 250,
-    TIMEOUT_12BIT = 250, //70,
-    TIMEOUT_8BIT = 250, //15,
+
+    /* SHT1x_SHT7x_E data sheet v3.01 indicates readings take at most
+     * 320 ms for 14 bits, 80 ms for 12 bits and 20 ms for 8 bits.
+     * Add 20% as a safety margin.
+     */
+    TIMEOUT_14BIT = 393,
+    TIMEOUT_12BIT = 98,
+    TIMEOUT_8BIT = 25,
   } sht_timeout_t;
 
   bool on = TRUE;
@@ -240,11 +246,17 @@ implementation {
     call DATA.makeOutput();
     call DATA.set();
     call CLOCK.clr();
+    call BusyWait.wait(5);
     call CLOCK.set();
+    call BusyWait.wait(5);
     call DATA.clr();
+    call BusyWait.wait(5);
     call CLOCK.clr();
+    call BusyWait.wait(5);
     call CLOCK.set();
+    call BusyWait.wait(5);
     call DATA.set();
+    call BusyWait.wait(5);
     call CLOCK.clr();
   }
 
@@ -261,6 +273,7 @@ implementation {
        call DATA.clr();
       byte = byte << 1;
       call CLOCK.set();
+      call BusyWait.wait(5);
       call CLOCK.clr();
     }
   }
@@ -373,6 +386,7 @@ implementation {
     call DATA.makeOutput();
     call DATA.clr();
     call CLOCK.set();
+    call BusyWait.wait(5);
     call CLOCK.clr();
     call DATA.makeInput();
     call DATA.set();
@@ -382,6 +396,7 @@ implementation {
     call DATA.makeOutput();
     call DATA.set();
     call CLOCK.set();
+    call BusyWait.wait(5);
     call CLOCK.clr();
   }