最近研究MPU9250,一参考www.deyisupport.com/.../59723.aspx
码。现在在MPU6050Init(&sMPU6050, &sI2CInst, 0x68, MPU6050Callback, 0); 这一条通不过。。。程序卡在i2cm_drv.c 的
if(ui8Enabled)
{
MAP_IntEnable(psInst->ui8Int);
}
处。
谢谢指教~
若能给一个完整的测试程序最好了。邮箱 2731263864@qq.com
我的程序如下:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/i2c.h"
#include "utils/uartstdio.h"
#include "i2cm_drv.h"
#include "mpu6050.h"
#include "sensorlib/hw_mpu6050.h"
#include "hw_ints.h"
#include "driverlib/rom.h"
tI2CMInstance sI2CInst;
tMPU6050 sMPU6050;
void MPU6050_I2C_Init(void)
{
//
// The I2C2 peripheral must be enabled before use.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//
// Configure the pin muxing for I2C3 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);
ROM_IntEnable(INT_I2C2);
//
// Enable interrupts to the processor.
//
ROM_IntMasterEnable();
//
// Initialize I2C3 peripheral.
//
I2CMInit(&sI2CInst, I2C2_BASE, INT_I2C2, 0xff, 0xff,
ROM_SysCtlClockGet());
}
//
// A boolean that is set when a MPU6050 command has completed.
//
volatile bool g_bMPU6050Done;
//
// 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 main(void)
{
float fAccel[3], fGyro[3]; //fMagneto[3];
ROM_FPUEnable();
ROM_FPULazyStackingEnable();//打开浮点运算,但是会消耗额外的堆栈空间
ROM_SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
//Pin_Init();
MPU6050_I2C_Init();
// IntPriorityGroupingSet(1);
// IntPrioritySet(INT_I2C2,1 << 5);
//
// 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)
{
}
MPU6050ReadModifyWrite(&sMPU6050,MPU6050_O_PWR_MGMT_1, 0x00,0x00,MPU6050Callback,0);
//
// 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, gyroscope, and magnetometer readings.
//
MPU6050DataAccelGetFloat(&sMPU6050, &fAccel[0], &fAccel[1],&fAccel[2]);
MPU6050DataGyroGetFloat(&sMPU6050, &fGyro[0], &fGyro[1], &fGyro[2]);
//MPU6050DataMagnetoGetFloat(&sMPU6050, &fMagneto[0], &fMagneto[1],&fMagneto[2]);
//
// Do something with the new accelerometer, gyroscope, and magnetometer
// readings.
//
}
}