Hello All,
I am using MMA8452QR1 with STM32, and for communication I2C protocol is using.
I am trying to get the motion detection of accelerometer
But while writing an register FF_MT_CFG (0x15) = 0xD8 ;
it did not write that value but instead of that (0x50) value written on that register.
the configuration of register for MMA8452Q is as follows,
CTRL_REG (0x2A) = 0x01;
FF_MT_COUNT(0x18) = 0x02;
XYZ_DATA_CFG (0x0E) = 0x00;
FF_MT_THS (0x17) = 0x85;
Code is as Follows,
#define ACC_ADD 0x1D
#define ACC_MOD_REG 0x2A
#define ACC_DATA_CONFIG_REG 0x0E
#define ACC_MOT_CFG_REG 0x15
#define ACC_MOT_DET_STATUS 0x16
#define ACC_DATA_REG_X 0x01
#define ACC_DATA_REG_Y 0x03
#define ACC_DATA_REG_Z 0x05
#define ACC_MOT_DEBOUNCE_COUNT 0x18
#define ACC_MOT_THS 0x17
extern I2C_HandleTypeDef hi2c1 ;
/*
@brief receives data from accelerometer of acceleration co-ordinate & motion detection
@paraacc_axis_data_t holds acceleration data of X-Y-Z axis
*/
void acc_init()
{
uint8_t buf[5] = {0} ;
uint8_t bufTemp[5] = {0};
buf[0]=0x01;
if (HAL_I2C_Mem_Write(&hi2c1, ACC_ADD <<1, ACC_MOD_REG, I2C_MEMADD_SIZE_8BIT, &buf[0], 1, 10) == HAL_OK) // active mode select
{
HAL_Delay(100);
buf[0] = 0;
HAL_I2C_Mem_Read(&hi2c1, ACC_ADD <<1 , ACC_MOD_REG , I2C_MEMADD_SIZE_8BIT, buf, 1 , 10);
}
buf[0]=0xD8;
if (HAL_I2C_Mem_Write(&hi2c1, ACC_ADD <<1, ACC_MOT_CFG_REG, I2C_MEMADD_SIZE_8BIT,&buf[0] , 1, 10) == HAL_OK) // config of motion detection
{
buf[0] = 0;
if(HAL_I2C_Mem_Read(&hi2c1, ACC_ADD <<1 , ACC_MOT_CFG_REG , I2C_MEMADD_SIZE_8BIT, bufTemp, 1 , 10) == HAL_OK)
{
buf[0] = 0;
}
}
buf[0]=0x02;
if (HAL_I2C_Mem_Write(&hi2c1, ACC_ADD << 1 , ACC_MOT_DEBOUNCE_COUNT, I2C_MEMADD_SIZE_8BIT, &buf[0], 1, 10) == HAL_OK) //
{
buf[0] = 0;
HAL_I2C_Mem_Read(&hi2c1, ACC_ADD <<1 , ACC_MOT_DEBOUNCE_COUNT , I2C_MEMADD_SIZE_8BIT, buf, 1 , 10);
}
buf[0]=0x00;
if (HAL_I2C_Mem_Write(&hi2c1, ACC_ADD << 1 , ACC_DATA_CONFIG_REG, I2C_MEMADD_SIZE_8BIT, &buf[0], 1, 10) == HAL_OK) //
{
buf[0] = 0;
HAL_I2C_Mem_Read(&hi2c1, ACC_ADD <<1 , ACC_DATA_CONFIG_REG , I2C_MEMADD_SIZE_8BIT, buf, 1 , 10);
}
buf[0]=0x85;
if (HAL_I2C_Mem_Write(&hi2c1, ACC_ADD << 1 , ACC_MOT_THS, I2C_MEMADD_SIZE_8BIT, &buf[0], 1, 10) == HAL_OK) //
{
buf[0] = 0;
HAL_I2C_Mem_Read(&hi2c1, ACC_ADD <<1 , ACC_MOT_THS , I2C_MEMADD_SIZE_8BIT, buf, 1 , 10);
}
Regards,
Pranal .