Hallo,
So habe Pullup Widerstände dran.
Aber ich kriege die Programmierung nicht hin. Entweder kommt als Wert 0 raus oder 65535. Woran liegt das?
Bräuchte dabei drigend Hilfe.
Code verwende ich folgenden.
Code:
Declare Function Rn_beschleunigung() As Word
' ---------------RN-Mega128Funk übliche ------------------
$regfile = "m128def.dat" ' Bei Mega 128 "
$framesize = 32
$swstack = 32
$hwstack = 32
$crystal = 16000000
$baud = 19200
$baud1 = 9600
Config Scl = Portd.0
Config Sda = Portd.1
Config Ping.0 = Output
Lcdpower Alias Portg.0
Config Pine.2 = Output
Rdy_hostempfangsbereit Alias Porte.2
Config Pine.5 = Input
Bsy_funkmodulsendebereit Alias Porte.5
Open "com2:" For Binary As #2
Sound Portg.2 , 400 , 450
Sound Portg.2 , 400 , 250
Sound Portg.2 , 400 , 450
' ---------------------------------------------------
Dim Beschleunigung As Word
Dim V As Byte
Wait 3
I2cinit
Print "RN-Mega128Funk Testprogramm "
V = 1
Do
Beschleunigung = Rn_beschleunigung()
Print "Wert x: " ; Beschleunigung
V = V + 3
Wait 1
Loop
End
Function Rn_beschleunigung() As Word
Local Lob As Byte
Local Hib As Byte
Local be_slaveid As Byte
Local be_slaveid_read As Byte
be_slaveid = &B00111011
be_slaveid_read = be_slaveid+1
'Register auswählen
I2cstart
I2cwbyte be_slaveid
I2cwbyte 2
I2cstop
I2cstart
I2cwbyte be_slaveid_read
I2crbyte Hib , Ack
I2crbyte Lob , Nack
I2cstop
Rn_beschleunigung = Makeint(lob , Hib)
End Function
Lesezeichen