LM75 und C-Control

Gast #53631
Lesenswert?

Hallo Alle,

ich habe hier ein seeehr ernstes Problem mit einer C-Control, mit der
ich einen LM75 über I2C auslesen will.

Das Problem ist, dass ich zwar Werte empfange, diese aber immer nur in
2°-Schritten an- und absteigen. Ich kann das einfach nicht
nachvollziehen, zumal der Quelltext OK zu sein scheint.

Here it goes:

scl = 1 'I2C im Ruhezustand
sda = 1
pause t


sda = 0 : pause t 'Start Condition

scl = 0 : pause t


sda = 1 : tog scl : tog scl 'Geräteadresse senden
sda = 0 : tog scl : tog scl
sda = 0 : tog scl : tog scl
sda = 1 : tog scl : tog scl
sda = 0 : tog scl : tog scl
sda = 0 : tog scl : tog scl
sda = 0 : tog scl : tog scl
sda = 1
scl = 1             'Lesemodus
pause t
scl = 0

DEACT sda

' MSB vom I2C Bus lesen

msb = 0

for i=0 to 7

    scl = 1 : pause t

    if sda  then msb = msb or &B00000001

    if sda = 0 then msb = msb and &B11111110

    msb = msb shl 1

    scl = 0 : pause t

next



sda = 0

scl = 1 :  pause t

scl = 0

DEACT sda

pause t

' LSB vom I2C Bus lesen

lsb = 0

for i=0 to 7

    scl = 1 : pause t

    if sda  then lsb = lsb or &B00000001

    if sda = 0 then lsb = lsb and &B11111110

    lsb = lsb shl 1

    scl = 0 : pause t

next



DEACT sda

tog scl : tog scl



sda = 0

scl = 1 : pause t

sda = 1

print msb;
return

"Print msb" gibt immer nur Werte in Zweierschritten aus, also 20, 22,
24 etc.

Hat jemand eine Ahnung, woher das kommt?

Gruß,

Christoph
Gast #53634
Lesenswert?

Hmmm-ich hab ne Idee:
Du liest ein Bit, AND oder OR-st es in "msb" rein und shiftest dann.
Das würde bedeuten, daß ein Bit, daß in Bit0 des "msb"
reingeAND/OR-ed wird, automatisch nach dem Shift an der Stelle von Bit1
steht. Bit0 von MSB ändert sich nie, da es immer wieder durch den
shift-Befehl gelöscht wird. Setze den shl - Befehl an den Anfang der
Schleife, dann sollte es funktionieren.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren