So hab jetzt nochmal das abgeändert und ausprobiert.
Find alles sehr merkwürdig^^
Alle Ergebnisse wurden praktisch Zeitgleich erstellt und der Sensor wurde dabei nicht bewegt.
Hier mal der aktuelle Code zum Auslesen des ACC Wertes:
Die Ergebnisse hierzu:Code:Sub Acc_readsensordata() Slaveadress = Acc_w_addr '= &H30 Subadress = Out_x_l_a '= &H28 Subadress.7 = 1 'Variablen sind so deklariert: Dim Slaveadress As Byte Dim Subadress As Byte I2cstart I2cwbyte Slaveadress 'SAD+W I2cwbyte Subadress Incr Slaveadress 'for reading LSB=1 I2crepstart I2cwbyte Slaveadress 'SAD+R I2crbyte Iax_tmp(2) , Ack 'Variablen sind so deklariert: Dim Iax_tmp(2) As Byte At Iax Overlay Dim Iax As Integer I2crbyte Iax_tmp(1) , Ack I2crbyte Iay_tmp(2) , Ack I2crbyte Iay_tmp(1) , Ack I2crbyte Iaz_tmp(2) , Ack I2crbyte Iaz_tmp(1) , Nack I2cstop Print "Iax: " ; Iax ; " " ; "Iay: " ; Iay ; " " ; "Iaz: " ; Iaz End Sub
Code zum Auslesen des Magnetsensors ohne Shift:Iax: 4096 Iay: 0 Iaz: -7999
Iax: 4096 Iay: 4096 Iaz: -24383
Iax: 8192 Iay: 16384 Iaz: -12095
Die Ergebnisse hierzu:Code:Sub Magnet_readsensordata() Slaveadress = Magnet_w_addr '&H3C Subadress = Out_x_h_m '&H03 Subadress.7 = 1 'Variablen sind so deklariert: Dim Slaveadress As Byte Dim Subadress As Byte I2cstart I2cwbyte Slaveadress 'SAD+W I2cwbyte Subadress Incr Slaveadress 'for reading LSB=1 I2crepstart I2cwbyte Slaveadress 'SAD+R I2crbyte Imx_tmp(1) , Ack 'Variablen sind so deklariert: Dim Imx_tmp(2) As Byte At Imx Overlay Dim Imx As Integer I2crbyte Imx_tmp(2) , Ack I2crbyte Imy_tmp(1) , Ack I2crbyte Imy_tmp(2) , Ack I2crbyte Imz_tmp(1) , Ack I2crbyte Imz_tmp(2) , Nack I2cstop Print "Imx: " ; Imx ; " " ; "Imy: " ; Imy ; " " ; "Imz: " ; Imz End Sub
Imx: 21504 Imy: 1280 Imz: 1537
Imx: 18432 Imy: 1536 Imz: 2049
Imx: 17920 Imy: 0 Imz: 4097
Und nochmal Magnetsensor mit Shift
und deren Ergebnisse: (Ich habe auch deine Variante mit (Highbyte * 256 + Lowbyte) ausprobiert. kommt das selbe raus wie bei shift)Code:Sub Magnet_calcmvalues() Wait 1 Slaveadress = Magnet_w_addr '&H3C Subadress = Out_x_h_m '&H03 Subadress.7 = 1 'Variablen sind so deklariert: Dim Slaveadress As Byte Dim Subadress As Byte I2cstart I2cwbyte Slaveadress 'SAD+W I2cwbyte Subadress Incr Slaveadress 'for reading LSB=1 I2crepstart I2cwbyte Slaveadress 'SAD+R I2crbyte Abmagdata(1) , Ack 'Variablen sind so deklariert: Dim Abmagdata(6) As Byte I2crbyte Abmagdata(2) , Ack I2crbyte Abmagdata(3) , Ack I2crbyte Abmagdata(4) , Ack I2crbyte Abmagdata(5) , Ack I2crbyte Abmagdata(6) , Nack I2cstop 'Iaxx = Abmagdata(1) 'Variablen sind so deklariert: Dim Iaxx As Integer 'Shift Iaxx , Left , 8 'Iaxx = Iaxx + Abmagdata(2) Iayy = Abmagdata(3) Shift Iayy , Left , 8 Iayy = Iayy + Abmagdata(4) Iazz = Abmagdata(5) Shift Iazz , Left , 8 Iazz = Iazz + Abmagdata(6) Print "Shift: Imx: " ; Iaxx ; " " ; "Imy: " ; Iayy ; " " ; "Imz: " ; Iazz Print "" End Sub
Shift: Imx: 75 Imy: 11 Imz: 266
Shift: Imx: 83 Imy: 14 Imz: 264
Shift: Imx: 74 Imy: -6 Imz: 277
Lesezeichen