I am trying to connect a DPS310 and an ADXL345 to my Arduino using 4 wire SPI. When the individually tested (i.e. each has its own script), the output is correct, however when the scripts are combined the ADXL output is garbage, but the DPS functions.

What we expect to see:

Temperature = 24.14 *C
Pressure = 857.88 hPa
X: -4  Y: 4  Z: 29   

What we actually see:

Temperature = 24.14 *C
Pressure = 857.88 hPa
X: 0  Y: 0  Z: 0    // and does not change when tilted

When the DPS310 line is commented out, the ADXL works fine (this line is indicated in script)

The whole script (with the faulty line indicated):

#include <SparkFun_ADXL345.h>
#include <Adafruit_DPS310.h>

// ADXL obj
#define ADXL345_CS   9 // SPI pin
ADXL345 ADXL = ADXL345_CS; // Instantiate obj with CS pin
int x = 0, y = 0, z = 0; 

// DPS obj
#define DPS310_CS   10 // SPI pin
Adafruit_DPS310 dps; // Instantiate obj (pin is set in setup)
sensors_event_t temp_event, pressure_event; 

void setup() {
   while (!Serial) delay(10);

   digitalWrite(ADXL345_CS, LOW); // START COMM
   Serial.print("ADXL345: ");
   ADXL.setInterrupt(0x84, true);
   ADXL.setAxisOffset(0, 0, 5);
   ADXL.readAccel(&x, &y, &z);
   if(x != -1 && y != -1 && z != -1) {
   } else {
   digitalWrite(ADXL345_CS, HIGH); // END COMM

   digitalWrite(DPS310_CS, LOW); // START COMM
   Serial.print("DPS310: ");
   if (! dps.begin_SPI(DPS310_CS)) { /////////////////PROBLEM LIES HERE//////////////////
      Serial.println(" [FAILED]");
   Serial.println(" [PASSED]");

   dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
   dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
   digitalWrite(DPS310_CS, HIGH); // END COMM

void loop() {
    digitalWrite(ADXL345_CS, LOW);
    ADXL.readAccel(&x, &y, &z);
    digitalWrite(ADXL345_CS, HIGH);

    digitalWrite(DPS310_CS, LOW);
    dps.getEvents(&temp_event, &pressure_event);
    digitalWrite(DPS310_CS, HIGH);
    Serial.print("Temperature = ");
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.println(" hPa"); 

    Serial.print("X: ");
    Serial.print("  Y: ");
    Serial.print("  Z: ");


I think the fault might lie in the classes written for these devices, for instance maybe they were written for single SPI device or have different frequencies/modes? (I'm probably wrong though XD). I have not yet tried to setup the SPI for each device manually (programming commandment: do no reinvent the wheel), so any help would be greatly appreciated.

  • 1
    set CS pin of the second device HIGH before initializing the first device
    – Juraj
    Commented Sep 16, 2020 at 16:52
  • @Juraj I just tried that and it failed. Even tried to put both HIGH as well as delay for 2s before initializing anything
    – newt
    Commented Sep 16, 2020 at 19:30

1 Answer 1


The ADXL345 uses SPI_MODE3 and DPS310 the SPI_MODE0. The libraries for these devices don't use SPI transactions, but set the settings only in begin(), so they can't be used together.

Your options to solve this is either to put one sensor on software SPI or to put one or both sensors on I2C.

The ADXL345 can be used as I2C device. Its library supports I2C with the constructor when no parameters are provided. Does your module have an option to wire it to I2C?

The Adafruit library for DPS310 has built-in software SPI, so you can use it with any set of pins. And it too supports I2C.

  • I was afraid of that, any idea how I can modify the libraries to operate with each other? I tried to write a basic SPI script to do the transactions by following what the libraries did, however the libraries are far to complicated for me and so it was to no avail. Or should I rather try to implement my own independent SPI script (keeping in mind I'm very new to this)?
    – newt
    Commented Sep 18, 2020 at 6:42
  • @newt, I enhanced the answer
    – Juraj
    Commented Sep 18, 2020 at 7:20
  • Thanks, switched the ADXL to I2C and kept DPS in SPI mode and it worked!
    – newt
    Commented Sep 18, 2020 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.