bool mpu6050Detect(sensor_t * acc, sensor_t * gyro, uint8_t scale) { bool ack; uint8_t sig; delay(35); // datasheet page 13 says 30ms. other stuff could have been running meanwhile. but we'll be safe ack = i2cRead(MPU6050_ADDRESS, MPU_RA_WHO_AM_I, 1, &sig); if (!ack) return false; if (sig != MPU6050_ADDRESS) return false; // get chip revision + fake it if needed if (scale) mpuProductID = MPU6000_REV_C5; // no, seriously? why don't you make the chip ID list public. else i2cRead(MPU6050_ADDRESS, MPU_RA_PRODUCT_ID, 1, &mpuProductID); acc->init = mpu6050AccInit; acc->read = mpu6050AccRead; acc->align = mpu6050AccAlign; gyro->init = mpu6050GyroInit; gyro->read = mpu6050GyroRead; gyro->align = mpu6050GyroAlign; #ifdef MPU6050_DMP mpu6050DmpInit(); #endif return true; }
bool mpu6050Detect(sensor_t * acc, sensor_t * gyro, uint8_t scale) { bool ack; uint8_t sig; delay(35); // datasheet page 13 says 30ms. other stuff could have been running meanwhile. but we'll be safe ack = i2cRead(MPU6050_ADDRESS, MPU_RA_WHO_AM_I, 1, &sig); if (!ack) return false; // So like, MPU6xxx has a "WHO_AM_I" register, that is used to verify the identity of the device. // The contents of WHO_AM_I are the upper 6 bits of the MPU-60X0’s 7-bit I2C address. // The least significant bit of the MPU-60X0’s I2C address is determined by the value of the AD0 pin. (we know that already). // But here's the best part: The value of the AD0 pin is not reflected in this register. if (sig != (MPU6050_ADDRESS & 0x7e)) return false; // get chip revision + fake it if needed if (scale) mpuProductID = MPU6000_REV_C5; // no, seriously? why don't you make the chip ID list public. else i2cRead(MPU6050_ADDRESS, MPU_RA_PRODUCT_ID, 1, &mpuProductID); acc->init = mpu6050AccInit; acc->read = mpu6050AccRead; acc->align = mpu6050AccAlign; gyro->init = mpu6050GyroInit; gyro->read = mpu6050GyroRead; gyro->align = mpu6050GyroAlign; #ifdef MPU6050_DMP mpu6050DmpInit(); #endif return true; }