WAY OT: pushing data bits

Jan 27, 2010 33 Replies

I have a meager understanding of this subject so bear with me. I've been trying to get a Basic stamp to talk to a 1wire maxim DS1822 temperature sensor with no success. With a huge number of trials I always get the same data back from the sensor. (several different sensors, wirings, temperatures at sensor) See below for output of data bits and program listing.



I keep checking one more theory per day. Its got me pissed, I'm going to crack this nut if it kills me. Today's theory, "Maybe the command to tell the DS1822 sensor to resample temp. isn't working " It would be this command: 'Send Convert Temperature command OWOUT OWpin, OWFERst, [SkipROM, ConverT]



If the sensor never resamples, it would explain why I always get the same data IF they come factory preset here.



OK, for the bit head types out there. How does one check if a sensor is receiving and acting on a bit level command? I must be getting data from the unit as its a non random string of 0 and 1.



Karl


Data sheet:

formatting link


  1. Output of stamp program


1



1
1010000
101
1001011
1111111
11111111
111100
1000000
1110000
11111100


  1. program listing



' File...... ds1920.bsp ' Purpose... Measuring of Temperature with DS1920 iButton ' Author.... Claus Kuehnel ' Started... 2001-08-11 'CHOPPED UP FOR DIAGNOSIS 1 26 10



' '{$STAMP BS2px} 'specifies a BS2p ' -----[ Constants ]------------------------------------------ ' OWpin CON 15 '1-wire device pin



OWFERst CON %0001 'Front-End Reset OWBERst CON %0010 'Back-End reset OWBitMode CON %0100 SkipROM CON $CC 'Skip ROM Command ReadScratch CON $BE 'Read Scratch Pad ConverT CON $44 'Convert Temperature ' -----[ Variables ]------------------------------------------ ' temp VAR Word 'Temperature Value CRem1 VAR Byte CRem2 VAR Byte CRem3 VAR Byte CRem4 VAR Byte CRem5 VAR Byte CRem6 VAR Byte CRem7 VAR Byte CRem8 VAR Byte CRem9 VAR Byte


' -----[ Initialization ]------------------------------------- ' init: PAUSE 1000 'open debug window



' -----[ Main Code ]------------------------------------------ ' Start: 'Send Convert Temperature command OWOUT OWpin, OWFERst, [SkipROM, ConverT]



DEBUG CLS CheckForDone: 'Wait until conversion is done PAUSE 2 OWIN OWpin, OWBitMode, [Temp] DEBUG CR, BIN temp 'conversion time IF Temp = 0 THEN CheckForDone 'Send Read Scratch Pad command OWOUT OWpin, OWFERst, [SkipROM, ReadScratch] OWIN OWpin, OWBERst, [CRem1,CRem2,CRem3,CRem4,CRem4,CRem5,CRem6,CRem7,CRem8,CRem9]



DEBUG CR, BIN Temp DEBUG CR, BIN CRem1 DEBUG CR, BIN CRem2 DEBUG CR, BIN CRem3 DEBUG CR, BIN CRem4 DEBUG CR, BIN CRem5 DEBUG CR, BIN CRem6 DEBUG CR, BIN CRem7 DEBUG CR, BIN CRem8 DEBUG CR, BIN CRem9



PAUSE 5000 'next measurement in 5 sec GOTO Start


Can you get the correct response from 33h Read ROM?

jsw

Schematic, please.

Is your 'Vdd' pin properly grounded?

Do you have the required 5K data pullup resistor in place between system Vdd and the data pin? How about the FET in parallel with the pullup to provide the 'strong pullup' for data conversion?

Do you get the same pulse string when your sensor is disconnected from your processor?

--Winston

Karl say 'no'.

Karl > "I've been trying to get a Basic stamp to talk to a 1wire maxim DS1822 Karl > temperature sensor with no success."

--Winston

I've tried two ways, see the DS1822.pdf. There are three pins on the 1822. It can be run in parasite mode with the power pin grounded, or in power mode. Both ways call for a 4.7 Kohm pull-up resistor from 5 volt to data line.

