Hello Federico,
Thank you for writing.
In your case, I highly recommend you to use the MMA9553. The MMA9553 is an intelligent motion sensing pedometer, and is much more easy to make a pedometer with this IC than with the MMA8451.
This is how you can configure the MMA9553.
void MMA9553L_Init(void){
pedometer_config();
pedometer_enable();
pedometer_active();
pedometer_wakeup();
}
The pedometer_config function, is the following.
void pedometer_config(void){
unsigned char MBx[20]= {0x15, 0x20, 0x00, 0x10,
SLEEP_MIN_MSB, SLEEP_MIN_LSB,
SLEEP_MAX_MSB, SLEEP_MAX_LSB,
SLEEP_COUNT_THR_MSB, SLEEP_COUNT_THR_LSB,
CONFIG, STEP_LENGTH,
HEIGHT, WEIGHT, FILTER_STEP,
MALE_FILTER_TIME, STEP_PERIOD,
STEP_COALESCE, ACT_COUNT_THR_MSB,
ACT_COUNT_THR_LSB};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
The pedometer_enable function, is the following.
void pedometer_enable(void){
unsigned char MBx[5]={0x17, 0x20, 0x05, 0x01, 0x00};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
The pedometer_active function, is the following.
void pedometer_active(void){
unsigned char MBx[5]={0x15, 0x20, 0x06, 0x01, 0x80};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
The pedometer_wakeup function, is the following.
void pedometer_wakeup(void){
unsigned char MBx[5]={0x12, 0x20, 0x06, 0x01, 0x00};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
This is how you could read the steps.
void Read_Step(void)
{
pedometer_cmd_readstatus();
I2C_ReadMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, 2, MBx);
if (MBx[1]==0x80){
I2C_ReadMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
StepCount = ((short) (MBx[6]<<8 | MBx[7]));
}
}
The pedometer_cmd_readstatus function is the following.
void pedometer_cmd_readstatus(void){
unsigned char MBx[4]={0x15, 0x30, 0x00, 0x0C};
I2C_WriteMultiRegisters(MMA9553L_ADDRESS, MMA9553_SUB_ADDR, sizeof(MBx), MBx);
}
Finally, these are the macros that you are going to need.
#define MMA9553L_ADDRESS 0x4C
#define MMA9553_SUB_ADDR 0x00
#define SLEEP_MIN_MSB 0x0C
#define SLEEP_MIN_LSB 0xE0
#define SLEEP_MAX_MSB 0x13
#define SLEEP_MAX_LSB 0x20
#define SLEEP_COUNT_THR_MSB 0x00
#define SLEEP_COUNT_THR_LSB 0x96
#define CONFIG 0x60
#define STEP_LENGTH 0x50
#define HEIGHT 0xAA
#define WEIGHT 0x44
#define FILTER_STEP 0x04
#define MALE_FILTER_TIME 0x03
#define STEP_PERIOD 0x05
#define STEP_COALESCE 0x01
#define ACT_COUNT_THR_MSB 0x00
#define ACT_COUNT_THR_LSB 0x00
I hope this information will be useful for you.
Best Regards,
Diego