/** Power on and prepare for general usage. * This will activate the device and take it out of sleep mode (which must be done * after start-up). This function also sets both the accelerometer and the gyroscope * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets * the clock source to use the X Gyro for reference, which is slightly better than * the default internal clock source. */ void MPU6050_Initialize() { // GYRO AT 2000g AND ACC AT 2g MPU6050_SetClockSource(MPU6050_CLOCK_PLL_XGYRO); MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, MPU6050_DLPF_BW_42); //set DLPF bandwidth to 42Hz MPU6050_SetFullScaleGyroRange(MPU6050_GYRO_FS_2000); MPU6050_SetFullScaleAccelRange(MPU6050_ACCEL_FS_2); MPU6050_SetSleepModeStatus(DISABLE); }
void KumpasHazirla(void) { MPU6050_WriteBits(0x0C<<1, 0x0A, 0, 8, 0x00); //PowerDownMode MPU6050_WriteBits(0x0C<<1, 0x0A, 0, 8, 0x0F); //SelfTest MPU6050_WriteBits(0x0C<<1, 0x0A, 0, 8, 0x00); //PowerDownMode, /** Write multiple bits in an 8-bit device register. * @param slaveAddr I2C slave device address * @param regAddr Register regAddr to write to * @param bitStart First bit position to write (0-7) * @param length Number of bits to write (not more than 8) * @param data Right-aligned value to write */ // MPU9150_I2C_ADDRESS = 0x0C; //change Adress to Compass // MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode // MPU9150_writeSensor(0x0A, 0x0F); //SelfTest // MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode // MPU9150_I2C_ADDRESS = 0x69; //change Adress to MPU // // MPU9150_writeSensor(0x24, 0x40); //Wait for Data at Slave0 // MPU9150_writeSensor(0x25, 0x8C); //Set i2c address at slave0 at 0x0C // MPU9150_writeSensor(0x26, 0x02); //Set where reading at slave 0 starts // MPU9150_writeSensor(0x27, 0x88); //set offset at start reading and enable // MPU9150_writeSensor(0x28, 0x0C); //set i2c address at slv1 at 0x0C // MPU9150_writeSensor(0x29, 0x0A); //Set where reading at slave 1 starts // MPU9150_writeSensor(0x2A, 0x81); //Enable at set length to 1 // MPU9150_writeSensor(0x64, 0x01); //overvride register // MPU9150_writeSensor(0x67, 0x03); //set delay rate // MPU9150_writeSensor(0x01, 0x80); // // MPU9150_writeSensor(0x34, 0x04); //set i2c slv4 delay // MPU9150_writeSensor(0x64, 0x00); //override register // MPU9150_writeSensor(0x6A, 0x00); //clear usr setting // MPU9150_writeSensor(0x64, 0x01); //override register // MPU9150_writeSensor(0x6A, 0x20); //enable master i2c mode // MPU9150_writeSensor(0x34, 0x13); //disable slv4 }
void MPU6050_enablemagnetometer() { //MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS,0x24, 7,8, 0x40); //delay(100); MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS,0x37, 7,8, 0x32); delay(100); MPU6050_WriteBit(MPU6050_DEFAULT_ADDRESS, 0x6A, 5,DISABLE); delay(100); MPU6050_WriteBits(AK8975_I2C_ADDR,AK8975_CNTL, 3,4, 0x0F); delay(100); MPU6050_WriteBits(AK8975_I2C_ADDR,AK8975_CNTL, 3,4, 0x0F); delay(100); MPU6050_WriteBits(AK8975_I2C_ADDR,AK8975_CNTL, 3,4, 0x0F); delay(100); MPU6050_WriteBits(AK8975_I2C_ADDR,AK8975_CNTL, 3,4, 0x00); delay(100); MPU6050_WriteBits(AK8975_I2C_ADDR,AK8975_CNTL, 3,4, 0x01); delay(100); }
/** Set full-scale accelerometer range. * @param range New full-scale accelerometer range setting * @see MPU6050_GetFullScaleAccelRange() */ void MPU6050_SetFullScaleAccelRange(uint8_t range) { MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range); }
/** Set full-scale gyroscope range. * @param range New full-scale gyroscope range value * @see MPU6050_GetFullScaleGyroRange() * @see MPU6050_GYRO_FS_250 * @see MPU6050_RA_GYRO_CONFIG * @see MPU6050_GCONFIG_FS_SEL_BIT * @see MPU6050_GCONFIG_FS_SEL_LENGTH */ void MPU6050_SetFullScaleGyroRange(uint8_t range) { MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range); }
/** Set clock source setting. * An internal 8MHz oscillator, gyroscope based clock, or external sources can * be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator * or an external source is chosen as the clock source, the MPU-60X0 can operate * in low power modes with the gyroscopes disabled. * * Upon power up, the MPU-60X0 clock source defaults to the internal oscillator. * However, it is highly recommended that the device be configured to use one of * the gyroscopes (or an external clock source) as the clock reference for * improved stability. The clock source can be selected according to the following table: * * <pre> * CLK_SEL | Clock Source * --------+-------------------------------------- * 0 | Internal oscillator * 1 | PLL with X Gyro reference * 2 | PLL with Y Gyro reference * 3 | PLL with Z Gyro reference * 4 | PLL with external 32.768kHz reference * 5 | PLL with external 19.2MHz reference * 6 | Reserved * 7 | Stops the clock and keeps the timing generator in reset * </pre> * * @param source New clock source setting * @see MPU6050_GetClockSource() * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_CLKSEL_BIT * @see MPU6050_PWR1_CLKSEL_LENGTH */ void MPU6050_SetClockSource(uint8_t source) { MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source); }
void MPU6050_Config(uint8_t source) { MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_CONFIG, 2, 3, source); }
void MPU6050_SetLowPassFilter(uint8_t range) { MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_CONFIG, 0, 8, range); }
/** Set DLPF_CFG * DLPF_CFG | Accelerometer(Fs 1khz) | Gyroscope * -----------+-------------------------------------- * |Bandwidth hz | Delay ms |Bandwidth hz | Delay ms | FS khz * 0x00 | 260 0.0 256 0.98 8 * 0x01 | 184 2.0 188 1.9 1 * 0x02 | 94 3.0 98 2.8 1 * 0x03 | 44 4.9 42 4.8 1 * 0x04 | 21 8.5 20 8.3 1 * 0x05 | 10 13.8 10 13.4 1 * 0x06 | 5 19.0 5 18.6 1 * 0x07 | RESERVED RESERVED 8 */ void MPU6050_SetDigitalLowPassFilter(uint8_t range) { MPU6050_WriteBits(MPU6050_DEFAULT_ADDRESS, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, range); }