u8 MPU6050_Init (void)
{
u8 res;
res = I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_PWR_MGMT_1, 0x80);
if (res) return res;
delay_ms(500);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_GYRO_CONFIG, 0x00); //250g/s scale range
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_ACCEL_CONFIG, 0x00); //2g scale rande
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_INT_PIN_CFG, LATCH_INT_EN | INT_RD_CLEAR);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_INT_ENABLE, DATA_RDY_EN);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_USER_CTRL, 0x00);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_PWR_MGMT_1, 0x00);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_PWR_MGMT_2, 0x00);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_FIFO_EN, 0x00);
if (PIN_SYG(JP1))
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_SMPLRT_DIV, 1000/GyroSampleRateHzFast-1);
else
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_SMPLRT_DIV, 1000/GyroSampleRateHzNorm-1);
I2c_Write_Register(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_CONFIG, 0x06);
return res;
}
u8 MPU6050_GetResultXYZFast (int * x, int * y, int * z)
{
static u8 Buffer[7];
Errors.I2C_Error = CheckI2C(MPU6050_I2Cx);
#ifdef DRY_PIN_USE
if (PIN_SYG(DRY) == 0) return 0;
#endif
I2c_Read_Page(MPU6050_I2Cx, MPU6050_DEFAULT_ADDRESS, MPU6050_RA_INT_STATUS, Buffer, sizeof(Buffer));
if ((Buffer[0] & DATA_READY_BIT) == 0) return 0;
* x = uIntTosInt((Buffer[1]<<8)|Buffer[2])-x_offset;
* y = uIntTosInt((Buffer[3]<<8)|Buffer[4])-y_offset;
* z = uIntTosInt((Buffer[5]<<8)|Buffer[6])-z_offset;
return SUCCESS;
}