Gy-521 mit MSP430G3 (version 1.5) Launchpad

Gast #4513116
Lesenswert?

Hallo zusammen,
ich versuche vergeblich einen MPU6050 auf einem GY-521 breakout board 
mit einem MSP430G2 via I2C auszulesen. Ich habe die pins wie folgt 
belegt:

MSP    -> GY-521
GND    -> GND
VCC    -> VCC
Pin1.7 -> SDA
Pin1.8 -> SCL
(optional zusätzlich auch GND -> AD0 um die Adresse auf 0x69 
festzusetzen)

Der code, den ich in Energia verwende ist:


#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(9600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 
registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C 
(ACCEL_XOUT_L)
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E 
(ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 
(ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 
(TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 
(GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 
(GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 
(GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation 
for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);
  delay(333);
}

Die MPU-address sollte stimmen und ansonsten sehe ich nicht, wo der 
fehler liegen könnte. Den code habe ich von einem arduino-Beispiel 
benutzt. Die wire-library sollte ja identisch sein. Da das MSP430 nur 
3.3V ausgibt, habe ich auch schon extern 5V als power supply verwendet 
und kein anderes Ergebnis bekommen. Das GY-521 hat auch bereits pull-up 
Widerstände on-board. Hat jemand einen Tipp, was ich übersehe bzw. 
welchen Fehler ich mache?

Vielen Dank und viele Grüße,
Martin
Gast #4513474
Lesenswert?

Hallo,
danke für die Antwort, ich habe es mit 5V und 3.3V versucht und den ad0 
sowohl auf GND als auch auf 3.3V ausprobiert (dann jeweils addresse 0x68 
bzw. 0x69) verwendet. Andersherum habe ich's auch schon versucht. Leider 
ohne Erfolg
Gast #4513520
Lesenswert?

Hallo,
danke für die Antwort. Ich habe ein Multimeter zur Hand, mit dem ich die 
Leitungen abtasten kann. Wenn du das mit Scope meinst. Die 5V habe ich 
von einem arduino aus direkt an das GY-521 angeschlossen, als ich es mit 
einer 5V-Spannungsversorgung versucht habe.
Gast #4514172
Lesenswert?

@ Clemens: Sorry, ich meinte auch
Pin1.7 -> SDA
Pin1.6 -> SCL
war schon spät, als ich den post geschrieben habe, habe mich einfach 
vertippt.
@Wolfgang: Genau, 36.53, was kann ich darauf ableiten, dass alle 
Register als 0 gelesen werden? Der MPU6050 wird also einfach nicht 
ausgelesen. Wo könnte ich ansetzen das Problem zu finden?
Gast #4514202
Lesenswert?

Martin schrieb:
> Der MPU6050 wird also einfach nicht ausgelesen. Wo könnte ich
> ansetzen das Problem zu finden?

Du solltest erstmal prüfen, ob er über haupt reagiert, also ob der 
MPU6050 überhaupt auf dem Bus mit Ack reagiert. Das setzt allerdings 
mehr als ein Multimeter voraus.

In deinem Code ignorierst du sämtliche Rückgabewerte von wire.write() 
und liest in blindem Vertrauen vom Bus, ohne vorher mit Wire.available() 
zu prüfen, ob Wire.requestFrom() überhaupt angekommen ist. Da ist die 
Diagnosemöglichkeit natürlich eingeschränkt.

Ein simpler I2C-Scanner könnte dir verraten, ob der Sensor sich 
überhaupt meldet und ob die Adresse stimmt.
Gast #4514426
Lesenswert?

Den code habe ich, wie Clemens schon gesagt hat von 
http://playground.arduino.cc/Main/MPU-6050
übernommen. Das MSP430G2553 habe ich wie im angehängten Bild mit dem 
GY-521 verbunden. Der Pin unten rechts auf dem MSP ist ebenfalls ein GND 
pin (habe ich nachgemessen: VCC->GND unten rechts entspricht 3.3V). Den 
Jumper J51 habe ich rausgenommen, gemäß der Anleitung unter
http://energia.nu/pin-maps/guide_msp430g2launchpad/
Angehängte Dateien:
Gast #4515184
Lesenswert?

Die Ausgabe vom I2C scanner spuckt das aus:

Scanning...
I2C device found at address 0x01  !
I2C device found at address 0x02  !
I2C device found at address 0x03  !
I2C device found at address 0x04  !
I2C device found at address 0x05  !
I2C device found at address 0x06  !
I2C device found at address 0x07  !
I2C device found at address 0x08  !
I2C device found at address 0x09  !
I2C device found at address 0x0A  !
I2C device found at address 0x0B  !
I2C device found at address 0x0C  !
I2C device found at address 0x0D  !
I2C device found at address 0x0E  !
I2C device found at address 0x0F  !
I2C device found at address 0x10  !
I2C device found at address 0x11  !
I2C device found at address 0x12  !
I2C device found at address 0x13  !
I2C device found at address 0x14  !
I2C device found at address 0x15  !
I2C device found at address 0x16  !
I2C device found at address 0x17  !
I2C device found at address 0x18  !
I2C device found at address 0x19  !
I2C device found at address 0x1A  !
I2C device found at address 0x1B  !
I2C device found at address 0x1C  !
I2C device found at address 0x1D  !
I2C device found at address 0x1E  !
I2C device found at address 0x1F  !
I2C device found at address 0x20  !
I2C device found at address 0x21  !
I2C device found at address 0x22  !
I2C device found at address 0x23  !
I2C device found at address 0x24  !
I2C device found at address 0x25  !
I2C device found at address 0x26  !
I2C device found at address 0x27  !
I2C device found at address 0x28  !
I2C device found at address 0x29  !
I2C device found at address 0x2A  !
I2C device found at address 0x2B  !
I2C device found at address 0x2C  !
I2C device found at address 0x2D  !
I2C device found at address 0x2E  !
I2C device found at address 0x2F  !
I2C device found at address 0x30  !
I2C device found at address 0x31  !
I2C device found at address 0x32  !
I2C device found at address 0x33  !
I2C device found at address 0x34  !
I2C device found at address 0x35  !
I2C device found at address 0x36  !
I2C device found at address 0x37  !
I2C device found at address 0x38  !
I2C device found at address 0x39  !
I2C device found at address 0x3A  !
I2C device found at address 0x3B  !
I2C device found at address 0x3C  !
I2C device found at address 0x3D  !
I2C device found at address 0x3E  !
I2C device found at address 0x3F  !
I2C device found at address 0x40  !
I2C device found at address 0x41  !
I2C device found at address 0x42  !
I2C device found at address 0x43  !
I2C device found at address 0x44  !
I2C device found at address 0x45  !
I2C device found at address 0x46  !
I2C device found at address 0x47  !
I2C device found at address 0x48  !
I2C device found at address 0x49  !
I2C device found at address 0x4A  !
I2C device found at address 0x4B  !
I2C device found at address 0x4C  !
I2C device found at address 0x4D  !
I2C device found at address 0x4E  !
I2C device found at address 0x4F  !
I2C device found at address 0x50  !
I2C device found at address 0x51  !
I2C device found at address 0x52  !
I2C device found at address 0x53  !
I2C device found at address 0x54  !
I2C device found at address 0x55  !
I2C device found at address 0x56  !
I2C device found at address 0x57  !
I2C device found at address 0x58  !
I2C device found at address 0x59  !
I2C device found at address 0x5A  !
I2C device found at address 0x5B  !
I2C device found at address 0x5C  !
I2C device found at address 0x5D  !
I2C device found at address 0x5E  !
I2C device found at address 0x5F  !
I2C device found at address 0x60  !
I2C device found at address 0x61  !
I2C device found at address 0x62  !
I2C device found at address 0x63  !
I2C device found at address 0x64  !
I2C device found at address 0x65  !
I2C device found at address 0x66  !
I2C device found at address 0x67  !
I2C device found at address 0x68  !
I2C device found at address 0x69  !
I2C device found at address 0x6A  !
I2C device found at address 0x6B  !
I2C device found at address 0x6C  !
I2C device found at address 0x6D  !
I2C device found at address 0x6E  !
I2C device found at address 0x6F  !
I2C device found at address 0x70  !
I2C device found at address 0x71  !
I2C device found at address 0x72  !
I2C device found at address 0x73  !
I2C device found at address 0x74  !
I2C device found at address 0x75  !
I2C device found at address 0x76  !
I2C device found at address 0x77  !
I2C device found at address 0x78  !
I2C device found at address 0x79  !
I2C device found at address 0x7A  !
I2C device found at address 0x7B  !
I2C device found at address 0x7C  !
I2C device found at address 0x7D  !
I2C device found at address 0x7E  !
done
Gast #4515198
Lesenswert?

@ Clemens: wenn ich
Serial.print(Wire.requestFrom()) eingebe, wird der code nicht 
kompiliert, da requestForm() drei integers als inout benötigt. Welche 
soll ich dort eingeben?
Für die Überprüfung von endTransmission() habe ich lediglich die Zeile
Serial.print(Wire.endTransmission())
eingefügt
Gast #4515241
Lesenswert?

Martin schrieb:
> Die Ausgabe vom I2C scanner spuckt das aus:
>
> Scanning...
> I2C device found at address 0x01  !
> I2C device found at address 0x02  !
> ...
> I2C device found at address 0x7D  !
> I2C device found at address 0x7E  !
> done

Und du bist ganz sicher, dass deine I2C Bibliothek und dein µC incl. 
Beschaltung ok sind?

Das sieht weder nach einem Adress-0x68/0x69- noch nach einem 
MPU6050-Problem aus.
Gast #4515273
Lesenswert?

Hallo Wolfgang,
bei der Schaltung bin ich mir zu 100% sicher! Den code für den I2C 
scanner habe ich wie gesagt von
http://playground.arduino.cc/Main/I2cScanner
übernommen. Was du mit den I2C Bibliotheken meinst, weiß ich nicht. Ich 
habe den selben µC nun mit dem gleichn code an zwei unterschiedlichen 
Rechnern ausprobiert und bekomme immer das gleiche Ergebnis beim I2C 
scan. Wo liegt der Fehler? Hat jemand eine Idee?
Gast #4516677
Lesenswert?

Mit dem Arduino Uno funktioniert der Sensor bzw ich kann ihn über den 
Serial Monitor auslesen. Das Skript ist identisch zur Anleitung unter:
http://playground.arduino.cc/Main/MPU-6050
und der I2c-scanner wirft
I2C Scanner
Scanning...
I2C device found at address 0x68  !
done
aus. Mir ist aufgefallen, dass das MSP430 auch die selbe lange Liste an 
I2C devices ausspuckt, wenn das MPU6050 gar nicht angeschlossen ist. Ich 
mache anscheinend irgendwas falsch mit dem MSP.
Beitrag #4971017 wurde von einem Moderator gelöscht.

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