# Can someone help me to understand the data sheet of this ADXL345

#### Rscott9399

Joined Jan 13, 2017
51
Here is the data sheet

So here is my problem. No where can i find in the data sheet on how to interpret the data

Im not having any trouble communicating with the device and I'm able to read the x,y,z registers
But i have no idea what the numbers mean.

UNLESS I MISSED IT
which is totally possible but i have not found anything in the data sheet that says

ok if you get this two complement number it = this degree of tilt

I do understand there are different degrees of resolution.
For my application i need the highest resolution with the lowest G requirements

I don't even see in the data sheet what the axis limits of tilt are.
Does it reset when you past 90 degree?

For example if its laying flat on a table should i see a value of zero?

Normally to figure this out i would look at that maximum number allowed in the register and divide it by something to know what the resolution is.
However i don't know what that "something" is by this data sheet?

Anyone have any experience with this device?

#### Rscott9399

Joined Jan 13, 2017
51
thanks at the attempt but nothing in those links helped me to answer my questions

#### ericgibbs

Joined Jan 29, 2010
18,865
thanks at the attempt but nothing in those links helped me to answer my questions
Did you look at the PDF, it shows the calibration method.?

#### Rscott9399

Joined Jan 13, 2017
51
Did you look at the PDF, it shows the calibration method.?
Yes i did. and i have seen the calibration mode many times
What in my question makes you think i need calibration mode?

Im asking specifically how to interpret the data

#### Rscott9399

Joined Jan 13, 2017
51
Thank you!
that was helpful to figure out the title part

Im still trying to interpret my data at the moment.
I have numbers that change and look pretty correct

They range from about 6000 to zero and -6000 to zero depending on how you hold the device.
Thats what I'm getting back from my code.

Here is the issue

on page 32 it talks about the data registers

I have it setup for full resolution at 2g (which in the 2g case is 10 bits)

In the beginning of the data sheet it says that its a twos complement number

If i take those 10 bits and convert from 2s complement i don't get anything that is sensicle

If i take all 16 bits and convert it, i get something that as described above
from about 6000 to 0 and -6000 to zero

The data sheet does a very poor job at telling you if you should take the whole 16 bits or just the 10
Here is the reason for the confusion
The data sheet talks about how that in most cases the left most bits are almost always zero.

So are you suppose to include those during your conversion or leave them out?
In other words, are you suppose to convert just the 10 bits or the whole 16 to find out what the answer is?

like i said above, converting the 16 gives me something sensicle, the 10 does not
the data sheet really leads me to think its just the 10
I may have to call analog

#### shteii01

Joined Feb 19, 2010
4,644
Thank you!
that was helpful to figure out the title part

Im still trying to interpret my data at the moment.
I have numbers that change and look pretty correct

They range from about 6000 to zero and -6000 to zero depending on how you hold the device.
Thats what I'm getting back from my code.

Here is the issue

on page 32 it talks about the data registers

I have it setup for full resolution at 2g (which in the 2g case is 10 bits)

In the beginning of the data sheet it says that its a twos complement number

If i take those 10 bits and convert from 2s complement i don't get anything that is sensicle

If i take all 16 bits and convert it, i get something that as described above
from about 6000 to 0 and -6000 to zero

The data sheet does a very poor job at telling you if you should take the whole 16 bits or just the 10
Here is the reason for the confusion
The data sheet talks about how that in most cases the left most bits are almost always zero.

So are you suppose to include those during your conversion or leave them out?
In other words, are you suppose to convert just the 10 bits or the whole 16 to find out what the answer is?

like i said above, converting the 16 gives me something sensicle, the 10 does not
the data sheet really leads me to think its just the 10
I may have to call analog
The way I am reading it, the device will always send 16 bits to the uC.

#### Rscott9399

Joined Jan 13, 2017
51
Check out AN-1057: http://www.analog.com/media/en/technical-documentation/application-notes/AN-1057.pdf

Looks like in single axis mode it only goes from -90 to +90 degrees. I think if you push it further than that, it will simply report that it reached maximum value, either -90 or +90.

AN-1057 says you need two axes to measure full 360 degrees.
The way I am reading it, the device will always send 16 bits to the uC.

