I'm trying to read the temperature with a DS18S20 every two seconds, printing the result on a RS232 printer.
The problem is that some times (everi 15/20 readings) the result goes from 28,00 to -0,00 or 60,00 then returns to 28,00 degrees (currente temperature in my office)
Below there is the code
Code: Select all
//--------------------------------------------
Delay_ms(500);
Ow_Reset(PORTE,2); // onewire reset signal
Ow_Write(PORTE,2, $CC); // issue SKIP ROM command to DS1820
Ow_Write(PORTE,2, $44); // issue CONVERT T command to DS1820
Delay_us(120);
i := Ow_Reset(PORTE,2);
Ow_Write(PORTE,2, $CC); // issue SKIP ROM command to DS1820
Ow_Write(PORTE,2, $BE); // issue READ SCRATCHPAD command to DS1820
j1 := Ow_Read(PORTE, 2); // get result
j2 := Ow_Read(PORTE, 2); // get result
if j2 = $FF then
begin
tmp_sign := '-'; // temperature sign
j1 := j1 or $FF; // complement of two
j1 := j1 + $01;
end
else
tmp_sign := ' ';
j2 := (j1 and $01)*5; // get decimal value
j1 := j1 shr 1; // get temp value
BEETEXT:='Tmp2 0.0000';
ByteToStr(j1, text); // whole number
BEETEXT[7]:= tmp_sign;
BEETEXT[8]:= text[1];
BEETEXT[9]:= text[2];
BEETEXT[10]:= '.';
ByteToStr(j2, text); // decimal
BEETEXT[11]:=text[2];
Usart_Write_Text(BEETEXT);
USART_Write(13); USART_Write(10);Delay_500us;
//--------------------------------------------
Thanks in advance