Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 21938

MSP432/MPU-6050 I2C

$
0
0

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.


Viewing all articles
Browse latest Browse all 21938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>