Code Monkey home page Code Monkey logo

Comments (10)

greiman avatar greiman commented on July 18, 2024

0x17, 0xFF is the basic initialization command which occurs at very low SPI clock. Usually means an SPI problem.

Is the SD connected to the correct pins?

Are you trying to map the SPI pins?

from sdfat.

derekriter avatar derekriter commented on July 18, 2024

Hi, thanks for your help. I believe the SPI interface is connected correctly, as if I change it at all then I get 0x01, with the SPI failing completely. I am using SPI.begin to set the SPI bus to the pins I am using. My code roughly goes as follows

#define SD_FAT_TYPE 0
SdFat sd;

void setup() {
    SPI.begin(SD_SCK, SD_MISO, SD_MOSI, -1);
    if(!sd.begin(SD_CS)) {
        sd.initErrorHalt();
    }
}

from sdfat.

greiman avatar greiman commented on July 18, 2024

You need to prevent SdFat from calling SPI.begin().

#define SD_FAT_TYPE 0  //  Will platformio make this global??

// You can use DEDICATE_SPI in place of SHARE_SPI if the SD is the only SPI device.
// Choose a higher SD_SCK after you test this.
#define SD_CONFIG SdSpiConfig(SD_CS, USER_SPI_BEGIN | SHARED_SPI, SD_SCK_MHZ(10))

SdFat sd;

void setup() {
    SPI.begin(SD_SCK, SD_MISO, SD_MOSI, -1);
    if(!sd.begin(SD_CONFIG)) {
        sd.initErrorHalt();
    }
}
void loop() {}

from sdfat.

derekriter avatar derekriter commented on July 18, 2024

Ok, I will try that later today when I am able.

from sdfat.

derekriter avatar derekriter commented on July 18, 2024

It didn't work. I am still getting 0x17. My exact code is

#include <Arduino.h>
#include <SPI.h>

#include "SdFat.h"

#define SD_FAT_TYPE 0

const uint8_t SD_CS_PIN = 6;
const uint8_t SD_MISO_PIN = 10;
const uint8_t SD_MOSI_PIN = 9;
const uint8_t SD_SCK_PIN = 11;

#define SD_CONFIG SdSpiConfig(SD_CS_PIN, USER_SPI_BEGIN | DEDICATED_SPI, SD_SCK_MHZ(10))

#if SD_FAT_TYPE == 0
SdFat sd;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
#elif SD_FAT_TYPE == 2
SdExFat sd;
#elif SD_FAT_TYPE == 3
SdFs sd;
#else
#error Invalid SD_FAT_TYPE
#endif

void setup() {
    Serial.begin(115200);
    
    Serial.println("Type any character to start");
    while(!Serial.available()) {
        yield();
    }
    
    SPI.begin(SD_SCK_PIN, SD_MISO_PIN, SD_MOSI_PIN, -1);
    if(!sd.begin(SD_CONFIG)) {
        sd.initErrorHalt();
    }
}
void loop() {
    
}

And console output

Type any character to start
begin() failed
Do not reformat the SD.
SdError: 0X17,0XFF

I also tried moving the #define SD_FAT_TYPE 0 into the beginning of SdFat.h, and it had no effect, so I believe that it takes global effect.

from sdfat.

greiman avatar greiman commented on July 18, 2024

I can't do more since I don't have your hardware.

Here is a similar ESP32 issue where the above worked.

from sdfat.

derekriter avatar derekriter commented on July 18, 2024

OK, thank you for your efforts. If I can't get it to work, I might just have to bit-bang it.

from sdfat.

greiman avatar greiman commented on July 18, 2024

You need to verify the SPI is available on the pins you selected. Here is a pinout for Feather ESP32-S3:
adafruit_products_Adafruit_Feather_ESP32-S3_Pinout

Looks like the option is:
MOSI pin 11
SCK pin 12
MISO pin 13

Standard pins are:

SCK pin 36
MOSI pin 35
MISO pin 37

from sdfat.

greiman avatar greiman commented on July 18, 2024

Here is the IO MUX pin functions from the ESP32-S3 datasheet:
Screenshot 2024-02-24 at 06-49-40 esp32-s3_technical_reference_manual_en pdf

from sdfat.

greiman avatar greiman commented on July 18, 2024

I found a ESP32-S2 Feather someone gave me. It has the same pinout as the ESP32-S3 Feather.

I edited your sketch to use the correct pins and added a call to ls().

#include <Arduino.h>
#include <SPI.h>

#include "SdFat.h"

#define SD_FAT_TYPE 0

const uint8_t SD_CS_PIN = 10;
const uint8_t SD_MISO_PIN = 13;
const uint8_t SD_MOSI_PIN = 11;
const uint8_t SD_SCK_PIN = 12;

#define SD_CONFIG SdSpiConfig(SD_CS_PIN, USER_SPI_BEGIN | DEDICATED_SPI, SD_SCK_MHZ(10))

#if SD_FAT_TYPE == 0
SdFat sd;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
#elif SD_FAT_TYPE == 2
SdExFat sd;
#elif SD_FAT_TYPE == 3
SdFs sd;
#else
#error Invalid SD_FAT_TYPE
#endif

void setup() {
    Serial.begin(115200);
    
    Serial.println("Type any character to start");
    while(!Serial.available()) {
        yield();
    }
    
    SPI.begin(SD_SCK_PIN, SD_MISO_PIN, SD_MOSI_PIN, -1);
    if(!sd.begin(SD_CONFIG)) {
        sd.initErrorHalt();
    }
    sd.ls();
}
void loop() {}

Here is the output:

bench.dat
SF411Logger.csv
STM32F411Logger.csv
STM32F411ADC/
STM32F411Logger/

from sdfat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.