Deklaration:
Code: Alles auswählen
program Project1;
{$O-,J-}
type
TSPIGPIO = bitpacked record
p0, p1, p2, p3, SlaveSelect, DataIn, DataOut, Clock: boolean;
end;
var
SPI_PORT: TSPIGPIO absolute PORTB;
SPI_DDR: TSPIGPIO absolute DDRB;
SPI_PIN: TSPIGPIO absolute PINB;
Wen ich einen 74HC165 Softwaremässig einlese, funktioniert alles bestens.
Code: Alles auswählen
function SoftShiftIn165: byte; // geht
var
i: byte;
begin
Result := 0;
for i := 0 to 7 do begin // LSBFIRST
Result := Result shl 1;
if SPI_PIN.DataIn then Inc(Result);
SPI_PORT.Clock := True;
SPI_PORT.Clock := False;
end;
end;
Will ich aber über die USI-Schnittstelle einlesen, kommt das Result falsch.
Code: Alles auswählen
function HardShiftIn165: byte; // geht nicht.
begin
USISR := (1 shl USIOIF);
repeat
USICR := (%01 shl USIWM) or (%010 shl USICS) or (1 shl USICLK) or (1 shl USITC);
until (USISR and (1 shl USIOIF)) <> 0;
Result := USIDR;
end;
Das gleiche Verhalten kann ich feststellen, wen ich Softwaremässig einlese, wie es shiftIn von Arduino macht. Man beachte das SPI_PORT.Clock .
Code: Alles auswählen
function SoftShiftIn165: byte; // geht nicht
var
i: byte;
begin
Result := 0;
for i := 0 to 7 do begin // LSBFIRST
Result := Result shl 1;
SPI_PORT.Clock := True;
if SPI_PIN.DataIn then Inc(Result);
SPI_PORT.Clock := False;
end;
end;
Geht dies überhaupt ?
Im Anhang der ganze Code.