Trouble with SPI on custom PCB with SdFat

I have been working on a model rocket flight computer and i have been having problems getting a SPI device to work, its a SD Card module and im using the SdFat library to change the SPI pinout but i'm having trouble getting the module to be found. For the code i have just been trying to get SoftwareSpi to work, i looked over the wiring in the pcb schematic, and the connections and everything looks fine, i'm just kind of lost on what is wrong :frowning:
Im using the Arduino 33 BLE for the micro prossesor.
when i run SoftwareSpi i get this error message:

begin() failed
Do not reformat the SD.
SdError: 0X17,0X1

I wired the SPI pins with SdFat like this:
CS = 5
SCK = 6
MOSI = 7
MISO = 8
I also looked over the connections on the board with a multimeter and that was also all good.
Im just totally lost on how to fix this.

If you post the schematic along with the code (or maybe a modified CardInfo sketch) here, then you stand a better chance of getting help with your project.

Ok, ill do that.

Any particular reason you are trying to use a software SPI setup?

Im using it because it allows me to change the pinout of the SPI device because the other SPI pins are in use. I know i can just connect it to the same SPI pins but i had trouble getting that to work.

Here is the code:

// An example of the SoftSpiDriver template class.
// This example is for an old Adafruit Data Logging Shield on a Mega.
// Software SPI is required on Mega since this shield connects to pins 10-13.
// This example will also run on an Uno and other boards using software SPI.
//
#include "SdFat.h"
#if SPI_DRIVER_SELECT == 2  // Must be set in SdFat/SdFatConfig.h

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 1
//
// Chip select may be constant or RAM variable.
const uint8_t SD_CS_PIN = 5;
//
// Pin numbers in templates must be constants.
const uint8_t SOFT_MISO_PIN = 8;
const uint8_t SOFT_MOSI_PIN = 7;
const uint8_t SOFT_SCK_PIN = 6;

// SdFat software SPI template
SoftSpiDriver<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> softSpi;
// Speed argument is ignored for software SPI.
#if ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(25), &softSpi)
#else  // ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(25), &softSpi)
#endif  // ENABLE_DEDICATED_SPI

#if SD_FAT_TYPE == 0
SdFat sd;
File file;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
File32 file;
#elif SD_FAT_TYPE == 2
SdExFat sd;
ExFile file;
#elif SD_FAT_TYPE == 3
SdFs sd;
FsFile file;
#else  // SD_FAT_TYPE
#error Invalid SD_FAT_TYPE
#endif  // SD_FAT_TYPE

void setup() {
 Serial.begin(9600);
 // Wait for USB Serial
 while (!Serial) {
   yield();
 }
 Serial.println("Type any character to start");
 while (!Serial.available()) {
   yield();
 }

 if (!sd.begin(SD_CONFIG)) {
   sd.initErrorHalt();
 }

 if (!file.open("SoftSPI.txt", O_RDWR | O_CREAT)) {
   sd.errorHalt(F("open failed"));
 }
 file.println(F("This line was printed using software SPI."));

 file.rewind();

 while (file.available()) {
   Serial.write(file.read());
 }

 file.close();

 Serial.println(F("Done."));
}
//------------------------------------------------------------------------------
void loop() {}
#else  // SPI_DRIVER_SELECT
#error SPI_DRIVER_SELECT must be two in SdFat/SdFatConfig.h
#endif  // SPI_DRIVER_SELECT

And here is the PCB schematic:

There's a fault with many of the SD card module adapters that are used - generally when being used with the 5V UNO board - that the MISO line is always being driven by the adapter module. That obviously affects the operation of the SPI bus.

Your schematic shows a Nano Every?

yup, thats why i didn't connect the SD card module to the normal SPI pins.

kicad didn't have the schematic for the 33 BLE but they all have the same pinout so i justed used that.

Can you show a photo of the SD card module you have or provide a link to where you got it.

If you are running the micro at 3.3V, then the SD card module should contain nothing more than the SD card socket.

Ah, with a 3.3V system, you should be using an SD card module/adapter like this:

The one you linked to is for 5V systems that includes the level shifting logic from 5V to 3.3V for the SD card. That design of board also generally has the MISO fault.

1 Like

ahhh ok, i will get one of those and see if it works.

So would this work?

That one should work. It does have some 47K pull up resistors on the various signals. Hopefully that should not interfere with the operation of your other SPI module.

Ok! i was also having problems getting the other one to work too lol, but that should only be a small problem.

I moved your topic to an appropriate forum category @mrd_aerospace.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

So i got it, and hooked it up and now its only working without the other spi device hooked up :frowning:
any ideas?

never mind, fixed

Glad it's working. So are you using the hardware SPI interface now or still a software SPI library?