user26375: I'm having trouble getting information off the accelerometer I'm trying to use. What code should I use to read the X,Y, and Z axis?  I've read the data sheet but I don't have any experience with SPI communication.  
Spec sheet

user13432: The basic SPI operations looks like this. First read single register:
uint8_t readRegister(int index)
{
  digitalWrite(CS, LOW);
  SPI.beginTransaction(SPI_SETTING);
  SPI.transfer(READ | index);
  uint8_t res = SPI.transfer(0);
  SPI.endTransaction();
  digitalWrite(CS, HIGH);
  return (res);
}

And second write single register:
void writeRegister(int index, uint8_t data)
{
  digitalWrite(CS, LOW);
  SPI.beginTransaction(SPI_SETTING);
  SPI.transfer(WRITE | index);
  SPI.transfer(data);
  SPI.endTransaction();
  digitalWrite(CS, HIGH);
}

Some more details:
const uint8_t WRITE = 0x00;
const uint8_t READ = 0x80;

It is also possible to read/write a sequence of registers by providing the register index with the MS set. This will auto-increment the register index. 
SPI_SETTING is left as an exercise (to be updated).  
Cheers!

26375: <p>I'm having trouble getting information off the accelerometer I'm trying to use. What code should I use to read the X,Y, and Z axis?  I've read the data sheet but I don't have any experience with SPI communication.  </p>

<p><a href="http://www.st.com/content/ccc/resource/technical/document/datasheet/6e/c2/95/d9/3a/3f/4f/cb/DM00162193.pdf/files/DM00162193.pdf/jcr:content/translations/en.DM00162193.pdf" rel="nofollow">Spec sheet</a></p>
 13432: <p>The basic <a href="https://www.arduino.cc/en/Reference/SPI" rel="nofollow">SPI</a> operations looks like this. First read single register:</p>

<pre><code>uint8_t readRegister(int index)
{
  digitalWrite(CS, LOW);
  SPI.beginTransaction(SPI_SETTING);
  SPI.transfer(READ | index);
  uint8_t res = SPI.transfer(0);
  SPI.endTransaction();
  digitalWrite(CS, HIGH);
  return (res);
}
</code></pre>

<p>And second write single register:</p>

<pre><code>void writeRegister(int index, uint8_t data)
{
  digitalWrite(CS, LOW);
  SPI.beginTransaction(SPI_SETTING);
  SPI.transfer(WRITE | index);
  SPI.transfer(data);
  SPI.endTransaction();
  digitalWrite(CS, HIGH);
}
</code></pre>

<p>Some more details:</p>

<pre><code>const uint8_t WRITE = 0x00;
const uint8_t READ = 0x80;
</code></pre>

<p>It is also possible to read/write a sequence of registers by providing the register index with the MS set. This will auto-increment the register index. </p>

<p>SPI_SETTING is left as an exercise (to be updated).  </p>

<p>Cheers!</p>
