Skip to content

Commit 4de7a47

Browse files
authored
Merge pull request #1 from eric-wieser/patch-2
Correct use of FS parameter
2 parents 63d7af4 + 0557964 commit 4de7a47

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

src/MPU9250.cpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -490,37 +490,25 @@ void MPU9250::MPU9250SelfTest(float * destination)
490490
uint8_t selfTest[6];
491491
int32_t gAvg[3] = {0}, aAvg[3] = {0}, aSTAvg[3] = {0}, gSTAvg[3] = {0};
492492
float factoryTrim[6];
493-
uint8_t FS = 0;
494-
495-
// Set gyro sample rate to 1 kHz
496-
writeByte(_I2Caddr, SMPLRT_DIV, 0x00);
497-
// Set gyro sample rate to 1 kHz and DLPF to 92 Hz
498-
writeByte(_I2Caddr, CONFIG, 0x02);
499-
// Set full scale range for the gyro to 250 dps
500-
writeByte(_I2Caddr, GYRO_CONFIG, 1<<FS);
501-
// Set accelerometer rate to 1 kHz and bandwidth to 92 Hz
502-
writeByte(_I2Caddr, ACCEL_CONFIG2, 0x02);
503-
// Set full scale range for the accelerometer to 2 g
504-
writeByte(_I2Caddr, ACCEL_CONFIG, 1<<FS);
505-
506-
// Get average current values of gyro and acclerometer
507-
for (int ii = 0; ii < 200; ii++)
508-
{
509-
Serial.print("BHW::ii = ");
510-
Serial.println(ii);
511-
// Read the six raw data registers into data array
512-
readBytes(_I2Caddr, ACCEL_XOUT_H, 6, &rawData[0]);
513-
// Turn the MSB and LSB into a signed 16-bit value
514-
aAvg[0] += (int16_t)(((int16_t)rawData[0] << 8) | rawData[1]) ;
515-
aAvg[1] += (int16_t)(((int16_t)rawData[2] << 8) | rawData[3]) ;
516-
aAvg[2] += (int16_t)(((int16_t)rawData[4] << 8) | rawData[5]) ;
517-
518-
// Read the six raw data registers sequentially into data array
519-
readBytes(_I2Caddr, GYRO_XOUT_H, 6, &rawData[0]);
520-
// Turn the MSB and LSB into a signed 16-bit value
521-
gAvg[0] += (int16_t)(((int16_t)rawData[0] << 8) | rawData[1]) ;
522-
gAvg[1] += (int16_t)(((int16_t)rawData[2] << 8) | rawData[3]) ;
523-
gAvg[2] += (int16_t)(((int16_t)rawData[4] << 8) | rawData[5]) ;
493+
uint8_t FS = GFS_250DPS;
494+
495+
writeByte(MPU9250_ADDRESS, SMPLRT_DIV, 0x00); // Set gyro sample rate to 1 kHz
496+
writeByte(MPU9250_ADDRESS, CONFIG, 0x02); // Set gyro sample rate to 1 kHz and DLPF to 92 Hz
497+
writeByte(MPU9250_ADDRESS, GYRO_CONFIG, FS<<3); // Set full scale range for the gyro to 250 dps
498+
writeByte(MPU9250_ADDRESS, ACCEL_CONFIG2, 0x02); // Set accelerometer rate to 1 kHz and bandwidth to 92 Hz
499+
writeByte(MPU9250_ADDRESS, ACCEL_CONFIG, FS<<3); // Set full scale range for the accelerometer to 2 g
500+
501+
for( int ii = 0; ii < 200; ii++) { // get average current values of gyro and acclerometer
502+
503+
readBytes(MPU9250_ADDRESS, ACCEL_XOUT_H, 6, &rawData[0]); // Read the six raw data registers into data array
504+
aAvg[0] += (int16_t)(((int16_t)rawData[0] << 8) | rawData[1]) ; // Turn the MSB and LSB into a signed 16-bit value
505+
aAvg[1] += (int16_t)(((int16_t)rawData[2] << 8) | rawData[3]) ;
506+
aAvg[2] += (int16_t)(((int16_t)rawData[4] << 8) | rawData[5]) ;
507+
508+
readBytes(MPU9250_ADDRESS, GYRO_XOUT_H, 6, &rawData[0]); // Read the six raw data registers sequentially into data array
509+
gAvg[0] += (int16_t)(((int16_t)rawData[0] << 8) | rawData[1]) ; // Turn the MSB and LSB into a signed 16-bit value
510+
gAvg[1] += (int16_t)(((int16_t)rawData[2] << 8) | rawData[3]) ;
511+
gAvg[2] += (int16_t)(((int16_t)rawData[4] << 8) | rawData[5]) ;
524512
}
525513

526514
// Get average of 200 values and store as average current readings

0 commit comments

Comments
 (0)