Arduino SPI library communication with ADXL 345

Hi ,

It try to use a Arduino with a ADXL 345 Sensor to communicat over SPI Bus. I use the SPI-Library and read the 0x33 (x sensor from the ADL 345) but nothing happend. The wiring is in my opinion correct.

Can somebody give my an example or a advice how i can resolve the problem ?

Here my code:

#include "Spi.h"
#define SCK 13
#define SO 12
#define SI 11
#define SS 10  
 
//opcodes
 
#define RESET 2
#define READ  0x03
#define WRITE 0x02
 
byte clr;
byte X;
 
void setup()
 
{
 
  Serial.begin(9600); // SPI INITIALIZATION  
 
  /* SPI interrupt disabled, SPI enabled, sends MSB first, MC is master,  
   clock polarity=0, clock phase=0(hence mode 0), SPI speed = 4MHz(fastest)*/
 
  SPCR = ( (1<<SPE)|(1<<MSTR)); // 0101 0000
  clr=SPSR;                                
  clr=SPDR;
  digitalWrite(RESET,LOW); 
  delay(10);
  digitalWrite(RESET,HIGH);
  delay(10);
}
 
 
void loop()
 
{
 
  delay(10);
  digitalWrite(SS,LOW);
  Spi.transfer(READ);
  Spi.transfer(0x33);// CANSTAT address of TXB0
  X=Spi.transfer(0xFF);
  digitalWrite(SS,HIGH);
  delay(10);
  Serial.print("X: ");
  Serial.println(X, HEX);
  delay(200);
 
}

Thx,
Arek

Hey Arek. I'm doing the exact same thing as you (arduino, ADXL 345, SPI) so lets compare notes. First of all, I think you need to init the POWER_CTL register first. You should look at Google Code Archive - Long-term storage for Google Code Project Hosting.

that above link is an I2C lib, but here is some code that might work for SPI. I'm still struggling to get it to work. http://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345-talktest.zip

edit: had wrong link