View Single Post
  #7   Spotlight this post!  
Unread 03-02-2010, 11:02
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by charrisTTI View Post
Code worked fine in my testing.

If you look at the getAxis method you will see that I am doing a 2-byte read when I get the data (2 consecutive registers in one read). This insures that the data does not get corrupted. If two individual 1-byte reads were performed there is a chance that in between the first and second read the data could change. This would result in first read getting the low byte of the prior value and second read getting the high byte of the subsequent value. Putting the two together again could create some really funny numbers. See page 18 of the ADXL345 data sheet "Register 0x32 to Register 0x37" section for more information about this.

Here is an example of the problem: prior value is 0x0100 subsequent value is 0x00ff, a 1 bit change. Two single byte reads would read low byte 0x00 and high byte 0x00 giving 0x0000. No where near close to what the sensor is actually reading.
Makes sense. Thanks for the code! Much easier than writing my own.
Reply With Quote