Problem with DS18B20 OneWire and long cables

Problem is fixed - a least, I get values for a few hours now...

Here's the patch to OneWire.cpp:

--- OneWire_orig.cpp    2008-05-20 02:10:54.000000000 +0200
+++ OneWire.cpp 2009-04-14 19:30:58.000000000 +0200
@@ -115,8 +115,8 @@
 // more certain timing.
 //
 void OneWire::write_bit(uint8_t v) {
-    static uint8_t lowTime[] = { 55, 5 };
-    static uint8_t highTime[] = { 5, 55};
+    static uint8_t lowTime[] = { 60, 8 };
+    static uint8_t highTime[] = { 8, 60};
     
     v = (v&1);
     *modeReg |= bitmask;  // make pin an output, do first since we
@@ -137,7 +137,7 @@
     
     *modeReg |= bitmask;    // make pin an output, do first since we expect to be at 1
     *outputReg &= ~bitmask; // zero
-    delayMicroseconds(1);
+    delayMicroseconds(3);
     *modeReg &= ~bitmask;     // let pin float, pull up will raise
     delayMicroseconds(5);          // A "read slot" is when 1mcs > t > 2mcs
     r = ( *inputReg & bitmask) ? 1 : 0; // check the bit

As you can see, I had to adjust the timing a little bit. As far as I understand the specifications, I think the original timings in OnwWire.cpp are at the minimum allowed. I now put the values a little bit more to "safe" mode :wink:

And I also had to replace the 4k7 resistor with a 2k2.

I'm not sure how to contact Tom - maybe he is reading this post :wink:

1 Like