diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/mpu6050.h b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/mpu6050.h index ee27b23..f79fb89 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/mpu6050.h +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/mpu6050.h @@ -43,6 +43,8 @@ void delay(volatile unsigned int count); #define G_X_OFFSET 4 #define A_Z_OFFSET 0 +#define IMU_ADDRESS 0x68 +#define IMU_CONNECTED (MPU_Sigle_Read(WHO_AM_I)==IMU_ADDRESS) typedef struct{ float gX; diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/mpu6050.c b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/mpu6050.c index 58e57d9..67009bc 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/mpu6050.c +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/mpu6050.c @@ -47,14 +47,13 @@ short MPU_GetData(unsigned char REG_Addr) { void MPU_init() { IIC_init(); - //delay(500); - MPU_Sigle_Write(PWR_MGMT_1, 0x00); - MPU_Sigle_Write(SMPLRT_DIV, 0x07); - MPU_Sigle_Write(CONFIG, 0x06); - MPU_Sigle_Write(GYRO_CONFIG, 0x18); - MPU_Sigle_Write(ACCEL_CONFIG, 0x01); - - //LED1 = MPU_Sigle_Read(WHO_AM_I) == 0x68?0:1; + do { + MPU_Sigle_Write(PWR_MGMT_1, 0x00); + MPU_Sigle_Write(SMPLRT_DIV, 0x07); + MPU_Sigle_Write(CONFIG, 0x06); + MPU_Sigle_Write(GYRO_CONFIG, 0x18); + MPU_Sigle_Write(ACCEL_CONFIG, 0x01); + } while(IMU_CONNECTED); } void MPU6050_getStructData(pSixAxis cache) { diff --git a/src/main.c b/src/main.c index a777379..97ffc12 100644 --- a/src/main.c +++ b/src/main.c @@ -5,7 +5,6 @@ #include "motor.h" #include "uart.h" #include "wifi.h" -#include "key.h" #define Kp 100.0f //比例增益支配率(常量) #define Ki 0.002f //积分增益支配率 @@ -102,7 +101,6 @@ int main() { #if defined (DEBUG_PID) || defined (DEBUG_MPU6050_EULER) || defined (DEBUG_MPU6050_SOURCEDATA) || defined (DEBUG_BLDC) SixAxis sourceData; #endif - initLED(); //Brushless motor auto init #ifdef DEBUG_BLDC