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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

ソリューションへジャンプ
1,401件の閲覧回数
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 件の賞賛
返信
1 解決策
1,329件の閲覧回数
marks
Contributor IV

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

Thanks for reading!

Mark

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
1,330件の閲覧回数
marks
Contributor IV

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

Thanks for reading!

Mark

0 件の賞賛
返信