Martin Dusek

DS18B20 temperature sensor

Discussion created by Martin Dusek on Sep 30, 2008
Latest reply on Oct 5, 2008 by Martin Dusek
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

 

Outcomes