Adafruit SD card reader and DPS310 not working together with SPI

Hello all!

I am using an Adafruit SD card reader breakout Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY! : ID 4682 : Adafruit Industries, Unique & fun DIY electronics and kits alongside an Adafruit DPS310 breakout Overview | Adafruit DPS310 Precision Barometric Pressure and Altitude Sensor | Adafruit Learning System.

I am running into an issue where each device works perfectly fine by itself over SPI, but as soon as I put these two on the same SPI interface, only the DPS initializes and the SD card fails to do so. I believe that the SD card reader works with other SPI devices as I tried to use it alongside an SPI display and it worked just fine.

Maybe I am missing something very obvious, regardless, I provided my code below.

#include <Adafruit_DPS310.h>
#include <SPI.h>
#include <SD.h>

Adafruit_DPS310 dps;
#define DPS310_CS 5
#define SD_CS 4

void setup() {
  Serial.begin(9600);
  while (!Serial) delay(10);

  if (! dps.begin_SPI(DPS310_CS)) {
    Serial.println("DPS310 initialization failed!");
    while(true);
  }
  dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
  dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);

  if (!SD.begin(SD_CS)) {
    Serial.println("SD initialization failed!");
    while(true);
  }
  Serial.println("initialization done.");

}

void loop() {
}

Which board are you using? What is the reported memory usage?

there can be problems with common SD card readers when sharing a SPI bus with other devices, see Sharing the SPI bus among SD card and other SPI devices
one approach is to use a microcontroller with two SPI interfaces
what microcontroller are you using?

I am using the nano 33 ble and the reported capacity is 16gb.

What board are you using? I hope it's not a 5V board as that SD breakout board doesn't have level shifters.

Never mind, I just saw your answer. :slight_smile:

Since it's just a breakout of the bare card, there shouldn't be any MISO issues with that. Which leaves your pressure sensor.

One test worth making would be to hook up the pressure sensor, and wire 2 4.7K resistors from its MISO line - one to ground and one to 3.3V. Write a little sketch that sets up SPI but leaves the CS pin unselected (high). Then measure the voltage on the MISO line. If it's around 1.65V, great; the pressure sensor is properly tristating MISO when it's not selected. If it's 3.3V or 0V - there's your problem.

1 Like

@psmieja is not using a common SD card reader but a passive one. From the Adafruit link:

And the schematic

Yeah I’ve had this guy work in the past with other SPI devices so I’m just confused exactly why it’s not working with this one.

Not what I asked :slight_smile: I was asking what the IDE was reporting after compilation.

But OK, a Nano 33 BLE should have enough memory to cater for the dynamic memory allocation of the Adafruit stuff.

So I do not know where the problem could be.

The 33 ble uses a 3v architecture so I don’t believe that’s the issue here. However good point for the atmegas out there

Oh so sorry I misread your comment! Thank you for looking into it my friend!

It might be that the pressure sensor isn't tristating MISO when not selected; check my updated post 5.

Got it! I will definitely try that tomorrow once I have some time! What could be causing the issue here?

Awesome thanks!

I use this. The SPI interfaces must be disabled or they will crosstalk (bus contention) during the begin calls. The SD.begin() function will probably fail without this. This is the only time you need to set the CS pins on them. The libraries should handle the CS lines once the begin calls are complete.

void setup() {
  Serial.begin(9600);
  while (!Serial) delay(10);

  # disable SD SPI
  pinMode(SD_CS,OUTPUT);
  digitalWrite(SD_CS,HIGH);

  # disable DPS310 SPI
  pinMode(DPS310_CS,OUTPUT);
  digitalWrite(DPS310_CS,HIGH);

# rest of your code.
1 Like

Sorry for a while of no response. I have tried this and I got 1.71V on the MISO bus. I additionally decided to test this with a BMP390 and got the same result where only one initializes and the other one fails. Could this be a problem with the SD reader?

1.71V is a good sign. That's only a few percent above 1.65V and is easily explained by resistor tolerances and Vcc maybe not being exactly 3.3V. It sounds like the pressure sensor is properly tristating MISO.

You say you got the same result with a different pressure sensor, hmm? Interesting. I wouldn't have thought that the SD reader would be the problem; it's a bare breakout and the SD card ought to properly tristate MISO. Though I suppose you could repeat the "check for tristate" experiment with it to verify that.

I don't have a BMP390 here but I do have a BME280 so when I have some time I'll through it, a bare SD breakout board and an SPI OLED on a handy Wemos D1 and just see what happens. I expect it to Just Work but the truth's in the trying.

Thank you Van! I suspect the SD breakout but I thought the same exact thing is that there is nearly nothing in between... Let me know how it goes! I might get a different SD breakout to try.

As I suspected, it Just Worked (once I moved the BME280's CS pin off one of the ESP8266's "pins which must not be pulled high at startup"). uSD, BME280 and an SPI SSD1306. And as @SurferTim noted, I made sure all the CS pins were set HIGH before anything else was done.

I've never used a Nano 33 BLE but I can't imagine there's something in it that objects to more than one peripheral on SPI. Edit: and as you noted in your original message, the SD breakout worked just fine with other SPI devices.

The only thing I can see, and I'm grasping at straws here, is that the Adafruit uSD breakout has 47K pullups on all the SPI lines. Why that should make any difference, I have no idea. The breakout I have is just direct connections to the card and nothing else. But I can't imagine it would make any difference at all.

I suspect the problem may involve Adafruit's level translation circuit. It's the same in both the DPS310 and the BME280. On two of the lines, when the line goes low, it has, in effect, two 10K pullup resistors in parallel to 3.3V. SPI is supposed to be a push/pull thing, with no pullup resistors. Still, you'd think it would work. So I don't know what's going wrong. Both sensors also appear to have the same goofy "SPI or I2C" option, which may be causing something strange to happen.

But my point is that the DPS310 and BME280 are NOT two different SPI devices, and I suspect either of them could cause the same problem even if the SD breakout is working right. You need to test the SD module with something completely different.

Do you have the option of using I2C for the sensor?

I do not have the option for I2C. However, I tested the BMP390 and SD reader with a separate setup (like @van_der_decken did) and with a different version of the 33 ble and it works just fine.


My original setup looks like this and uses a 33 ble rev2.

The top connector is for the display, the middle for the sensors, and the bottom of course for the SD card. Can something like this have an effect? I additionally double and triple-checked my PCB and the wiring doesn't seem to be the problem.