Struggling to get digital SPI accelerometer working (ADXL363)

Hi there,

I’m quite new to using Arduinos and have to use one for my research project, which currently involves implementing a digital acceleromter. I’ve never used digital sensors before and am a little confused as to how to start reading data. From what I can see from looking around, the accelerometer I’m using (ADXL363 - datasheet here) communicates using the SPI protocol - I am not familiar with this and am unsure as to where to go next to get it working. I am using an Arduino Due.

If anyone could lend me a hand that would be greatly appreciated!

Thanks in anticipation,


This should read the six axis registers byte values and combine these into three integer values. It uses the standard SPI library. You can use the Due extended stuff, but this keeps it compatible with other Arduino boards. Use D8 as the ADXL slave select pin.

You need not adjust any of the SPI settings. This IC uses all the default values (MSBFIRST, MODE0, 4MHz).

#include <SPI.h>

#define slaveSelect 8

byte xLow, xHi, yLow, yHi, zLow, zHi;
int xVal, yVal, zVal;

void setup() {
  pinMode(slaveSelect, OUTPUT);
  digitalWrite(slaveSelect, HIGH);


void loop() {


  xVal = xHi << 8 | xLow;
  yVal = yHi << 8 | yLow;
  zVal = zHi << 8 | zLow;

  Serial.print(", ");
  Serial.print(", ");

void readRegisters() {

  // activate ADXL SPI
  digitalWrite(slaveSelect, LOW);

  // transfer a read command

  // transfer the start register address. 0x0E is the start of the accelerometer registers

  // get all the registers
  xLow = SPI.transfer(0x00);
  xHi = SPI.transfer(0x00);
  yLow = SPI.transfer(0x00);
  yHi = SPI.transfer(0x00);
  zLow = SPI.transfer(0x00);
  zHi = SPI.transfer(0x00);

  // disable the ADXL SPI
  digitalWrite(slaveSelect, HIGH);

No guarantees. I don’t have this model accelerometer to test this with.

Hi there,

Thanks very much for your help - I've tried running this code with MISO, MOSI, SCK and SS plugged in 50, 51, 53 and 8 respectively, but the serial monitor just outputs '65335, 65335, 65335' repeatedly. I don't suppose you know what's causing this? I tried changing the registry read code to the following:

  xLow = SPI.transfer(slaveSelect,0x00);
  xHi = SPI.transfer(slaveSelect,0x00);
  yLow = SPI.transfer(slaveSelect,0x00);
  yHi = SPI.transfer(slaveSelect,0x00);
  zLow = SPI.transfer(slaveSelect,0x00);
  zHi = SPI.transfer(slaveSelect,0x00);

This changed the output to '255, 255, 255' which still isn't particularly helpful. Any help would be greatly appreciated!

Best wishes,


I don't have a Due yet, but hope to purchase one soon to upgrade my Mega.

The Due product page says the SPI pins are on the ICSP connector. It does not mention anything about D50 to D53.

edit: The code I posted will use the ADXL default stuff. 2G, 100Hz update.

edit2: The Due labels the old ICSP pins as SPI. Those are the pins you want to use.

The new ICSP pins for the Due are located in a different position, close to the power jack.