DS18B20 CRC checking?

Eclectica

Member
Hi all,

It is great to be able to just use the readtemp12 routine to read the 12 bit temperature from a DS18B20. ;)

Now, when I've pushed the cable length beyond the 10M mark and it is an electrically noisy environments, sometimes the results which come back are clearly wrong, but conceptually, sometimes the errors would be more subtle e.g. 1 or 2 bits.

As far as I know there is no indication of CRC failure with the PICaxe routines (which would show if a single bit had been corrupted) - I would be happy to be proved wrong on this though?!:p

Cheers.
 

hippy

Ex-Staff (retired)
I would presume READTEMP only reads the two bytes of temperature from the DS18B20 and not the full scratchpad and CRC.

If using a PICAXE with OWIN and OWOUT commands you could probably read the full scratchpad data and CRC and do your own error checking on the result.
 

Paix

Senior Member
Alternatively, if the problem is seen as data errors rather than wanting to be able to check the CRC, you could try adjusting the pull-up resistor to get an improvement.

Is your 4k7 pullup currently located at the board or sensor end of things? Alas, I know the questions but not necessarily the answers, and so have no personal practical knowledge of how resistor placement is likely to affect things.

Certainly with I2C, lowering the pull-up resistor value has been known to allow a slightly longer signal path to be used. Perhaps Manuka or WestAust55 or someone else will be able to advise on that aspect.

When the answer is truly elusive, change the question ! :)
 

Eclectica

Member
I would presume READTEMP only reads the two bytes of temperature from the DS18B20 and not the full scratchpad and CRC.

If using a PICAXE with OWIN and OWOUT commands you could probably read the full scratchpad data and CRC and do your own error checking on the result.
Yes, I was wondering if the CRC was read at the same time, but I guess it would say in the manual.
Indeed, OWOUT/OWIN would be the way to go - thank you.:cool:


Alternatively, if the problem is seen as data errors rather than wanting to be able to check the CRC, you could try adjusting the pull-up resistor to get an improvement.

Is your 4k7 pullup currently located at the board or sensor end of things? Alas, I know the questions but not necessarily the answers, and so have no personal practical knowledge of how resistor placement is likely to affect things.
Thank you for the resistor suggestion and location. Interestingly, regarding location of the pullup resistor, I have tried both ends. The most successfull in noisy environments somewhat oddly appears to be having the resistor at the sensor end. The setup using screened twin twisted pair cable with one pair 0V/5V and the other 0V/Dq with 0V's linked at both ends, and a 100uF low ESR capacitor accross the 0V/5V, and using 3k3 resistor across Dq/5V.

Cheers,
E.
 

hippy

Ex-Staff (retired)
A side-step around the problem may be to put an 08M2 at the sensor end, have that interface with the DS18B20 over a short distance and send its data back using serial. You can still use a single wire to activate the reading and get the data back.

The serial may be far less susceptible to noise as the 1-wire protocol is fairly high speed.
 

geoff07

Senior Member
A side-step around the problem may be to put an 08M2 at the sensor end, have that interface with the DS18B20 over a short distance and send its data back using serial.
This works really well. I have had temp sensors running now for several years doing this every few secs from my solar panels and hot water system over screened two-wire. You can diode-mux them onto one interrupt pin, giving them each different prime-number sending intervals, and read several on one pin, disregarding the occasional clash. An 08M is enough if you still have them. Another advantage of using interrupts is that the data just appears as if by magic and you don't need to go looking for it.
 

westaust55

Moderator
The data line pull up resistor should be at the PICAXE end.
Certainly look at reducing the value for longer cakes - even down to 2.2 kOhm but try intermediate values as well.

What type of cable are you using?
Twisted pair unscreened is best however I have used around 30 to 40 metres of screened stereo audio cable successfully.
Don't earth/ground spare cores as that can add to capacitance on the signal wire.

Have a look at my 1-Wire networks thread/tutorial for greater information.
 

Paix

Senior Member
Further to Westaust55's update, assuming two twisted pairs, the power on one and the signal and spare on the other, the spare is only connected to ground at the Picaxe end of things, to prevent ground loops whilst still providing a grounded screen.

Unless I'm mistaken that was Westaust55's or Manuka's advice a couple of years ago. :)
 

Eclectica

Member
Thanks for the replies guys :) - useful to find your thread westaust - great work.

Hippy - the PICaxe08M at the end of a serial line is a nice idea - something I am already doing in another project.:cool:

I like the idea of the bi-directional serial lines Geoff; (kind of like one of the RS485 configurations) - will have to try this at some point.

Paix - the ground loop problem crossed my mind - but then on the other hand one could argue that it provides an extra low impedence path for the 0v and allows the DS18B20 greater V/msec. I definately agree with screens only being connected at one end though!

Thanks again.;)
 
Top