Zitat:
also die #2 bedeutet, dass die Peripherie verwendet wird, die als #2 deklariert wurde. Das ist allerdings nur für XMega-AVRs gültig (im Hinblick auf TWI), weil normale Megas nur eine TWI haben und somit die #2 komplett entfällt.
Dann lösche ich die einfach :)
Zitat:
Das Grundprogramm ist weder richtig noch falsch, es passt einfach nicht zu deiner Aufgabenstellung.
Warum ? Ich mit diesem Prog erst einmal nur sehen, ob ich der mpu überhaupt richtig Daten entnehmen kann (ob ich mit i2c alles richtig gemacht habe usw. )
Zitat:
Du müsstest TMP_Gyro... als Overlay definieren.
Warum ?
Zitat:
Außerdem weiß ich nicht, ob die Slave-Adressen richtig sind, aber da du diese ja schon angepasst hast, gehe ich davon aus, dass du das DB gelesen hast und entsprechend deiner Anschlussbelegung die Adresse richtig gewählt hast.
Also im Datenblatt steht bei AD0 = 0 (gnd) Adresse : 1101000 Das macht fürs schreiben also &HD0 und fürs lesen &HD1 ,oder ??
Zitat:
Deine Print-Ausgabe ist auch falsch bzw. unsinnig, da du als Mensch wohl nur schlecht die zwei Bytes (high & low) in sekundenschnelle zu einem int16 zusammensetzen kannst...
Naja, dass soll ja nur zum testen sein :)
Zitat:
Außerdem ist die Syntax falsch, aber da wird Bascom wohl sowieso meckern.
Warum falsch ? Bei mir hat Bascom nicht gemeckert ...
Zitat:
Am besten schreibst du erstmal ein compilierfähiges Grundprogramm (Controller-Def, Quarz, Mainloop) und fügst dann die relevaten Codeteile (zum Auslesen & Initialiseren des MPU) hinzu.
Ok. Hier:
Code:
$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600
$hwstack = 200
$swstack = 200
$framesize = 400
Config Portd.7 = Output
Config Sda = Portc.1
Config Scl = Portc.0
Config Twi = 100000
Declare Sub Read_gyro
Declare Sub Read_acc
Dim Tmp_gyrox(2) As Byte
Dim Tmp_gyroy(2) As Byte
Dim Tmp_gyroz(2) As Byte
Dim Tmp_accx(2) As Byte
Dim Tmp_accy(2) As Byte
Dim Tmp_accz(2) As Byte
Sound Portd.7 , 400 , 450
Sound Portd.7 , 400 , 250
Sound Portd.7 , 400 , 450
Wait 2
I2cinit
'--- (25) Sample Rate Divider = 1 ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 25 'Register 25 Sample Rate Divider (1..8 kHz)
I2cwbyte &B00000000 'Divider set to 1 (soll)
I2cstop 'stop condition
'--- (26) DLPF = 42/44 Hz ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 26 'Register 26 DLPF_CFG (digital lowpass filter) Configuration
I2cwbyte &B00000011 'Bits 0..2 = 011 (3) - ACC:44Hz, 4.9ms; Gyro:42Hz, 4.8ms
I2cstop 'stop condition
'--- (27) Gyro Full Range = +-2000°/s ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 27 'Register 27 Gyro Configuration
I2cwbyte &B00011000 'Bits 3+4 = 11 - Full Scale Range: +/-2000°/s
I2cstop 'stop condition
'--- (28) ACC Full Range = +-2g ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 28 'Register 28 ACC Configuration
I2cwbyte &B00000000 'Bits 3+4 = 00 - Full Scale Range: +/-2g / No High Pass Filter
I2cstop 'stop condition
'--- (107) Power Management 1 ---
I2cstart 'start condition
I2cwbyte &HD0 'write adress of MPU-6050
I2cwbyte 107 'Register 107 Power Management 1
I2cwbyte &B00001011 'No Reset / No Sleep / No Cycle / Temp_Sens: Dis / Clock Source: Z-Gyro
I2cstop
Do
Call Read_gyro
Print "Tmp_gyrox(2) :" ; Tmp_gyrox(2)
Print "Tmp_gyrox(1) :" ; Tmp_gyrox(1)
Waitms 20
Print "Tmp_gyroy(2) :" ; Tmp_gyroy(2)
Print "Tmp_gyroy(1) :" ; Tmp_gyroy(1)
Waitms 20
Print "Tmp_gyroz(2) :" ; Tmp_gyroz(2)
Print "Tmp_gyroz(1) :" ; Tmp_gyroz(1)
Waitms 100
Call Read_acc
Print "Tmp_accx(2) :" ; Tmp_accx(2)
Print "Tmp_accx(1) :" ; Tmp_accx(1)
Waitms 20
Print "Tmp_accy(2) :" ; Tmp_accy(2)
Print "Tmp_accy(1) :" ; Tmp_accy(1)
Waitms 20
Print "Tmp_accz(2) :" ; Tmp_accz(2)
Print "Tmp_accz(1) :" ; Tmp_accz(1)
Wait 1
Loop
End
Sub Read_gyro()
I2cstart
I2cwbyte &HD0
I2cwbyte 67
I2crepstart
I2cwbyte &HD1
I2crbyte Tmp_gyrox(2) , Ack
I2crbyte Tmp_gyrox(1) , Ack
I2crbyte Tmp_gyroy(2) , Ack
I2crbyte Tmp_gyroy(1) , Ack
I2crbyte Tmp_gyroz(2) , Ack
I2crbyte Tmp_gyroz(1) , Nack
I2cstop
'Gyrox = Gx
'Gyroy = 0 - Gy
'Gyroz = 0 - Gz
End Sub
Sub Read_acc()
I2cstart
I2cwbyte &HD0
I2cwbyte 59
I2crepstart
I2cwbyte &HD1
I2crbyte Tmp_accx(2) , Ack
I2crbyte Tmp_accx(1) , Ack
I2crbyte Tmp_accy(2) , Ack
I2crbyte Tmp_accy(1) , Ack
I2crbyte Tmp_accz(2) , Ack
I2crbyte Tmp_accz(1) , Nack
I2cstop
'Accx = Ax
'Accy = Ay
'Accz = Az
End Sub
Zitat:
Und du solltest noch die passende Lib für die I2C Kommunikation einfügen.
Habe ich noch nie gemacht und es hat trotzdem funktioniert. Muss ich das machen ?
Eine Frage an dich : sind die Grundeinstellungen von dir zum init für die mpu richtig ??