Exemple #1
0
void mpu6050_init(const nrf_drv_twi_t * twi)
{
	uint8_t inData[7]={0x00,												//0x19
								0x00,												//0x1A
								0x03,												//0x6B
								0x10,												//0x1B
								0x00,												//0x6A
								0x32,												//0x37
								0x01};											//0x38
	uint8_t acc = 0x00;	

    // Do a reset on signal paths
    uint8_t reset_value = 0x04U | 0x02U | 0x01U; // Resets gyro, accelerometer and temperature sensor signal paths.
    mpu6050_register_write(twi, MPU6050_RA_SIGNAL_PATH_RESET, reset_value);

    // Read and verify product ID
    mpu6050_verify_product_id(twi);
	
		//设置GYRO
	mpu6050_register_write(twi, MPU6050_RA_SMPLRT_DIV, 	inData[0]); //设置采样率    -- SMPLRT_DIV = 0  Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
	mpu6050_register_write(twi, MPU6050_RA_CONFIG, 		inData[1]); //CONFIG        -- EXT_SYNC_SET 0 (禁用晶振输入脚) ; default DLPF_CFG = 0 => (低通滤波)ACC bandwidth = 260Hz  GYRO bandwidth = 256Hz)
	mpu6050_register_write(twi, MPU6050_RA_PWR_MGMT_1, 	inData[2]); //PWR_MGMT_1    -- SLEEP 0; CYCLE 0; TEMP_DIS 0; CLKSEL 3 (PLL with Z Gyro reference)
	mpu6050_register_write(twi, MPU6050_RA_GYRO_CONFIG, inData[3]); //gyro配置 量程  0-1000度每秒
	mpu6050_register_write(twi, MPU6050_RA_USER_CTRL,	inData[4]);	// 0x6A的 I2C_MST_EN  设置成0  默认为0 6050  时能主IIC 	
	// 0x37的 推挽输出,高电平中断,一直输出高电平直到中断清除,任何读取操作都清除中断 使能 pass through 功能 直接在6050 读取5883数据
	mpu6050_register_write(twi, MPU6050_RA_INT_PIN_CFG, inData[5]);	
	mpu6050_register_write(twi, MPU6050_RA_INT_ENABLE,  inData[6]); //时能data ready  引脚	
								
	//设置 ACC
	mpu6050_register_write(twi, MPU6050_RA_ACCEL_CONFIG,acc);       //ACC设置  量程 +-2G s 	
}
//@-node:gan0ling.20140624184821.3316:mpu6050 declarations
//@+node:gan0ling.20140624184821.3317:mpu6050_init
bool mpu6050_init(uint8_t device_address)
{   
  bool transfer_succeeded = true;

  m_device_address = (uint8_t)(device_address << 1);

  // Do a reset on signal paths
  uint8_t reset_value = 0x04U | 0x02U | 0x01U; // Resets gyro, accelerometer and temperature sensor signal paths
  transfer_succeeded &= mpu6050_register_write(ADDRESS_SIGNAL_PATH_RESET, reset_value);

  // Read and verify product ID
  transfer_succeeded &= mpu6050_verify_product_id();

  return transfer_succeeded;
}