My son is mailing my logic probe but I get 0 resistance to known ground on VOA meter.

Yes, 4.7 actually.

??? Don't understand you here. Both the resistor and the DS1822 have one leg on 5V and one leg on data so that would be a parallel connection. I didn't show a program I chopped up from a 1wire weather station to a stamp. It was written slightly different with turning the data pin into an output for a strong pull-up prior to the OWOUT command. This program gives same results.

No, that gives a long string of "1"s. Also get all "1"s with sensor in backward.

Can you get the correct response from 33h Read ROM?

jsw

I played with this a bit but abandoned this route. The data came out the same no matter which sensor (should be different) but also diddn't make sense. NOTE: The example programs were extremely complex so I'm sure I could have program errors. I also ran several "find serial no." example programs. They were unable to record a serial number. Again a complex program (for me)

If there's something worth looking at, I'll investigate more here. My thinking was get a simple one sensor circuit to work before playing with multiple units and serial numbers on the same bus.

Karl

other program clip:

' ******************************** ' Retrieve and display temperature ' ******************************** ' Show_Temp: eeAddr = DS1820 ' load device serial number GOSUB Load_SN

OWOUT OWpin, OW_FERst,[MatchROM, STR romData\8, CnvrtTemp]

HIGH OWpin ' extra juice during conversion PAUSE 750 INPUT OWpin

OWOUT OWpin, OW_FERst,[MatchROM, STR romData\8, RdScratch] OWIN OWpin, OW_BERst,[tLo, tHi]

tSign = sign ' save sign bit tempIn = tempIn >> 1 ' round to whole degrees IF (tSign = 0) THEN NoNeg1 tempIn = tempIn | $FF00 ' extend sign bits for negs

(...)

So, *both* the Vdd and GND pins of the DS1822 are grounded, yes? We are in 'parasite' mode, correcto?

See the first schematic on page 6, if you would please:

formatting link
In 'parasite' mode the chip needs a low impedance Vdd source connected to the data pin for at least 750 mS before each reading. The FET is needed since we have both the GND and Vdd pins of the DS1822 at GND potential.

Your program needs to turn on that separate output pin to drive the FET 'on' and then 'off' for the required amount of time before you take your reading.

Oopsy. We should see a 480 uS long negative going pulse on the data line every time your microcontroller reads the DS1822. All bets are off if we don't !INIT the chip.

--Winston

So we are powering the DS1822 separately, not in 'parasite' mode. One remaining mystery is why we aren't resetting the sensor. It doesn't have to work properly if we choose not to !INIT it.

I don't see where your program sends an !INIT pulse to reset the sensor.

Show_Temp: eeAddr = DS1820 ' load device serial number GOSUB Load_SN

OWOUT OWpin, OW_FERst,[MatchROM, STR romData\8, CnvrtTemp]

HIGH OWpin ' extra juice during conversion PAUSE 750 INPUT OWpin

OWOUT OWpin, OW_FERst,[MatchROM, STR romData\8, RdScratch] OWIN OWpin, OW_BERst,[tLo, tHi]

tSign = sign ' save sign bit tempIn = tempIn >> 1 ' round to whole degrees IF (tSign = 0) THEN NoNeg1 tempIn = tempIn | $FF00 ' extend sign bits for negs

(...)

--Winston

I've left the unit set up with power to the DS1822, non parasite mode. Communication with Don Foreman and others says this is the best most reliable way.

OWIN and OWOUT are stamp commands written just for 1wire comm. They talk about this pulse in the mode parameter. See below but it doesn't copy well to text. Or there's a link to the manual on this page:

formatting link
I've found four stamp programs that do 1wire. They all just use the OWIN and OWOUT commands.Note the second program example turns the comm. pin into an output to give extra power to the 1wire device while doing a temperature sample. This shouldn't be necessary in non parasite mode.

Now, I agree the DS1822 must not be receiving, or is not acknowleding this pulse. I'm just stuck, don't know what else to try.

