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.

MPU6050 with an lm4f120xl

Other Parts Discussed in Thread: TM4C1233H6PM

Hi!

I'm new here, and my English is poor, so sorry for bad language.

I have an lm4f120xl launchpad and an MPU6050 breakout board.

The I2C communication is working fine, i can read and write registers.

I use the TivaWare_C_Series-2.1.0.12573 with Rowley Crossworks for ARM.

The Stellarisware doesn't have sensorlib, therefore i set target processor to tm4c1233h6pm.

This is my code...

//**************************************************
// globals
//
  INT8U addr = 0;
  
  //
  // A boolean that is set when a MPU6050 command has completed.
  //
  volatile bool g_bMPU6050Done;
tI2CMInstance sI2CInst; tMPU6050 sMPU6050; //************************************************** // // The function that is provided by this example as a callback when MPU6050 // transactions have completed. // void MPU6050Callback(void *pvCallbackData, uint_fast8_t ui8Status) { // // See if an error occurred. // if(ui8Status != I2CM_STATUS_SUCCESS) { // // An error occurred, so handle it here if required. // // debug_printf("%d\n",ui8Status); } // // Indicate that the MPU6050 transaction has completed. // if(ui8Status == I2CM_STATUS_SUCCESS) { g_bMPU6050Done = true; } } void I2C3_IRQHandler() { I2CMIntHandler(&sI2CInst); } void new_task_code(void *p) { INT32U speed = SysCtlClockGet(); I2CSetup(I2C3_BASE, true); addr = I2CBusScan(I2C3_BASE); unsigned long ret; INT8U dataH[2], dataL[2]; float *pfAccel, *pfGyro; // // Enable interrupts to the processor. // IntMasterEnable(); I2CMInit(&sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, SysCtlClockGet());
// // Initialize the MPU6050. This code assumes that the I2C master instance // has already been initialized. // g_bMPU6050Done = false; MPU6050Init(&sMPU6050, &sI2CInst, addr, MPU6050Callback, &sMPU6050); while(!g_bMPU6050Done) { }
// Disable sleep mode MPU6050Write(&sMPU6050, MPU6050_O_PWR_MGMT_1, 0 , 1, MPU6050Callback, &sMPU6050); while(!g_bMPU6050Done) { } while (1) { // task logic goes here g_bMPU6050Done = false; MPU6050DataRead(&sMPU6050, MPU6050Callback, &sMPU6050); while(!g_bMPU6050Done) { } // // Get the new accelerometer and gyroscope readings. // MPU6050DataAccelGetFloat(&sMPU6050, pfAccel, pfAccel + 1, pfAccel + 2); MPU6050DataGyroGetFloat(&sMPU6050, pfGyro, pfGyro + 1, pfGyro + 2); ret = I2CReadData(I2C3_BASE, addr, MPU6050_O_GYRO_XOUT_H, dataH, 2); ret = I2CReadData(I2C3_BASE, addr, MPU6050_O_GYRO_XOUT_L, dataL, 2); ret = I2CReadData(I2C3_BASE, addr, MPU6050_O_ACCEL_XOUT_H, dataH, 2); ret = I2CReadData(I2C3_BASE, addr, MPU6050_O_ACCEL_XOUT_L, dataL, 2); } }

This code initialize a I2C periph and an mpu6050 instance. I2C interrupts are coming. The processor run at 50MHz.

The code is working, but it give me not correct results.

I think,in the pfAccel i get the gyro data, and the pfGyro contains zeros all the time.

pfAccel can be -10.xxx, -9.xxx, ... - ...+9.xxx, +10.xxx at the x,y and z axis, if i move, rotate the breakout board.

What i miss?

Thank You for help, best Regards!