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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
1,672 Views
marks
Contributor IV

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 },
    __END_WRITE_DATA__
};

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 SENSOR_ERROR_INIT;
}
    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,

Mark

0 Kudos
1 Solution
1,600 Views
marks
Contributor IV

Never mind. I ended up just defining 5 constants as thresholds and used those.

Thanks for reading!

Mark

View solution in original post

0 Kudos
1 Reply
1,601 Views
marks
Contributor IV

Never mind. I ended up just defining 5 constants as thresholds and used those.

Thanks for reading!

Mark

0 Kudos
%3CLINGO-SUB%20id%3D%22lingo-sub-868175%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHow%20to%20write%20a%20variable%20to%20a%20MMA8451%20register%20using%20SDK%202.1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-868175%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%20I%20would%20like%20to%20write%20a%20variable%20value%20to%20a%20threshold%20register%20in%20the%20MMA8451.%20Using%20SDK%202.1.%20The%20register%20write%20drivers%20are%20all%20set%20up%20to%26nbsp%3B%20use%20constants.%20For%20example%2C%20to%20write%20to%20the%20CTRL_REG1%20you%20need%20to%20do%20all%20this%3A%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%2F%2F%20Each%20entry%20in%20a%20RegisterWriteList%20is%20composed%20of%3A%20register%20address%2C%20value%20to%20write%2C%20bit-mask%20to%20apply%20to%20write%20(0%20enables)%3CBR%20%2F%3Econst%20registerwritelist_t%20MMA845x_IDLE%5B%5D%20%3D%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%7B%20MMA845x_CTRL_REG1%2C%200x00%2C%200x01%20%7D%2C%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20__END_WRITE_DATA__%3CBR%20%2F%3E%7D%3B%3C%2FP%3E%3CP%3Eint8_t%20MMA845x_Idle(struct%20PhysicalSensor%20*sensor%2C%20SensorFusionGlobals%20*sfg)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%20int32_t%20status%3B%3CBR%20%2F%3E%20if(sensor-%26gt%3BisInitialized%20%3D%3D%20F_USING_ACCEL)%20%7B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20status%20%3D%20Sensor_I2C_Write(sensor-%26gt%3Bbus_driver%2C%20%26amp%3Bsensor-%26gt%3BdeviceInfo%2C%20sensor-%26gt%3Baddr%2C%20MMA845x_IDLE%20)%3B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20sensor-%26gt%3BisInitialized%20%3D%200%3B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20sfg-%26gt%3BAccel.isEnabled%20%3D%20false%3B%3CBR%20%2F%3E%20%7D%20else%20%7B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20return%20SENSOR_ERROR_INIT%3B%3CBR%20%2F%3E%20%7D%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20return%20status%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3EAnd%20once%20you%20had%20all%20of%20that%20done%20you%20would%20use%20it%20by%3A%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3Eglobal_I2C_status%20%3D%20MMA845x_IDLE(%26amp%3B(sensors%5B0%5D)%2C%20%26amp%3Bsfg)%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EAnd%20the%20above%20method%20works%20well%20for%20writing%20a%20constant.%20However%2C%20I%20would%20like%20to%20write%20a%20variable.%20Could%20someone%20please%20be%20kind%20enough%20to%20help%20me%20out.%20I%20miss%20the%20good%20old%20days%20where%20something%20like%26nbsp%3BWriteI2CByte_MMA8451(MMA8451_CTRL_REG1%2C0x06)%20would%20work%20but%20I%20can%20not%20find%20anything%20simple%20like%20that.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EBest%20regards%2C%3C%2FP%3E%3CP%3EMark%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-868176%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20How%20to%20write%20a%20variable%20to%20a%20MMA8451%20register%20using%20SDK%202.1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-868176%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ENever%20mind.%20I%20ended%20up%20just%20defining%205%20constants%20as%20thresholds%20and%20used%20those.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThanks%20for%20reading!%3C%2FP%3E%3CP%3EMark%3C%2FP%3E%3C%2FLINGO-BODY%3E