ds18B20 CRC Errors?

Hello, newbie here. Used to work with Picaxe and then decided it was time to get into using a real processor. I had 8 ds18B20’s connected to a 40 pin picaxe and didn’t really have any problems with the sensors; except for the very occasional bad read.

So I am using the Photon with one ds18B20 temp sensor. I am using the example program that is in the library. Everything works with the exception of random CRC failures. There’s no pattern to it. The failure can happen once in five minutes, or three times a minute.

I have tried parasite and local power modes. I have changed values of pullup resistor (currently have the 4.7K in). I’ve checked all wiring (although it is bread boarded which I know people say can cause problems with these sensors). I’ve played with timing for the read/writes/resets.

I’m not really seeing anyone else having this problem so I’m a little stumped.
Any ideas that anyone has would be greatly appreciated! Thanks all.

I do get them occasionally too, but for that reason the sample in this library does check the CRC and performs some additional read attempts to get a good reading.
That way I do get almost no wrong readings anymore. You can play with the retry count and also perform some sensor reset (implicitly performed with DS18B20::readPowerSupply()) if the error doesn’t go away.

Thanks ScruffR.

Interestingly, I loaded the code found in the “Docs” section for “temperature logger” and have had it running now for about 20 minutes and not a single error. I did get a Serial transmission of “No More Addresses” ,“blank line” and then another “No More Addresses”. I haven’t looked at the code that closely yet but maybe that is an error but just not giving the information?

Going to let it run and see what happens…

Thanks again!

Have you had any success or are you still having problems?

Since I had some troubles with deep sleep on that sensor after a minimal adaptation to the library things worked more reliable again.


float DS18B20::getTemperature(){
    ds->reset();
    //ds->select(addr); // <-- replace this with the following line
    ds->write(0xCC);        // Skip ROM for single drop bus
    ds->write(0x44);        // start conversion, with parasite power on at the end
    delay(750);             // 750ms for 12bit read
    // we might do a ds.depower() here, but the reset will take care of it.
    ds->reset();
    //ds->select(addr); // <-- replace this with the following line
    ds->write(0xCC);        // Skip ROM for single drop bus
    ds->write(0xBE);        // Read Scratchpad
    ...
}

And with that the reading gets a bit simpler too

float getTemp()
{
  int   i = 0;
  float _temp;
  
  do {
    _temp = ds18b20.getTemperature();
  } while(!ds18b20.crcCheck() && DS18B20_MAXRETRY > i++);
  if (i < DS18B20_MAXRETRY) return _temp;
  
  return -99.9;
}
1 Like

Thanks for your input. I have a 5 month old daughter so needless to say my time is very limited to do things I want for a while . I will take a look at my next chance and report back. Thanks again!

1 Like