My project needs a master MSP432 to configure a MMA8451Q accelerometer, the slave, with I2C bus, but I do not know how. In other words, I need a method able to write data into a given register(s) of the slave. There is such a method on the Internet (https://community.freescale.com/docs/DOC-98836 ) for FRDM-KL25Z platform. Here is the program:
void Accelerometer_Init (void)
{
unsigned char reg_val = 0;
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x40); // Reset all registers to POR values
do // Wait for the RST bit to clear
{
reg_val = I2C_ReadRegister(MMA845x_I2C_ADDRESS, CTRL_REG2) & 0x40;
} while (reg_val);
I2C_WriteRegister(MMA845x_I2C_ADDRESS, XYZ_DATA_CFG_REG, 0x00); // +/-2g range -> 1g = 16384/4 = 4096 counts
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG2, 0x02); // High Resolution mode
I2C_WriteRegister(MMA845x_I2C_ADDRESS, CTRL_REG1, 0x3D); // ODR = 1.56Hz, Reduced noise, Active mode
}
Any help will be greatly appreciated.
Thank you very much.