DS18B20 temperature sensor

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DS18B20 temperature sensor

4,168 Views
gaminn
Contributor IV
Hi,
I use Dallas DS18B20 temperature sensor with HC08 QT4 (sensor is connected to 0,PTA). My problem is, that everytime I try to read temperature from DS18B20, I get 0550h (= 85°C). I use the sensor with an external power supply. Between temperature conversion command and read command is more than one second of inactivity (so sensor should have enough time to convert the temperature).
 
To convert the temperature I use:
Code:
        jsr     oneWireReset        mov     #$CC,param        jsr     oneWireSendByte        mov     #$44,param        jsr     oneWireSendByte

 
To read temperature I use:
Code:
        jsr     oneWireReset        mov     #$CC,param        jsr     oneWireSendByte        mov     #$BE,param        jsr     oneWireSendByte
 
The routines I use to communicate with sensor are:
 
** reset routine
Code:
oneWireReset:        bset    0,DDRA        bclr    0,PTA        jsr     wait800u        bclr    0,DDRA        bset    0,PTAPUE        jsr     wait800u        rts

** write routine (writes data to DS18B20)
Code:
oneWireSendByte:        lda     param        mov     #!8,temp+$4writeLoopTemp:        bset    0,DDRA        bclr    0,PTA        lsra        bcc     writeZero        bra     writeOnewriteZero        jsr     wait70u        bset    0,PTA        jsr     wait10u        bra     endOfBitwriteOne:        jsr     wait5u        bset    0,PTA        jsr     wait70uendOfBit        dbnz    temp+$4,writeLoopTemp        bclr    0,DDRA        bset    0,PTAPUE        rts

 ** read routine (reads data from DS18B20)
Code:
oneWireReadByte:        mov     #!8,temp+$5readLoop:        jsr     wait70u        bset    0,DDRA        bclr    0,PTA        jsr     wait5u        bclr    0,DDRA        bset    0,PTAPUE        jsr     wait5u        lda     return        lsra        brclr   0,PTA,readZero        add     #$80readZero:        sta     return        dbnz    temp+$5,readLoop        rts

 

Labels (1)
0 Kudos
5 Replies

797 Views
gaminn
Contributor IV
Thanks for advice, I forgot to handle this. But it isn't the problem....
 
Today I bought new sensor, and it works. I'm not aware I made anything that could cause failure of the sensor, but probably I did...
 
Thanks to all
0 Kudos

797 Views
RogerSchaefer
Contributor III
Hi,
 
I've been running the DS18B20 with various Freescale CPU's for years.  Works great.  Check out my webpage on the subject to see my code.
 
Roger
0 Kudos

797 Views
donw
Contributor IV
the $0550 temp. reply is the default temperature if no conversion has been done.
So it seems your byte write & read routines are working OK, since you get a reply!
(perhaps try the 'read rom' command $33, to see if you can read the fixed rom value reliably)
Have you got an external pullup resistor (~1K) on the bus?. Using only the uP's internal pullup
maybe too high a value, causing a slow rise time...
0 Kudos

797 Views
gaminn
Contributor IV
Thanks. I have 4.2k pull up on line. It should be enough.
 
Another remark is that if I test sensor after sending conversion command, if the conversion is running (sensor responds by zeros when the conversion is running), I get zeros only approx. for 1 msec. I test it in 0.5msec loop, which means I get only two respons. After that, sensor begins to respond with ones.
 
Martin
0 Kudos

797 Views
bigmac
Specialist III
Hello Martin,
 
This may not have any bearing on your present problem, but it is a good idea to globally disable interrupts during the processing of each bit, where timing is critical.  Here, I assume that each delay routine is simply a timed software loop, and not reliant on any interrupt.  It should be possible to re-enable interrupts between bits so that any pending interrupt may be processed, before continuing with the next bit timing.
 
Regards,
Mac
 
0 Kudos