I'm trying set the high pass filter, and followed some of the instructions in the notes and using the arduino package already created. It works a bit, but when I lay the accelerometer flat I'm still getting some of the gravity effect (about half) in my data. I've tried to configure the settings to choose different cutoffs, but still no luck. I've seen that others on this site have nearly eliminated the effect of gravity. Here's a snapshot of my output and then my code taken, or adapted, from arduino code:
Output
x, y, z
-1.29526,-4.54898, 1.33836
-1.29047,-4.54180, 1.31442
-1.29047,-4.54898, 1.30723
Set data rate to 2G with HPF default cutoff:
uint8_t reg1 = readRegister8(MMA8451_REG_CTRL_REG1);
writeRegister8(MMA8451_REG_CTRL_REG1, 0x00); // deactivate
writeRegister8(MMA8451_REG_XYZ_DATA_CFG, 0b00001 & 0x13);
writeRegister8(MMA8451_REG_CTRL_REG1, reg1 | 0x01); // activate
Set data rate to 800Hz:
uint8_t ctl1 = readRegister8(MMA8451_REG_CTRL_REG1);
readRegister8(0x0F);
writeRegister8(MMA8451_REG_CTRL_REG1, 0x00); // deactivate
writeRegister8(0x0F, 0x00);
ctl1 &= ~(0b111 << 3); // mask off bits
ctl1 |= (0b000 << 3);
writeRegister8(MMA8451_REG_CTRL_REG1, ctl1 | 0x01); // activate
Set HPF:
uint8_t reg1 = readRegister8(MMA8451_REG_CTRL_REG1);
writeRegister8(MMA8451_REG_CTRL_REG1, 0x00); // deactivate
writeRegister8(MMA8451_REG_HPF, 0x03);
writeRegister8(MMA8451_REG_CTRL_REG1, reg1 | 0x01); // activate
Hi Chris,
In order to get the HPF data, the HPF_OUT bit must be set in the XYZ_DATA_CFG register (0x0E). Looking at your source code, you are not setting it correctly. You should use something like this:
writeRegister8(MMA8451_REG_XYZ_DATA_CFG, 0b000100XX);
where XX depends on the selected full-sacle range.
I hope it helps.
Best regards,
Tomas
PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.