예제 #1
0
//初始化MPU3050,根据需要请参考pdf进行修改************************
void Init_MPU3050(void)
{
   Single_Write(MPU3050_Addr,PWR_M, 0x80);   //
   Single_Write(MPU3050_Addr,SMPL, 0x07);    //
   Single_Write(MPU3050_Addr,DLPF, 0x1E);    //±2000°
   Single_Write(MPU3050_Addr,INT_C, 0x00 );  //
   Single_Write(MPU3050_Addr,PWR_M, 0x00);   //
}
예제 #2
0
/******************************************************************************
/ 函数功能:HMC5883校准
/ 修改日期:none
/ 输入参数:none
/ 输出参数:none
/ 使用说明:启动-中断-查询 (查询)
******************************************************************************/
void HMC5883L_Calibrate(void)
{
   Single_Write(HMC5883L_Addr,HMC5883L_REGA,0x15);   //30Hz,启动自检模式
   Single_Write(HMC5883L_Addr,HMC5883L_MODE,0x01);   //单一测量模式
   delay_ms(10);
   Single_Write(HMC5883L_Addr,HMC5883L_REGA,0x14);
   Single_Write(HMC5883L_Addr,HMC5883L_MODE,0x00);   //回到工作模式
}
예제 #3
0
//**************************************
//初始化MPU6050
//**************************************
u8 InitMPU6050(void)
{
	u8 date;
	date = Single_Write(MPU6050_ADDRESS, PWR_MGMT_1, 0x00);	//解除休眠状态
	date += Single_Write(MPU6050_ADDRESS, SMPLRT_DIV, 0x07);
	date += Single_Write(MPU6050_ADDRESS, CONFIGL, 0x03);
	date += Single_Write(MPU6050_ADDRESS, GYRO_CONFIG, 0x10);
	date += Single_Write(MPU6050_ADDRESS, ACCEL_CONFIG, 0x09);//+-4G
	return date;
}
예제 #4
0
파일: mpu6050.c 프로젝트: sensiki/HT-Hawk
/*====================================================================================================*/
u8 InitMPU6050(void)
{
	u8 ack;
	
	ack = Single_Read(MPU6050_ADDRESS, WHO_AM_I);
	if (!ack)
     return FALSE;
	
	Single_Write(MPU6050_ADDRESS, PWR_MGMT_1, 0x00);  	//解除休眠状态
	Single_Write(MPU6050_ADDRESS, SMPLRT_DIV, 0x07);     
	Single_Write(MPU6050_ADDRESS, CONFIGL, MPU6050_DLPF);              //低通滤波
	Single_Write(MPU6050_ADDRESS, GYRO_CONFIG, MPU6050_GYRO_FS_1000);  //陀螺仪量程 +-1000
	Single_Write(MPU6050_ADDRESS, ACCEL_CONFIG, MPU6050_ACCEL_FS_4);   //加速度量程 +-4G
	return TRUE;
}
예제 #5
0
void Init_HMC5883L()
{
	 RCC->APB2ENR|=1<<6;    	//使能PORTE时钟	
	 GPIOE->CRL&=0xffffff00;
	 GPIOE->CRL|=0x00000077;
	 GPIOE->ODR|=3;
   Single_Write(HMC5883L_Addr,0x02,0x00);  
}
예제 #6
0
rt_err_t l3g4200d_init(const char * i2c_bus_device_name)
{
    i2c_device = rt_i2c_bus_device_find(i2c_bus_device_name);
    if(i2c_device == RT_NULL)
    {
        rt_kprintf("i2c bus device %s not found!\r\n", i2c_bus_device_name);
        return -RT_ENOSYS;
    }
	
//	RCC_Configuration();
//	NVIC_Configuration();
//	GPIO_Configuration();
	
	Single_Write(CTRL_REG1, 0x0f);
	Single_Write(CTRL_REG2, 0x00);
	Single_Write(CTRL_REG3, 0x08);
	Single_Write(CTRL_REG4, 0x30);	//+-2000dps
	Single_Write(CTRL_REG5, 0x00);
	
//	rt_sem_init(&l3g4200d_int2,"l3g_INT2",0,RT_IPC_FLAG_FIFO);
	
	return RT_EOK;
}
예제 #7
0
//*****************************************************************
//初始化ADXL345,根据需要请参考pdf进行修改************************
int Init_ADXL345()
{
    if(Single_Read(DEVICE_ID)==0XE5)
	{	//读取器件ID
    Single_Write(DATA_FORMAT,0x2b);   //测量范围,正负16g,13位模式
    Single_Write(BW_RATE,    0x0a);   //速率设定为12.5 
    Single_Write(POWER_CTL,  0x28);   //选择电源模式   
    Single_Write(INT_ENABLE, 0x00);   //使能 DATA_READY 中断
    Single_Write(OFSX,0x00);   //X 偏移量 
    Single_Write(OFSY,0x00);   //Y 偏移量 
    Single_Write(OFSZ,0x00);   //Z 偏移量 
	return 0;
	}
	else
	return 1;
}
예제 #8
0
void L3G4200_Init( void )
{
	u8 L3G4200_Init_Data[6] = {
			0x8F,	/* L3G4200_CTRL_REG1	普通模式,三轴使能, ODR:400Hz, CutOff:20, XYZEnable */
			0x00,	/* L3G4200_CTRL_REG2	普通模式,高通滤波截止频率30hz*/
			0x08,	/* L3G4200_CTRL_REG3	数据准备使能*/
			0x10,	/* L3G4200_CTRL_REG4	持续更新,满量程Range:2000dps */  //0X20  2000dps   0x10 500dps
			0x00,	/* L3G4200_CTRL_REG5	默认*/
			0x00	/* L3G4200_REFERENCE	默认*/
		};//这里以后要改指针,高端
	Single_Write(L3G4200_I2C_ADDR, L3G4200_CTRL_REG1,L3G4200_Init_Data[0]);delay_ms(1);
	Single_Write(L3G4200_I2C_ADDR, L3G4200_CTRL_REG2,L3G4200_Init_Data[1]);delay_ms(1);
	Single_Write(L3G4200_I2C_ADDR, L3G4200_CTRL_REG3,L3G4200_Init_Data[2]);delay_ms(1);
  Single_Write(L3G4200_I2C_ADDR, L3G4200_CTRL_REG4,L3G4200_Init_Data[3]);delay_ms(1);
	Single_Write(L3G4200_I2C_ADDR, L3G4200_CTRL_REG5,L3G4200_Init_Data[4]);delay_ms(1);
	Single_Write(L3G4200_I2C_ADDR, L3G4200_REFERENCE,L3G4200_Init_Data[5]);delay_ms(1);
}
예제 #9
0
파일: hmc5883l.c 프로젝트: ronicsu/fly
/******************************************************************************
/ 函数功能:启动HMC5883开始转换(适用于启动-中断-读取数据的程序)
/ 修改日期:none
/ 输入参数:none
/ 输出参数:none
/ 使用说明:启动-中断-查询 (启动)
******************************************************************************/
void HMC5883L_Start(void)
{
   Single_Write(HMC5883L_Addr,HMC5883L_REGA,0x14);   //30Hz
   Single_Write(HMC5883L_Addr,HMC5883L_MODE,0x00);   //连续测量模式
}
예제 #10
0
//自动校准
//xval,yval,zval:x,y,z轴的校准值
void ADXL345_AUTO_Adjust(char *xval,char *yval,char *zval)
{
	short tx,ty,tz;
	u8 i;
	short offx=0,offy=0,offz=0;
	Single_Write(POWER_CTL,0x00);	   	//先进入休眠模式.
	delay_ms(100);
	Single_Write(DATA_FORMAT,0X2B);	//低电平中断输出,13位全分辨率,输出数据右对齐,16g量程 
	Single_Write(BW_RATE,0x0A);		//数据输出速度为100Hz
	Single_Write(POWER_CTL,0x28);	   	//链接使能,测量模式
	Single_Write(INT_ENABLE,0x00);	//不使用中断		 

	Single_Write(OFSX,0x00);
	Single_Write(OFSY,0x00);
	Single_Write(OFSZ,0x00);
	delay_ms(12);
	for(i=0;i<10;i++)
	{
		ADXL345_RD_Avval(&tx,&ty,&tz);
		offx+=tx;
		offy+=ty;
		offz+=tz;
	}	 		
	offx/=10;
	offy/=10;
	offz/=10;
	*xval=-offx/4;
	*yval=-offy/4;
	*zval=-(offz-256)/4;	  
 	Single_Write(OFSX,*xval);
	Single_Write(OFSY,*yval);
	Single_Write(OFSZ,*zval);	
}