Hello,
I am trying to initialize the MP-9150 with the following requirements:
- Accel data only
- Sample Accel Data at 40Hz
- Accel data stored in FIFO
- CYCLE mode active so device sleeps between samples
- No interrupts required.
Most init sequences I have tried do not work. Usually the FIFO count remains zero. I finally got the device putting data into the FIFO but it looks to be garbage data. This sequence is the closest that I have gotten to success:
// Perform Device Reset and wait for it to come back
mpu_write_reg(PWR_MGMT_1_REG, 0x80);
while(true)
{
uint8_t b = 0;
mpu_read(PWR_MGMT_1_REG, &b, 1);
if(b == 0x40) break;
}
delay_ms(30); // Probably not necessary...
// Turn off Magnetometer
/* mpu_write_reg(MAGNET_CONFIG_REG, 0x00); */
// Accel Config Register
// Bits: Value: Description:
// 0-7 0 Disable High pass filter, +-4G Accel Range, No self-test active.
mpu_write_reg(ACCEL_CONFIG_REG, 0x08);
// Set the Low Pass Filter Register
// Based on the example code this *seems* to be necessary. Not sure why.
mpu_write_reg(LPF_CONFIG_REG, 0x04);
// Power Management 1 register
// Bits: Value: Description:
// 0-2 000 Use Internal Oscillator
// 3 1 Disable Temp Sensor
// 4 0 Unused
// 5 1 Wake up from sleep to take a sample (CYCLE mode active)
// 6 0 Disable Sleep Mode
// 7 0 Do not reset device
mpu_write_reg(PWR_MGMT_1_REG, 0x28);
delay_ms(30);
// Power Management 2 Register
// Bits: Value: Description:
// 0-2 111 Keep Gyro in standby mode
// 3-5 000 Do not disable the Accelerometer
// 6-7 11 Sample frequency at 40Hz
mpu_write_reg(PWR_MGMT_2_REG, 0xC7);
delay_ms(30);
// Interrupt Enable Register:
// Bits: Value: Description:
// 0-7 0's Disable All Interrupts
mpu_write_reg(INT_ENABLE_REG, BIT_DATA_RDY_EN);
delay_ms(30);
// User Control Register:
// Bits: Value: Description:
// 0 0 Do not reset signal paths
// 1 0 I2C Master Reset (Automatically clears after reset)
// 2 0 FIFO Reset (Automatically clears after reset)
// 3 0 Reserved
// 4 0 Don't know - must be set to zero
// 5 0 I2C Master mode NOT enabled
// 6 1 FIFO Enabled
// 7 0 Unused
mpu_write_reg(USER_CTRL_REG, 0x04); // Reset it first
delay_ms(100);
mpu_write_reg(USER_CTRL_REG, 0x40);
delay_ms(100);
// Interrupt Enable Register:
// Bits: Value: Description:
// 0-7 0's Disable All Interrupts
mpu_write_reg(INT_ENABLE_REG, BIT_DATA_RDY_EN);
delay_ms(30);
// Set the accel range back to +-4g
mpu_write_reg(ACCEL_CONFIG_REG, 0x08);
// FIFO Enable Register:
// Bits: Value: Description:
// 0-2 000 External Input data is NOT stored in FIFO
// 3 1 Accel Data is stored in FIFO
// 4-6 000 Gyro Data is NOT stored in FIFO
// 7 0 Temp data is NOT stored in FIFO
mpu_write_reg(FIFO_ENABLE_REG, 0x08);
delay_ms(30);
After this init I read the buffer continuously. The buffer is almost always full. Sometimes it contains all zeros. Other time it just contains random garbage values.
I also tried a different init sequence where I disabled CYCLE mode and set the Sample Rate Divider so that the accel is sampled about 40Hz. This mode seems to work just fine. But of course the power consumption is about 4 times higher because the device never goes to sleep. In this mode I was able to read good data out of the FIFO consistently.
Can someone please take a look at my init code above and offer any advice for improvements.
Thank you in advance.