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.

MPU 9150 DK-TM4C123G

I am extracting the mpu 9150 code from qslogger example code in Tivaware. However, I have problem in MPU9150AppI2CWait(__FILE__,__LINE) where it stuck in an infinite loop. Please help, thanks.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/fpu.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "grlib/grlib.h"
#include "utils/uartstdio.h"
#include "driverlib/gpio.h"
#include "inc/tm4c123gh6pge.h"
#include "sensorlib/hw_mpu9150.h"
#include "sensorlib/hw_ak8975.h"
#include "sensorlib/i2cm_drv.h"
#include "sensorlib/ak8975.h"
#include "sensorlib/mpu9150.h"
#include "sensorlib/comp_dcm.h"

#define MPU9150_I2C_ADDRESS 0x69
#define X 0
#define Y 1
#define Z 2

tI2CMInstance g_sI2CInst; //i2c master driver
tMPU9150 g_sMPU9150Inst; //mpu9150
volatile uint_fast8_t g_vui8I2CDoneFlag;
volatile uint_fast8_t g_vui8ErrorFlag;
volatile uint_fast8_t g_vui8DataFlag;
int16_t g_i16Accel[3];
int16_t g_i16Gyro[3];
int16_t g_i16Mag[3];
uint32_t pui32ADC0Value[1];
float g_pfAccel[3];
float g_pfGyro[3];
float g_pfMag[3];




void MPU9150AppCallback(void *pvCallbackData, uint_fast8_t ui8Status)
{

if(ui8Status == I2CM_STATUS_SUCCESS)
{
g_vui8I2CDoneFlag = 1;
}

g_vui8ErrorFlag = ui8Status;
}

void MPU9150AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line)
{
UARTprintf("App Error!");
while(1)
{
}
}

void MPU9150AppI2CWait(char *pcFilename, uint_fast32_t ui32Line)
{
while((g_vui8DataFlag == 0) && (g_vui8ErrorFlag == 0))
{
}
if(g_vui8ErrorFlag)
{
MPU9150AppErrorHandler(pcFilename, ui32Line);
}
g_vui8DataFlag = 0;
}


void IntGPIOb(void)
{
unsigned long ulStatus;

ulStatus = GPIOIntStatus(GPIO_PORTB_BASE, true);

GPIOIntClear(GPIO_PORTB_BASE, ulStatus);

if(ulStatus & GPIO_PIN_2)
{

MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst);
}
}

void IntMPU9150I2CHandler(void)
{
I2CMIntHandler(&g_sI2CInst);
}

void ConsoleInit()
{
//UART Init
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

UARTStdioConfig(0, 115200, SysCtlClockGet());

UARTEnable(UART0_BASE);
UARTprintf("UART Init \n");

}



int main()
{
ConsoleInit();

//I2C
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);


GPIOPinConfigure(GPIO_PD0_I2C3SCL);
GPIOPinConfigure(GPIO_PD1_I2C3SDA);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
IntMasterEnable();

I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, SysCtlClockGet());
UARTprintf("I2CM Init\n");
SysCtlDelay(SysCtlClockGet()/3);
//MPU9150Init
MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,MPU9150AppCallback, &g_sMPU9150Inst);
UARTprintf("MPU9150 Init");
MPU9150AppI2CWait(__FILE__,__LINE__);
UARTprintf("Transaction!\n");

g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
MPU9150AppCallback, &g_sMPU9150Inst);

MPU9150AppI2CWait(__FILE__,__LINE__);
UARTprintf("Sensor Configured!\n");

g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
MPU9150_INT_PIN_CFG_LATCH_INT_EN;
g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
&g_sMPU9150Inst);

MPU9150AppI2CWait(__FILE__, __LINE__);

UARTprintf("hello \n");

while(1)
{

//i2c status

//mpu 9150 reading

MPU9150DataAccelGetFloat(&g_sMPU9150Inst, &g_pfAccel[X], &g_pfAccel[Y],
&g_pfAccel[Z]);

g_i16Accel[0]= ((g_pfAccel[0] /9.81f)*100.f);
g_i16Accel[1]= ((g_pfAccel[1] /9.81f)*100.f);
g_i16Accel[2]= ((g_pfAccel[2] /9.81f)*100.f);

MPU9150DataGyroGetFloat(&g_sMPU9150Inst, &g_pfGyro[X], &g_pfGyro[Y],
&g_pfGyro[Z]);

g_i16Gyro[X]= (g_pfGyro[X] *100.f);
g_i16Gyro[Y]= (g_pfGyro[Y] *100.f);
g_i16Gyro[Z]= (g_pfGyro[Z] *100.f);

MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, &g_pfMag[X], &g_pfMag[Y],
&g_pfMag[Z]);

g_i16Mag[X]= (int16_t) (g_pfMag[X] *1000000.f);
g_i16Mag[Y]= (int16_t) (g_pfMag[Y] *1000000.f);
g_i16Mag[Z]= (int16_t) (g_pfMag[Z] *1000000.f);
}



}