How to read MMA8451 values having only i2c_read and i2c_write functions?

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

How to read MMA8451 values having only i2c_read and i2c_write functions?

2,134件の閲覧回数
edelm
Contributor III

We got a boad with BLE113 Bluetooth chip onboard and mma8451Q sensor.

The board has SDK and in the SDK there is only i2c read and write functions.

Can you please give an example of how to read full X Y Z values using only read and write functions?

Please, we have tried so many, but we cannot get any adequate result.

enum {

    MMA845X_STATUS = 0x00,

    MMA845X_OUT_X_MSB,

    MMA845X_OUT_X_LSB,

    MMA845X_OUT_Y_MSB,

    MMA845X_OUT_Y_LSB,

    MMA845X_OUT_Z_MSB,

    MMA845X_OUT_Z_LSB,

dim tmp(6)

dim acc(6)

what we do is we activate the accelerometer:

#start accelerometer

    acc(0:1)=$2a #CTRL_REG1 address

    acc(1:1)=3  #enable accelerometer, set fast mode

    call hardware_i2c_write($38,1,2,acc(0:2))

then we read the values

    #read acceleration

    acc(0:1)=1

    call hardware_i2c_write($38,0,1,acc(0:1))#set address

    call hardware_i2c_read($38,1,6)(result,data_len,tmp(0))#read data

This suppose to read the values high and low bytes but it does not work this way.

The return value is 3 bytes only,

ラベル(1)
0 件の賞賛
返信
1 返信

969件の閲覧回数
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi,


If you intend to read full 14-bit data from registers 0x01 to 0x06, the F_READ bit in the CTRL_REG1 register (0x2A) needs to be cleared. Looking at your souce code, you have this bit set (= fast mode enabled), which means that the auto increment counter skips over the LSB data registers (0x02, 0x04, 0x06), resulting in 8-bit results only.

You might find useful my example code where I also demonstrate how to convert the raw data from accelerometer registers 0x01 – 0x06 to signed 14-bit values as well as real values in g’s.

I hope it helps.

Regards,

Tomas


PS: If my answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.

0 件の賞賛
返信