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