Exemplo n.º 1
0
u8 MPU_Init(void)
{ 
	u8 res;
	//RCC->APB2ENR|=1<<2;     //??PORTA?? 
	//GPIOA->CRH&=0X0FFFFFFF;	//PA15???????	  
	//GPIOA->CRH|=0X30000000; 
	//JTAG_Set(SWD_ENABLE);	//??JTAG,??PA15?????IO??,??PA15?????IO!!!
	//MPU_AD0_CTRL=0;			//??MPU6050?AD0?????,?????:0X68
	
	MPU_IIC_Init();//???IIC??
	MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X80);	//??MPU6050
  delay_ms(100);
	MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X00);	//??MPU6050 
	MPU_Set_Gyro_Fsr(3);					//??????,�00dps
	MPU_Set_Accel_Fsr(0);					//??????,�
	MPU_Set_Rate(50);						//?????50Hz
	MPU_Write_Byte(MPU_INT_EN_REG,0X00);	//??????
	MPU_Write_Byte(MPU_USER_CTRL_REG,0X00);	//I2C?????
	MPU_Write_Byte(MPU_FIFO_EN_REG,0X00);	//??FIFO
	MPU_Write_Byte(MPU_INTBP_CFG_REG,0X82);	//MPU_INTBP_CFG_REG 0x37
	res=MPU_Read_Byte(MPU_DEVICE_ID_REG);
	if(res==MPU_ADDR)//??ID??
	{
		MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X01);	//??CLKSEL,PLL X????
		MPU_Write_Byte(MPU_PWR_MGMT2_REG,0X00);	//??????????
		MPU_Set_Rate(50);						//??????50Hz
 	}
	else 
		return 1;
	
	return 0;
}
Exemplo n.º 2
0
//初始化MPU6050
//返回值:0,成功
//    其他,错误代码
uint8_t MPU_Init(void)
{ 
	uint8_t res;
//	IIC_Init();//初始化IIC总线
	MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X80);	//复位MPU6050
    delay_ms(100);
	MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X00);	//唤醒MPU6050 
	MPU_Set_Gyro_Fsr(3);					//陀螺仪传感器,±2000dps
	MPU_Set_Accel_Fsr(0);					//加速度传感器,±2g
	MPU_Set_Rate(50);						//设置采样率50Hz
	MPU_Write_Byte(MPU_INT_EN_REG,0X00);	//关闭所有中断
	MPU_Write_Byte(MPU_USER_CTRL_REG,0X00);	//I2C主模式关闭
	MPU_Write_Byte(MPU_FIFO_EN_REG,0X00);	//关闭FIFO
	MPU_Write_Byte(MPU_INTBP_CFG_REG,0X80);	//INT引脚低电平有效
	res=MPU_Read_Byte(MPU_DEVICE_ID_REG);
	if(res==MPU_ADDR)//器件ID正确
	{
		printf("\nRight\n\r");
		MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X01);	//设置CLKSEL,PLL X轴为参考
		MPU_Write_Byte(MPU_PWR_MGMT2_REG,0X00);	//加速度与陀螺仪都工作
		MPU_Set_Rate(50);						//设置采样率为50Hz
 	}
	else 
	{
		printf("\n Error \n\r");
		return 1;
	}
	return 0;
}
Exemplo n.º 3
0
//初始化MPU6050
//返回值:0,成功
//    其他,错误代码
u8 MPU_Init(void)
{ 
	u8 res;
	IIC_Init();//初始化IIC总线
	if(MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X80)){
		return 2;
	}	//复位MPU6050
	delay_ms(100);
	if(MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X00)){
		return 3;
	}	//唤醒MPU6050 
	if(MPU_Set_Gyro_Fsr(3)){
		return 4;
	}					//陀螺仪传感器,±2000dps
	if(MPU_Set_Accel_Fsr(0)){
		return 5;
	}					//加速度传感器,±2g
	if(MPU_Set_Rate(50)){
		return 6;
	}						//设置采样率50Hz
	if(MPU_Write_Byte(MPU_INT_EN_REG,0X00)){
		return 7;
	}	//关闭所有中断
	if(MPU_Write_Byte(MPU_USER_CTRL_REG,0X00)){
		return 8;
	}	//I2C主模式关闭
	if(MPU_Write_Byte(MPU_FIFO_EN_REG,0X00)){
		return 9;
	}	//关闭FIFO
	if(MPU_Write_Byte(MPU_INTBP_CFG_REG,0X80)){
		return 10;
	}	//INT引脚低电平有效
	res=MPU_Read_Byte(MPU_DEVICE_ID_REG);
	if(res==MPU_ADDR)//器件ID正确
	{
		MPU_Write_Byte(MPU_PWR_MGMT1_REG,0X01);	//设置CLKSEL,PLL X轴为参考
		MPU_Write_Byte(MPU_PWR_MGMT2_REG,0X00);	//加速度与陀螺仪都工作
		MPU_Set_Rate(50);						//设置采样率为50Hz
 	}else {
		printf("address error: %X\n",res);
		return 1;
	};
	return 0;
}