Yes i agree but........
The question is, are you suppose to convert the 16 bits or just the 10 that the data is stored in.
The register always has 16 bits sure.
But per the data sheet, and with my settings, of 2G
Do you convert the full 16 or only the 10 bits
Like i said, when i convert the 10 bits i get garbage
when i convert the 16 i get arbitrary numbers but at least they change like I'm expecting them too

#### ericgibbs

Joined Jan 29, 2010
18,865
What in my question makes you think i need calibration mode?[/QUOTE said:
Im asking specifically how to interpret the data
You said:
But i have no idea what the numbers mean.

To me, that means if you followed the simple example given in the application data, you should be able to understand and interpret the data when using your required resolution.

Do you convert the full 16 or only the 10 bits
Like i said, when i convert the 10 bits i get garbage

The d/s scale factor for 10Bit is +/- 2g is 256LSB/g
Use only the 10 lower order bits of the 16 bit word. Mask Off the upper bits.

Remember its a 2s complement value.

Do you understand 2s comp.?
http://www.convertforfree.com/twos-complement-calculator/
Eric

EDIT:
Post the 16 bit value for a Zero reading.

#### Attachments

• 22.6 KB Views: 5
Last edited:

#### KeepItSimpleStupid

Joined Mar 4, 2014
5,088
I'm guessing based on what's in this discussion, not the datasheet.

If you have a 10 bit 2's complement number, to convert it to 16 bit 2's complement number, you "sign extend" the 12 bit number.

What this means is, you take bit 9, the sign bit, if the bits are labeled starting at 0 with the lsb having a value of 1 and replicate it to bits 10,11,12,13, 14 and 15.

yea, you can replace it with pseudocode:
read 16 bit two-s complement # where it's a 2's complement 10 bit number.
If bit9=1 then value=value OR (bits 10-15 set as 1)
Ifbit9=0 then value = value AND (bits 9 to 0 set as 1)

You have to watch what your doing. It might be easier to read as an unsigned integer, sign extend it and then typecast the result to a 16 bit 2's complement value.

#### Rscott9399

Joined Jan 13, 2017
51
You said:
But i have no idea what the numbers mean.

To me, that means if you followed the simple example given in the application data, you should be able to understand and interpret the data when using your required resolution.

What example in the data sheet because mine has none

#### Rscott9399

Joined Jan 13, 2017
51
You said:
But i have no idea what the numbers mean.

To me, that means if you followed the simple example given in the application data, you should be able to understand and interpret the data when using your required resolution.

Do you convert the full 16 or only the 10 bits
Like i said, when i convert the 10 bits i get garbage

The d/s scale factor for 10Bit is +/- 2g is 256LSB/g
Use only the 10 lower order bits of the 16 bit word. Mask Off the upper bits.

Remember its a 2s complement value.

Do you understand 2s comp.?
http://www.convertforfree.com/twos-complement-calculator/
Eric

EDIT:
Post the 16 bit value for a Zero reading.
As i have said previously
Im using LEFT justification for this

I have masked off the lower bits and I'm only converting 10 bits from the MSB to the LSB

So if you look at the 2 registers together
Im converting
bit 16 - through bit 7

And as i have said i get garage

And yes i understand twos complement
Not that it would matter given I'm using a function that takes a binary number and converts it for me anyway

So just to be clear
Currently I'm doing the following

I reading in the two registers.
When i do the read, the function I'm using to complete the read is giving me a decimal number

So im converting the decimal to binary and placing the two binary numbers next to each other correctly so for example

X1 ---------- X0
D7,D6,D5,D4,D3,D2,D1,D0 D7,D6,D5,D4,D3,D2,D1,D0

Then I'm taking the left most 10 bits because i have set the left justification

sooo

D16,D15,D14,D13,D12,D11,D10,D9,D8,D7

Im taking the binary representation of those 10 bits and converting that alone FROM 2,s complement to a Decimal number

I get garbage back

If i convert the whole thing

D16,D15,D14,D13,D12,D11,D10,D9,D8,D7,D6,D5,D4,D3,D2,D1,D0

I get a numbers that change from 16,000 to zero and if i tilt the thing the other way i get numbers that of from -16000 to zero

Also just to be complete the device is set to 100 Hz

#### ericgibbs

Joined Jan 29, 2010
18,865
hi,
Have you tried right justification of the 10 bits within the 16 bit Word.?
Test Bit 9 for polarity, IF '0' the value is positive,
IF '1' it is a negative value, so subtract 0x3FF from the value and add 1 to the result.

Reading from the d/s that for +/-2g, it is 256 decimal [100H] for each 1g, dividing should give the 'g' value.

This is the method I use for 10 bit extraction from a 16 bit Word.

E

#### Rscott9399

Joined Jan 13, 2017
51
hi,
Have you tried right justification of the 10 bits within the 16 bit Word.?
Test Bit 9 for polarity, IF '0' the value is positive,
IF '1' it is a negative value, so subtract 0x3FF from the value and add 1 to the result.

Reading from the d/s that for +/-2g, it is 256 decimal [100H] for each 1g, dividing should give the 'g' value.

This is the method I use for 10 bit extraction from a 16 bit Word.

E
I just talked to analog
they don't even know the answer

#### ericgibbs

Joined Jan 29, 2010
18,865
Oh Dear, that must fill you with confidence.

Can you post the actual '0' and '1' bit pattern of one axis, with the sensor laying flat and level in that axis.
Lets see if I can help decoding it.

Eric

#### KeepItSimpleStupid

Joined Mar 4, 2014
5,088
Suppose I had an 8 bit 2's complement number and a 4 bit 2's complement #

an 8 bit -1decimal is 11111111 and a 4 bit -1 is 1111
If you sign extend the 4 bit -1, you get 11111111 or -1

Now suppose you had an 4 bit 2's complement 7 or 0111, and you sign extend it, you get
00000111 or 7 in 2's complement 8 bit notation.

If you really have 10 bit 2's complement, the positive numbers are easy and make sense, but the negative ones won;t make sense without the sign extension.

That's just the easy way to do it.

#### Rscott9399

Joined Jan 13, 2017
51
Suppose I had an 8 bit 2's complement number and a 4 bit 2's complement #

an 8 bit -1decimal is 11111111 and a 4 bit -1 is 1111
If you sign extend the 4 bit -1, you get 11111111 or -1

Now suppose you had an 4 bit 2's complement 7 or 0111, and you sign extend it, you get
00000111 or 7 in 2's complement 8 bit notation.

If you really have 10 bit 2's complement, the positive numbers are easy and make sense, but the negative ones won;t make sense without the sign extension.

That's just the easy way to do it.
Sure i understand that

Here is the issue, Im not using my own function to decode the 2compliment,
The language I'm using has a built in function for it. So all I'm doing is using the built in function and sending the function either 10 or 16 bits

With it flat on the desk this is what the 16 bit sequence shows

16 bit version

0000000011000000

10 bit version

0000001100

Converting it from twos complement i get

-36 for 10 bits

and

144 for 16 bits

So again you see the issue is, how do you interpret the data.

By way of the data sheet it looks as if the LSB should be in bit 7
assuming you call the MSB Bit 16 aka 10 bits
Just terminology

However, if i move the thing around, the 10 bit representation hardly changes regardless of how i move the sensor
It seems to stay around -36 -40 -47 or so

If i convert the whole 16 bits as shown above when it was equal to 144

If its flat on the table its around zero and if i tilt 90 degrees one way i get positive 16,000
and if i tilt 90 degrees the other way i get negative -16000

Thanks for your continued help to everyone

#### Rscott9399

Joined Jan 13, 2017
51
Oh Dear, that must fill you with confidence.

Can you post the actual '0' and '1' bit pattern of one axis, with the sensor laying flat and level in that axis.
Lets see if I can help decoding it.

Eric
Hi eric see post #18 for actual sequence

#### KeepItSimpleStupid

Joined Mar 4, 2014
5,088
It's basicaly l reversed for some reason which could be big endian or little endian miss match;

See: https://en.wikipedia.org/wiki/Endianness

None of those conversions are right.

Read the values as 16 bit unsigned integer and print in decimal and binary and see what you get?