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

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

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

1,858 Views
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,

Labels (1)
0 Kudos
1 Reply

693 Views
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 Kudos