SDFat on B404X: Cant initialize SD card

I’m trying to test the SD card functionality on a custom PCB I made for the B404X. I’m an electrical engineer and have been designing boards for 9 years. I copied the SD card pinout/schematic of the B Series SoM development board exactly, and have triple checked that it is the same.

I’ve been trying for days to get SDFat to work through the Web IDE, but none of the example codes worked. I’ve tried to use the secondary SPI1, as suggested in the Dev Board datasheet. The error I get is: SD errorCode: 0X20,0XFF

I’ve tried different SD cards. I’ve tried SPI_HALF_SPEED, but that creates a different error. I’ve set SD_SPI_Configuration to 1. I’ve tried SdFat SD(&SPI1). I’ve done a manual digitalRead of the CD pin and see it change when I insert/remove the SD card.

Any insights would be appreciated. Thank you

Here is the main code I’ve been working with:

#include <SdFat.h>


SerialLogHandler logHandler;

// Set up the SDFat object
//SdFat SD(&SPI1);
SdFat sd;

// Define the pin numbers
const uint8_t chipSelect = D5; // CS Pin
const uint8_t cardDetect = D6; // CD Pin
//SD inserted, cardDetect = 0
//No SD inserted, cardDetect = 1

void setup() {
    // Initialize serial communication
    //while (!Serial); // Wait for serial port to connect - required for native USB port only
    pinMode(cardDetect, INPUT);
    // Check if SD card is inserted
    if (digitalRead(cardDetect)) {
        Serial.println("No SD card detected. Insert SD card and restart the device.");
    Serial.println("SD Card Detected");
    // Initialize the SD card
    if (!sd.begin(chipSelect, SPI_FULL_SPEED)) {
    Serial.println("SD Card Initialized");

    // Open a new file
    File myFile ="test.txt", FILE_WRITE);

    // If the file opened okay, write to it
    if (myFile) {
        Serial.println("Writing to test.txt...");
        myFile.println("Testing 1, 2, 3.");
    } else {
        // If the file didn't open, print an error
        Serial.println("error opening test.txt");

void loop() {
    // nothing happens after setup

Oop, got it working myself. System won't let me delete the post.


SdFat sd(&SPI1);
//SdFat sd;

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.