Karl

OWIN - BASIC Stamp Command Reference

Page 296 . BASIC Stamp Syntax and Reference Manual 2.2 .

formatting link

This code will transmit a "reset" pulse to a 1-Wire device (connected to I/O

pin 0) and then will detect the device's "presence" pulse and then receive

one byte and store it in the variable result.

The Mode argument is used to control placement of reset pulses (and

detection of presence pulses) and to designate byte vs. bit input and

normal vs. high speed. Figure 5.19 shows the meaning of each of the 4

bits of Mode. Table 5.64 shows just some of the 16 possible values and

their effect.

I've tried both ways. Current set up is NON parasite mode.

...

Maybe I'm not understanding right, but I'm thinking the stamp does this as part of the OWIN command. I have no way to verify.

...

OK, my first assumption is that the example programs I've found on the Parallax site are correct from a software sytax point of view. I'm thinking this is handled for the programmer - I may be all wet here.

Karl

I have a 1 wire system setup to monitor 13 freezers, I used my computer a DS 9097, DS 18S20s and Lampomittari software. Here's a forum that will have someone that could help you set up a stamp. It helped me get started.

formatting link
Here's the top page, go to hardware and find hobby boards
formatting link

It's time to drag out the oscilloscope.

If you don't have one, 2 channels, 20MHz should be enough. Be sure you get at least two good probes, 3 is better. At that speed they can be different types and lengths.

I would use another Stamp output as a trigger just before the start of your data stream.

jsw

(...)

Have a look at:

AppNote001a_Getting_Started_with_1-Wire.PDF (Which is archived as:)

formatting link
...if you would, please.

You might be able to create a version of their source that'll talk to your DS1822.

Their source appears to have a bunch of initialization stuff in the beginning. This may be useful to you.

You'll note the use of a reset command in their example:

// Send reset pulse to 1-wire bus. oneWireBus.reset();

*That* is what I was looking for. :)

--Winston

This could be interesting. I have a Pick2 kit and a few of those sensors I ordered last year. Winter ended and I never pursued it further since the sensors showed up in spring.

I'll go back to eating dinner and reading.

Wes

-- "Additionally as a security officer, I carry a gun to protect government officials but my life isn't worth protecting at home in their eyes." Dick Anthony Heller

formatting link
This is for a different microcontroller and a different language.

rs I ordered last

owed up in spring.

Today would you buy the PicKit 3 instead? Or something else?

jsw

I found this, it's worth a try if you haven't already.

' -----[ Title ]----------------------------------------------------------------

'

' BS2p Professional Starter Kit

'

' File...... PSK_DS1822.BSP

' Purpose... Reads and displays information from a Dallas DS1822

' Author.... Parallax

' E-mail.... snipped-for-privacy@parallaxinc.com

' Started...

' Updated... 10 DEC 2001

' {$STAMP BS2p}

' -----[ Program Description ]--------------------------------------------------

'

' This program demonstrates using the DS1822 in its simplest form for direct

' temperature measurement. With only one sensor, we can use SkipROM and ignore

' the device serial number.

'

' Program output is via DEBUG.

' -----[ Revision History ]-----------------------------------------------------

'

' -----[ I/O Definitions ]------------------------------------------------------

'

OWpin CON 15

' -----[ Constants ]------------------------------------------------------------

'

' 1-Wire Support

'

OW_FERst CON %0001 ' Front-End Reset

OW_BERst CON %0010 ' Back-End Reset

OW_BitMode CON %0100

OW_HighSpd CON %1000

ReadROM CON $33 ' read ID, serial num, CRC

MatchROM CON $55 ' look for specific device

SkipROM CON $CC ' skip rom (one device)

SearchROM CON $F0 ' search

' DS1822 control

'

CnvrtTemp CON $44 ' do temperature conversion

RdScratch CON $BE ' read scratchpad

NoDevice CON %11 ' no device present

DS1822 CON $22 ' device code

DegSym CON 176

