ADXL362 with Arduino Due

Hey,

I want to read sensor data from an ADXL362 (http://www.watterott.com/de/Triple-Axis-Accelerometer-Breakout-ADXL362) accelerometer with an Arduino Due using SPI.

The whole situation is a little confusing to me, as I'm new to SPI. I'm trying to use the ADXL362 by annem library, however I must be doing something wrong.

I connected the MISO, MOSI and SCK pins next to the AMX3X8E to the corresponding pins on my breakout board. Additionally I connected the 3.3V supply pin (next to IO Ref and Reset) and the GND next to pin 53/52. The example programs in the ADXL362 library use pin 10 for SS/CS. However I decided that i want to use pin 52 as it is closer to my pin header. That configuration didn't work. Then I changed CS/SS to pin 10, which also doesn't work.

Something is confusing me: there seems to be no clock signal on the SCK pin. I connected an oscilloscope to it and cannot detect anything, the pin seems to be high all the time.

I figured that there must be something wrong with the SPI setup. However the documentation isn't helping. The extended SPI documentation for the Due says, that the SPI.begin() command needs the SS pin as a parameter. I changed the library .cpp file accordingly, but then the sketch does not work at all.

I'm running out of ideas. Can anyone give me a hint?

Best regards

The library is written for a standard Arduino and is not directly compatible with the Due. The call to SPI.begin() has to be changed to SPI.begin(10) to get the behavior you expect to have (define the SS pin, defaults to SS03 which is not externally connected on the Due, see SPI.cpp/SPI.h for details).

I disconnected the sensor and created a simple sketch, just using the SPI.begin() command without any parameter. Now I can see the clock and MOSI signal.

Maybe I have to debug the library step by step... :~

*edit: SPI.begin(10) does not produce a clock signal.

I'm beginning to suspect, that my ADXL362 is damaged. I stripped some functions from the library and the sketch seems to work. At least I'm getting signals on the oscilloscope and zeros instead of -1. When the accelerometer is moving, some wild -1 appear. This may be due to loose contacts?!

#include <SPI.h>
#include <Arduino.h>

int16_t slaveSelectPin = 52;

void setup() {
  // put your setup code here, to run once:
  pinMode(slaveSelectPin, OUTPUT);
  SPI.begin();
  //SPI.setClockDivider(10); 
  SPI.setDataMode(SPI_MODE0);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  SPI.transfer(0x0A);
  int16_t xdata;
  xdata = readXData();
  Serial.println(xdata); 
  delay(50);
}

int16_t readXData(){
	int16_t XDATA = SPIreadTwoRegisters(0x0E);
	return XDATA;
}

int16_t SPIreadTwoRegisters(byte regAddress){
	int16_t twoRegValue = 0;
  
	digitalWrite(slaveSelectPin, LOW);
	SPI.transfer(0x0B);  // read instruction
	SPI.transfer(regAddress);  
	twoRegValue = SPI.transfer(0x00);
	twoRegValue = twoRegValue + (SPI.transfer(0x00) << 8);
	digitalWrite(slaveSelectPin, HIGH);
	return twoRegValue;
}

Have you tried SPI.begin(52);? See http://arduino.cc/en/Reference/DueExtendedSPI

What should the

SPI.transfer(0x0A)

do? You're sending data without pulling the CS line low?

If you're using the interface above the hardware can control the CS line for you but otherwise you have to keep track of it yourself.