Portenta H7 SD.begin() returns 0 systematically

Using Arduino IDE 2.0, trying to read the contents of my 64 GB SD card, after putting a basic text file on it using my PC.
My code is dreadfully simple:invariably, SD.begin() returns 0, whether I use zero, one (CS pin) or two parameters (CS, CK). Based on the pinout, I am reading that the CS pin is J2_36, aka pin 154? Not sure though.
I am brand new with all of this. I appreciate any help you're willing to offer. Thank you.

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

void setup() {
 // to use the SD Card
  Serial.begin(9600);
  Serial.println(SD.begin());
....

Welcome to the forum.
Take a few minutes and read How to get the best out of this forum tutorial.
It help you to wrote correct messages to the thread.

Please show ALL the code, inserting it in code tags.

I have simplified the code to the extreme in order to focus on what does not work... Here it is:

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

void setup() {
 // to use the SD Card
  Serial.begin(9600);
  Serial.println(SD.begin());
  if (SD.begin()==0) {
    Serial.println("It has NOT begun...");
    }
    else{
    Serial.println("It has begun...");  
    }
  }
void loop() {
  // Nothing happens after setup: just trying to debug
}

In this lines you are fires SD.begin() twice in few milliseconds, which can lead to errors.
I would recommend that you invoke SD.begin() once, check return value and, based on the results of the check, print something into the Serial

Thank you for the tip.... It's great to get a response...
I modified to only invoke once the SD.begin() call. And it returns 0 still. I don't know whether I am supposed to indicate a CS pin, a CK pin?

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

void setup() {
 // to use the SD Card

  // put your setup code here, to run once:
  // initialize digital pin LED_BUILTIN as an output.
  Serial.begin(9600);
  if (SD.begin()==0) {
    Serial.println("It has NOT begun...");
    }
    else{
    Serial.println("It has begun...");  
    }
     
  // initialize digital pin LED_BUILTIN as an output.

  }

Do you see the examples of the SD.h library?

I did not see examples per se in the SD.h library. I did see the definitions of the SD.begin() method. There are two:

boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
boolean begin(uint32_t clock, uint8_t csPin);

This seems to indicate to me that we can use either none, 1 or two parameters, as the csPin appears to have a defaulted value. However, when I went to see what SD_CHIP_SELECT_PIN was equal to, I could not find the definition for it. And maybe that is the problem, maybe this default value is missing?
From the pinout, it seems that the CS pin is pin J2_36, but I am not sure how to derive from this what is the integer pin number corresponding to J2_36...
Again, I am very grateful for the help you have already provided me.

I finally saw the examples in the SD.h library. None of them work for me. Don't know where to go.

Do you try to setup CS pin?

I would love to set up the CS pin. I simply do not know how to infer its number from its position (36) on the connector J2. I suspect there is a document (other than the pinout documents) that shows that, but I did not find it.
Do you know what is the CS pin number on a Portenta H7?

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