Hi Tomas
Here is the initialization code:
U8 MMA8451OrientationInit(void)
{
U8 temp;
temp = MMA8451ReadReg(CTRL_REG1); //read contents of control register
temp &= ~ACTIVE_MASK; //clear active bit
MMA8451WriteReg(CTRL_REG1, temp); //rewrite CTRL_REG1
temp = MMA8451ReadReg(CTRL_REG1); //read contents of control register
temp &= 0xC7; //clear sample rate bits
temp |= 0xF4; //set 1.56Hz sleep mode sample rate and 1.56Hz System Output Data Rate
MMA8451WriteReg(CTRL_REG1, temp);
MMA8451WriteReg(CTRL_REG2, SMODS1_MASK + SMODS0_MASK + SLPE_MASK + MODS1_MASK + MODS1_MASK); //set low power for sleep and wake modes, enable auto-sleep
MMA8451WriteReg(ASLP_COUNT_REG,0x01); //short return to sleep interval, irrelevant since both modes are 1.56Hz
temp = MMA8451ReadReg(PL_CFG_REG); //read contents of portrait/landscape PL config reg
temp |= PL_EN_MASK; //enable PL detection
MMA8451WriteReg(PL_CFG_REG, temp);
temp = MMA8451ReadReg(PL_BF_ZCOMP_REG); //read Back/Front and Z Compensation Register
temp = 0x44; //default values for now
MMA8451WriteReg(PL_BF_ZCOMP_REG, temp);
temp = MMA8451ReadReg(PL_P_L_THS_REG); //read Portrait/Landscape Threshold and Hysteresis Register
temp = 0x84; //default trip angle of 45 degrees, with +/-14 degree hysterisis
MMA8451WriteReg(PL_P_L_THS_REG, temp);
temp = MMA8451ReadReg(CTRL_REG4); //read out control register 4
temp |= INT_EN_LNDPRT_MASK; //set landscape/portrait interrupt
MMA8451WriteReg(CTRL_REG4, temp);
MMA8451WriteReg(CTRL_REG3, WAKE_LNDPRT_MASK + PP_OD_MASK); //wake on orientation, interrupt polarity active low, open-drain
temp = MMA8451ReadReg(CTRL_REG5); //read out Interrupt Configuration Register
temp |= INT_CFG_LNDPRT_MASK; //set landscape/portrait interrupt to INT1 line (clear for INT2)
MMA8451WriteReg(CTRL_REG5, temp);
MMA8451WriteReg(PL_COUNT_REG, 0x50); //set PL debounce count to 5 samples ( 5 * 0.640 = 3.2 seconds)
temp = MMA8451ReadReg(CTRL_REG1); //read contents of control register
temp |= ACTIVE_MASK; //set active bit
MMA8451WriteReg(CTRL_REG1, temp);
temp = MMA8451ReadReg(PL_STATUS_REG); //return current orientation for testing purposes
temp &= 0x07;
return temp;
}
Rather than measuring total system sleep current(as reported yesterday), I've moved my meter to the VDD/VDDIO supply line of the MMA (eliminating MCU consumption from measurement)
With the ACTIVE bit = 1 --> 33uA
With the ACTIVE bit = 0 --> 3uA
Voltage applied to VDD/VDDIO is 2.75V
Thanks,
Bill