Hallo Rolf,
ja das dachte ich mir schon - ich hab aber leider keine Ahnung wie ich das machen könnte.
Ich bekomme eben als Ergebnis immer nur Mist bzw. einen Fehlercode.
Ich habe mal die meiner Meinung nach kritischen Stellen angehängt.
Die einzige Stelle, wo ich eben Probleme sehe sind die Funktionen
uDelay() und uDelay_1(). Wenn die TimeSlots nicht stimmen, bekomme ich
kein korrektes Ergebnis. Wie ich aber dafür ein kleines Testprogramm ohne Hardware
hinbekomme -
Code
//--------------------------------------------------------------------------
// READ_BYTE - Reads a byte from the one-wire bus.
//--------------------------------------------------------------------------
Function ReadByte: Byte;
//--------------------------------------------------------------------------
var
i: Byte;
Value: Byte;
begin
for i := 0 to 7 do
// initiate read bit time slot
OneWireDir := DirOutput;
OneWireLine := LowLine;
uDelay_1(1);
OneWireLine := HighLine;
OneWireDir := DirInput;
uDelay_1(15);
// reads byte in, one byte at a time and then shifts it left
If (OneWirePin = True) then
incl(Value, i);
else
excl(Value, i);
endif;
uDelay(11); // wait for rest of timeslot
endfor;
return (Value);
end ReadByte;
//--------------------------------------------------------------------------
// READ_Bit - Reads a bit from the one-wire bus.
//--------------------------------------------------------------------------
Function ReadBit : byte;
//--------------------------------------------------------------------------
VAR stat : boolean ;
begin // initiate read bit time slot
OneWireDir := DirOutput;
OneWireLine := LowLine;
uDelay_1(1);
OneWireLine := HighLine;
OneWireDir := DirInput;
uDelay_1(15);
stat := OneWirePin;
udelay(11); // wait for rest of timeslot
IF stat THEN
Return(1);
ELSE
RETURN(0);
ENDIF;
end ReadBit;
//--------------------------------------------------------------------------
// Write_Byte - Writes a byte to the one-wire bus.
//--------------------------------------------------------------------------
Procedure WriteByte (Value: Byte);
//--------------------------------------------------------------------------
var
i, temp : Byte;
begin
for i:=0 to 7 do
// initiate write bit time slot
OneWireDir := DirOutput;
OneWireLine := LowLine;
uDelay_1(1);
if ((Value shr i) and $01) > 0 then // shifts val right 'i' spaces
OneWireLine := HighLine; // return DQ high if write 1
endif;
uDelay(11); // hold value for remainder of timeslot
OneWireLine := HighLine;
OneWireDir := DirInput;
// uDelay_1(10); // ????????
endfor;
end WriteByte;
//--------------------------------------------------------------------------
// Write_Bit - Writes a bit to the one-wire bus.
//--------------------------------------------------------------------------
Procedure WriteBit(Value : byte);
//--------------------------------------------------------------------------
Begin
OneWireDir := DirOutput;
OneWireLine := LowLine;
uDelay_1(1); // 15us WriteSlot leave low
If value = 1 then
OneWireLine := HighLine;
EndIf ;
udelay(11); // If wite 0 THEN hold LOW for remainder of timeslot
OneWireLine := HighLine;
OneWireDir := DirInput;
// uDelay_1(10); //10us for each bit
End;
Code
//--------------------------------------------------------------------------
// ReadTemperature
//--------------------------------------------------------------------------
Function ReadTemperature(Sensor : Byte) : Int8;
//--------------------------------------------------------------------------
var
TLsb, // return temperature value
crc,
TMsb : Byte;
i,k : Byte;
ftemp : Int8;
begin
{$IFNDEF Simulator}
If OneWireReset THEN // select the DS1820
WriteByte(cmdMatchROM); // MatchCode
For i := 0 to 7 do // send RomNumber
WriteByte(RomArray[Sensor,i]);
Endfor;
Else
// Fehler...
Return(-127);
Endif;
WriteByte(cmdReadScratchpad); // Read Scratch Pad
for k := 0 to 8 do // read the data 9 bytes
RomGetA[k] := ReadByte;
crc := DoCrcByte(RomGetA[k]);
endfor;
Grüße
Elmar