' -----[ Variables ]------------------------------------------------------------

'

devCheck VAR Nib ' device check return ocde

idx VAR Byte ' loop counter

romData VAR Byte(8) ' ROM data from DS1820

tempIn VAR Word ' raw temperature

sign VAR tempIn.Bit11 ' 1 = negative temperature

tLo VAR tempIn.LowByte

tHi VAR tempIn.HighByte

tSign VAR Bit

tempC VAR Word ' Celsius

tempF VAR Word ' Fahrenheit

' -----[ EEPROM Data ]----------------------------------------------------------

'

' -----[ Initialization ]-------------------------------------------------------

'

Initialize:

DEBUG CLS

PAUSE 250 ' allow DEBUG screen to open

' -----[ Main Code ]------------------------------------------------------------

'

Main:

GOSUB Device_Check ' look for device

IF (devCheck NoDevice) THEN Get_ROM

No_Device_Found:

DEBUG CLS,"No DS1822 present.", CR

DEBUG "-- Insert device and re-start."

END

Get_ROM

OWOUT OWpin,OW_FERst,[ReadROM] ' send Read ROM command

OWIN OWpin,OW_BERst,[STR romData\8] ' read serial number & CRC

IF (romData(0) = DS1822) THEN Show_Data

DEBUG "Installed device is not DS1822", CR

DEBUG "-- Code = ",HEX2 romData(0)

END

Show_Data:

DEBUG Home, "DS1822 Data",CR,CR

DEBUG "Serial Number : "

FOR idx = 6 TO 1

DEBUG HEX2 romData(idx)

NEXT

DEBUG CR," Checksum : ",HEX2 romData(7),CR,CR

Show_Raw:

GOSUB Get_Temp

DEBUG " Raw Input : ",BIN16 tempIn,CR,CR

Display_Temperatures:

DEBUG " Temp C : ", SDEC tempC,DegSym,CR

DEBUG " Temp F : ", SDEC tempF,DegSym,CR

PAUSE 1000

GOTO Main

END

' -----[ Subroutines ]----------------------------------------------------------

'

' This subroutine checks to see if any 1-Wire devices are present on the

' bus. It does NOT search for ROM codes

'

Device_Check:

devCheck = 0

OWOUT OWpin,OW_FERst,[SearchROM] ' reset and start search

OWIN OWpin,OW_BitMode,[devCheck.Bit1,devCheck.Bit0]

RETURN

Get_Temp:

OWOUT OWpin,OW_FERst,[SkipROM,CnvrtTemp] ' send conversion command

PAUSE 500 ' give it some time

OWOUT OWpin,OW_FERst,[SkipROM,RdScratch] ' go get the temperature

OWIN OWpin,OW_BERst,[tLo,tHi]

tSign = sign ' save sign bit

tempC = tempIn

tempC = tempC >> 4 ' round to whole degrees

IF (tSign = 0) THEN NoNegC

tempC = tempC | $FF00 ' extend sign bits for negs

NoNegC:

tempF = tempC */ $01CD ' multiply by 1.8

IF tSign = 0 THEN NoNegF ' if neg, extend sign bits

tempF = tempF | $FF00

NoNegF:

tempF = tempF + 32 ' finish C -> F conversion

RETURN

ordered last

up in spring.

The general opinion on the Microchip forums is the PICkit 3 is not yet ready for prime time. Some would say it is not fit for purpose. It has to re-flash its firmware every time you select a different 'family' of PICs and many users have complained of its tendency to 'brick' itself.

\ \Today would you buy the PicKit 3 instead? Or something else? \ \jsw

Having bought a PICKit2 and 3 last week, today I'd choose only the PICKit 2, maybe they will get the PICKit 3 right later. I'm waiting on a return authorization for the PICKit3, it doesn't even work correctly with the board it came with. I don't know about others but I have to hold pressure on my PICkit 3 to get it to work at all, I think something is wrong with the connector. Microchip is going to send me a RA. The PICkit2 works great however.

RogerN

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required