Code
procedure InitMode(DevAdr : byte);
var
i : byte;
oddpar, ok : boolean;
begin
Writeln(Serout, 'TLV_init');
if I2Cinp(DevAdr, TLV_rdBuf) then
TLV_wrBuf[0]:= TLV_rdBuf[7] and %01111000;
TLV_wrBuf[0]:= TLV_wrBuf[0] or TLV_BITS_FST;
TLV_wrBuf[1]:= TLV_rdBuf[8];
TLV_wrBuf[2]:= TLV_rdBuf[9] and %00011111;
TLV_wrBuf[2]:= TLV_wrBuf[2] or TLV_BITS_LPP or TLV_BITS_PTE;
// Parity
// oddpar:= parity(TLV_rdBuf[6]);
oddpar:= parity(TLV_wrBuf[0]);
oddpar:= oddpar xor parity(TLV_wrBuf[1]);
oddpar:= oddpar xor parity(TLV_wrBuf[2]);
if not (oddpar) then
TLV_wrBuf[0]:= TLV_wrBuf[0] or %10000000;
endif;
for i:= 0 to 1 do
Write(Serout, bytetobin(TLV_wrBuf[i]));
Write(Serout, ',');
endfor;
Writeln(Serout, bytetobin(TLV_wrBuf[i]));
if not (I2Cout(DevAdr, 0, TLV_wrBuf)) then
Writeln(Serout, 'Write Error');
endif;
else
Writeln(Serout, 'Read Error');
endif;
end;
function InitAdr(DevAdr, iicadr : byte) : boolean;
var
MOD1 : byte;
begin
I2Cout(DevAdr, 0);
mdelay(5);
MOD1:= %010;
MOD1:= MOD1 or (iicadr shl 5);
if not (parity(MOD1)) then
MOD1:= MOD1 or %10000000;
endif;
Writeln(Serout, bytetobin(MOD1));
if not (I2Cout(DevAdr, 0, MOD1)) then
Writeln(Serout, 'Init Error ' + bytetobin(MOD1));
// I2Cout(DevAdr, 0);
return(false);
endif;
return(true);
end;
// setze Adressbits und PowerMode = master controlled
procedure TLV_PowerUp;
begin
sda:= true;
scl:= true;
mdelay(10);
InitAdr($5E, %11);
InitMode($4A);
sda:= true;
mdelay(10);
TLVVCC1:= true;
InitAdr($5E, %10);
InitMode($4E);
sda:= true;
mdelay(10);
TLVVCC2:= true;
InitAdr($5E, %01);
InitMode($5A);
sda:= true;
mdelay(10);
TLVVCC3:= true;
InitAdr($5E, %00);
InitMode($5E);
sda:= false;
mdelay(10);
TLVVCC4:= true;
InitAdr($1F, %11);
InitMode($0B);
sda:= false;
mdelay(10);
TLVVCC5:= true;
InitAdr($1F, %10);
InitMode($0F);
sda:= false;
mdelay(10);
TLVVCC6:= true;
InitAdr($1F, %01);
InitMode($1B);
sda:= false;
mdelay(10);
TLVVCC7:= true;
InitAdr($1F, %00);
InitMode($1F);
// I2Cscan;
end;
hello merlin,
this is the code i'm using at the moment. It is working somehow but it is not really stable.
One time all sensors are initialized, next time one or two not and they are not all times the same.
I guess this is a problem of timing during initialisation but i did not find the hotspot til now.
This is the reason why i'm using softi2c. When a sensor is completely initialized it is working correct. Beside this sensors there are two other devices on the board (NCP5623,PCA9554) and they are also working.
At the moment i have no idea what to do to get it stable.
Thanks for your interest
regards joachim