Using SPI to communicate with an ADXL345 acceleration sensor

Hello guys,

I need your help for trouble shooting my code. I rewrote the code from an example posted as an spark fun tutorial.
The problem is, that I’m always getting a value of 255 for every axis.

As setup I use an Arduino Due with the SparkFun breakout board ADXL345.

I linked my source code and the output of the serial monitor below.

Maybe you can find the mistake.

Best regards,

Niko

ADXL345_Basic.ino (4.3 KB)

As setup I use an Arduino Due with the SparkFun breakout board ADXL345.

How did you connect the two? The SPI pins are not on pins 11, 12 and 13 on the Due!

I connected SDA to 20, SCL to 21, CS to 10 and SDO to 12. As Vcc I use the 3,3 V voltage supply.

Thanks for your answer!

Niko

I connected SDA to 20, SCL to 21, CS to 10 and SDO to 12. As Vcc I use the 3,3 V voltage supply.

This is neither an SPI nor an I2C connection!

If you connect SDA to 20 and SCL to 21 you can use the sensor over I2C. If you want to use SPI, the pin labeled SDA on the board gets MOSI, SCL get SCKL, SDO gets MISO.

The SPI pins on the Due are on the ICSP header, in the middle between pin 0 and A5. This page shows the pinout of the connector (although it's for the UNO on that page, the pinout is always the same).