TI中文支持网
TI专业的中文技术问题搜集分享网站

关于I2C驱动MPU6050的问题

TM4C123X 驱动MCU6050,这个我的初始化程序,运行后,

MPU6050_ACCEL_CONFIG_AFS_SEL_4G, MPU6050Callback,0);
while(!g_bMPU6050Done)
{
}

程序卡死在这个while里面,下面是我的初始化程序,请大神指导!!!

void I2C_Inital(void)
{ //MPU6050
// The I2C2 peripheral must be enabled before use.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

// Configure the pin muxing for I2C2 functions on port D0 and D1.
ROM_GPIOPinConfigure(GPIO_PE4_I2C2SCL);
ROM_GPIOPinConfigure(GPIO_PE5_I2C2SDA);

// Select the I2C function for these pins. This function will also
// configure the GPIO pins pins for I2C operation, setting them to
// open-drain operation with weak pull-ups. Consult the data sheet
// to see which functions are allocated per pin.
GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4);
ROM_GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5);
// Configure and Enable the GPIO interrupt. Used for INT signal from the
// MPU6050
// ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4);
// GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_4);
// ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);
// ROM_IntEnable(INT_GPIOB);
// Initialize I2C2 peripheral.
I2CMInit(&sI2CInst, I2C2_BASE, INT_I2C2, 0xff, 0xff,ROM_SysCtlClockGet());
}

// 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.
}
// Indicate that the MPU6050 transaction has completed.
g_bMPU6050Done = true;
}

// The MPU6050 example.
void MPU6050Example(void)
{
// Initialize the MPU6050. This code assumes that the I2C master instance
// has already been initialized.
g_bMPU6050Done = false;
MPU6050Init(&sMPU6050, &sI2CInst, 0x68, MPU6050Callback, 0);
while(!g_bMPU6050Done)
{ }
// Configure the MPU6050 for +/- 4 g accelerometer range.
g_bMPU6050Done = false;
MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_ACCEL_CONFIG,
~MPU6050_ACCEL_CONFIG_AFS_SEL_M,
MPU6050_ACCEL_CONFIG_AFS_SEL_4G, MPU6050Callback,0);
while(!g_bMPU6050Done)
{
}
// Loop forever reading data from the MPU6050. Typically, this process
// would be done in the background, but for the purposes of this example,
// it is shown in an infinite loop.
while(1)
{
// Request another reading from the MPU6050.
g_bMPU6050Done = false;
MPU6050DataRead(&sMPU6050, MPU6050Callback, 0);
while(!g_bMPU6050Done)
{
}
// Get the new accelerometer and gyroscope readings.
MPU6050DataAccelGetFloat(&sMPU6050, &fAccel[0], &fAccel[1], &fAccel[2]);
MPU6050DataGyroGetFloat(&sMPU6050, &fGyro[0], &fGyro[1], &fGyro[2]);
// Do something with the new accelerometer and gyroscope readings.
}
}

xyz549040622:

MPU6050上电复位后,唤醒了没有

赞(0)
未经允许不得转载:TI中文支持网 » 关于I2C驱动MPU6050的问题
分享到: 更多 (0)