Problem occurred when interfacing arduino due board and adxl345 via I2C protocol

Hello,

I am new to the Forum, Arduino and Electronics in general, although for whatever reason my only "cum laude" while studying my degree was in electronics... :slight_smile:

Now i have a problem when i am interfacing arduino due board and adxl345 accelerometer. Being at the bottom of the learning curve, I opted for the Due and ADXL345 accelerometers, connected via SPI. I know now that it was not the best of the decissions, but once taken I have to make it work, even if it is only one accelerometer. As a backup plan I have ordered 4 analog ADXL335 that should make the trick.

Unfortunately, I am having issues with the SPI connection to the DUE. I can access the accelerometer data via I2C, but when trying to get to it through SPI i get nothing, only -1,-1,-1 but i got the device ID(for adxl345 is 0xE5 means in decimal is 229). I started trying to adapt the existing sketch from sparkfun for the due ADXL345 Hookup Guide - SparkFun Learn, but as it did not work I tried my low level implementation.

When i upload this code attached at below in arduino due board, it gives values of x, y, z are -1, -1, -1 respectively. When i changed the position of adxl345, values can not be changed. It gives constant values are -1, -1, -1. So how i can changed these values when i chenged the position of adxl345.

Please give response/answer as soon as possible. Give a perfect code for spi mode and interfacing image of arduino due and adxl345 and showing results which you can get.

spi.txt (4.06 KB)

You did read on the datasheet

The CS pin should always be tied high to
V DD I/O or be driven by an external controller because there is no
default mode if the CS pin is left unconnected. Therefore, not
taking these precautions may result in an inability to communicate
with the part.

To ieee488 from aedford1551

Saw you response to this issue " Problem occurred when Arduino due board and ad1345 via I2C protocol "

Is it possible that my issue may be similar Communication Error - Srduino Mega 2560 STK500v2 to T100 BlueESC goingthru I2C protocol
I posted this March 15, 2016 6:40pm