AnsweredAssumed Answered

How to write a variable to a MMA8451 register using SDK 2.1?

Question asked by Mark Sample on Jan 28, 2019
Latest reply on Jan 29, 2019 by Mark Sample

Hello, I would like to write a variable value to a threshold register in the MMA8451. Using SDK 2.1. The register write drivers are all set up to  use constants. For example, to write to the CTRL_REG1 you need to do all this:


// Each entry in a RegisterWriteList is composed of: register address, value to write, bit-mask to apply to write (0 enables)
const registerwritelist_t MMA845x_IDLE[] =
    { MMA845x_CTRL_REG1, 0x00, 0x01 },

int8_t MMA845x_Idle(struct PhysicalSensor *sensor, SensorFusionGlobals *sfg)
int32_t status;
if(sensor->isInitialized == F_USING_ACCEL) {
    status = Sensor_I2C_Write(sensor->bus_driver, &sensor->deviceInfo, sensor->addr, MMA845x_IDLE );
    sensor->isInitialized = 0;
    sfg->Accel.isEnabled = false;
} else {
    return status;

And once you had all of that done you would use it by:


global_I2C_status = MMA845x_IDLE(&(sensors[0]), &sfg);


And the above method works well for writing a constant. However, I would like to write a variable. Could someone please be kind enough to help me out. I miss the good old days where something like WriteI2CByte_MMA8451(MMA8451_CTRL_REG1,0x06) would work but I can not find anything simple like that.


Best regards,