I am still researching the earlier phenomenon with the DS18B20 and have come accross another oddity.
Here is the code I am using to read the 18B20
[code:1:407aa0c02d]
.********************************************
read_temperature:
'Dallas 18B20
'Chip defaults to 12 bit unless programmed otherwise
'9 bit mode = &B00011111; 12 bit mode = &B01111111
'response from device is 9 bytes
'9th byte is the CRC of bytes 1 -8
'temperature is in bytes 1 & 2
dim ds18b20_sc(10) as byte '10 byte array
dim tempi as integer 'temporary int
1wreset
1wwrite &HCC
1wwrite &H4E 'program bit mode follows
1wwrite &B00000000
1wwrite &B00000000
1wwrite &B01111111 '12 bit mode
1wreset
1wwrite &HCC ' all
1wwrite &H44 ' start measure
Waitms 700
1wreset ' reset the bus
1wwrite &HCC ' read
1wwrite &HBE
For I = 1 To 9
Ds18b20_sc(i) = 1wread() 'place all 9 bytes into array
Next
1wreset
tempw = crc8(Ds18b20_sc(1) , 8) ' do crc on ist 8 bytes
'crc from device = byte9
if Ds18b20_sc(9) <> tempw then
print #1 , "crc err" ;
return 'use prev value
end if
tempi = makeint(Ds18b20_sc(1) , Ds18b20_sc(2)) 'get temperature as integer <<<<<<<<THIS LINE
temperaturesng = tempi * 0.0625 'to sng
print #1 , "18B20 temperature = " ; temperaturesng
return
'***************************************************************[/code:1:407aa0c02d]
When the line beginning makeint is reached, I get a whole heap ( 20 or more) of CRLF from my debug port which a softw serial port c.3.
If I replace that line with this:
[code:1:407aa0c02d]
tempi = 256 * Ds18b20_sc(2)
tempi = tempi + Ds18b20_sc(1)[/code:1:407aa0c02d]
then the problem goes away.
In both cases the correct temperature is reported.
[b:407aa0c02d][color=red:407aa0c02d](BASCOM-AVR version : 2.0.7.6 )[/b:407aa0c02d][/color:407aa0c02d]
↧