10 years, 6 months ago.

MMA8452 12bit values only come out as 8 bit

Hi Anyone who is expert in accelerometers! :-/

I've written a driver for the MMA8452 - which is in keeping with many of the drivers on the site.

http://mbed.org/users/nherriot/code/MMA8452_test/admin/

http://mbed.org/users/nherriot/code/MMA8452/

However I'm pulling my hair out trying to figure out why the accelerometer only seems to change x,y and z values in the LSB bit of the 12 bit (2 register) range!

The technical data sheet says that the device provides 12 bit values in 2s compliment taking up 2 octets (2 register values). The range for register values are 0x01 to 0x06 where 0x01-0x02 = x 0x03-0x04 = y and 0x05 - 0x6 = z.

The first 4 bits of the LSB are not used - so I would expect to see 4 bits from the LSB and 8 bits from the MSB being used to show accelerometer values. I don't! I only ever see 0xFF for the MSB values for x,y and z. Only the LSB value changes as I rotate the accelerometer.

I've also checked the CTRL_Reg1 - where you can set the system into 'Fast Read' mode. This is not set either - hence still default of '0' for bit 1.

Is there something else that needs to be setup to make the system use 2 octets for reporting x,y and z values?

Kind regards, Nicholas.

Question relating to:

1 Answer

10 years, 6 months ago.

According to the datasheet is should receive a repeated start after the register write. Change:

m_i2c.write(mcu_address,xaxis_register,1)

To:

m_i2c.write(mcu_address,xaxis_register,1,true)

And hopefully that helps.

According to the datasheet the internal address pointer it uses to read the correct address is reset once it receives a stop condition. If that is the case you will read from address 0, the status register. Considering its bits are one when there is new data/old data is overwritten, it will be 0xFF if you don't read very fast from the device. So then your first read is indeed 0xFF, and second read is X-axis data, which will change.

Accepted Answer