This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432/MPU-6050 I2C

Other Parts Discussed in Thread: ENERGIA

Hi, 

Im new working with the MSP432 and i have a problem trying to read data from a MPU-6050 via I2C. Im trying to adapt a arduino's code, which connects to the MPU-6050 and reads the data from the accelerometer and gyroscope, for use in the MSP432-P401R, but I am not able to.

I have tried using Energy and CCS, but in both cases I read erroneous data and I dont know what is wrong. 

The energia's code is this: 

//Prueba de lectura de la IMU
//Librerias que incluímos:
#include <Wire.h> //Librería para la comunicacion con la IMU por I2C

//Declaración de variables para almacenar los datos de la IMU
int gyro_x, gyro_y, gyro_z;
long acc_x, acc_y, acc_z;
int temperatura;

#define LED RED_LED

void setup(){
Serial.begin(57600); //Inicilaización del monitor serie
Wire.begin(); //Inicializamos el I2C
// setup_IMU();
//Lee_IMU();
//Ahora mostramos los datos leidos de
Serial.println("Datos leídos de la IMU: ");
Serial.print("acc_x = ");
Serial.println(acc_x);
Serial.print("acc_y = ");
Serial.println(acc_y);
Serial.print("acc_z = ");
Serial.println(acc_z);
Serial.print("Temperatura: ");
Serial.println(temperatura);
Serial.print("gyro_x = ");
Serial.println(gyro_x);
Serial.print("gyro_y = ");
Serial.println(gyro_y);
Serial.print("gyro_z = ");
Serial.println(gyro_z);

pinMode(LED,OUTPUT);
digitalWrite(LED,HIGH);

}

void loop(){

}

void setup_IMU() {
//Función que se encarga de inicializar la IMU
Wire.beginTransmission(0x68);
Wire.write(0x6B);
Wire.write(0x00);
Wire.endTransmission();
//Configuración de la IMU
Wire.beginTransmission(0x68);
Wire.write(0x1C);
Wire.write(0x10);
Wire.endTransmission();
//Configuración del giroscopio
Wire.beginTransmission(0x68);
Wire.write(0x1B);
Wire.write(0x08);
Wire.endTransmission();
}

void Lee_IMU(){
//Subrutina que se utiliza para leer los datos de la IMU
Wire.beginTransmission(0x68);
Wire.write(0x3B);
Wire.endTransmission();
Wire.requestFrom(0x68,14);
while(Wire.available() <14); //Esperamos a haber leido los 14 datos
acc_x = Wire.read()<<8 |Wire.read();
acc_y = Wire.read()<<8 |Wire.read();
acc_z = Wire.read()<<8 |Wire.read();
temperatura = Wire.read()<<8 |Wire.read();
gyro_x = Wire.read()<<8 |Wire.read();
gyro_y = Wire.read()<<8 |Wire.read();
gyro_z = Wire.read()<<8 |Wire.read();

}

This is exactly the same code that i've used in a arduino, and it works perfectly.

I'm using pins 6.5 and 6.4 to connect to SCL and SDA, respectively (using the convenient pull up resistors).


I hope someone can help me.

Thanks you,

Luis.

  • Luis,

    What exactly is the data that you are receiving? Have you used a logic analyzer?
  • Hi Evan ,

    I'm new with code composer studio and with MSP432, I don't know how to analyze the logic signal, I do n't have an oscilloscope for it.

    When itried to read the IMU I always read a 65000 value or similar, but when i read the IMU with the arduino i read something really different.


    Can someone give me an example of how to read the IMU using CCS?.
    I have already tried to modify the example of CCS of i2ctmp006 but I still can not read the variables of the IMU well.

    Regards,
    Luis.
  • Alternatively, do you have some sample output you can copy/paste?

    Here's a distinction which is arcane, but which you can check in about 60 seconds:
    > acc_x = Wire.read()<<8 |Wire.read();

    This statement assumes that the arguments for "|" are evaluated left-to-right, but C does not guarantee this will happen. It's entirely possible that Arduino (AVR-GCC) and Energia (TI-ARM compiler) do it differently.

    A simple way to check is to take the actual results and reverse the bytes (low->high and vice versa) and see if those match the Arduino output. If not, you can look elsewhere. (I still suggest you re-code these statements someday.)
  • Hi Bruce,

    I have tried to reverse the bytes and it doesnt work....


    I do not know what else to do, I've tried everything I could think of. I would love to have someone solve my problem.

    Best regards.

    Luis.
  • Luis,

    I found a project on hackster.io using the MPU6050 with a LaunchPad and Energia. I don't have this IMU so I can't test it myself but the code and explanation there should be helpful.

    www.hackster.io/.../the-wingman-has-your-back-184ef0

**Attention** This is a public forum