Having problems with SD card

Dear sir/madam,

Recently I acquired a Renesas Sakura development board, to evaluate whether we want to use Renesas ICs in the future. One of the most interesting features was the microSD card slot that was already present, which is ideal for datalogging.

However, even the simple demo program that was posted in the reference guide does not work. I tried SD cards in three different sizes (1GB, 2GB and 8GB), formatted as both FAT16 and FAT32, and none of the six configurations works, all I get is the notification that no SD card was found (that is, SD.begin() results in false).

I was wondering, am I doing something wrong? Is my board faulty? What would be the best way to test this? 

The code I used is as follows:

#include <Arduino.h>
#include <SD.h>
 
void setup(){
    Serial.begin(9600);
    while(!Serial.available()); // wait to press key
    Serial.read(); //dummy
     
    if(!SD.begin()){
        Serial.println("Card failed, or not present.");
        while(1);
    }
}
      
void loop(){
    File file = SD.open("sample.txt", FILE_WRITE);
  
    if(file){
        //Write
        Serial.println("Success to open sample.txt and write hello.");
        file.println("Hello, my SD");
        file.close();
         
        //Read
        file = SD.open("sample.txt", FILE_READ);
        Serial.println("Reading file...");
        while(file.available()){
            Serial.print((char)file.read());
            delay(50);
        }
        Serial.println();
         
        //Size
        Serial.print("File Size:");
        Serial.println(file.size());
        file.close();
        digitalWrite(PIN_LED0, 0);
         
        //Remove
        Serial.println("Remove the file? y/n");
        while(!Serial.available());
        if(Serial.read() == 'y'){
            SD.remove("sample.txt");
            Serial.println("sample.txt has been removed");
        }
        delay(400);
 
    } else {
        Serial.println("Failed to open file.");
        digitalWrite(PIN_LED0, 0);
        while(1);
    }
}
 
Yours,
 
美月
  • I think your code is no problem. I'm not sure the cause.
    Did you hit any key in a serial monitor and catch a error message?
    Do you use web compiler ? Is the project template version V2.13 ?
  • In reply to Okamiya Yuuki:

    Dear Okamiya-さん,

    Thanks for the quick reply.

    When I start my serial monitor and hit a key, I get the message "Card failed, or not present.", as the code is told to report.
    I used the web compiler, with the project template version V2.13.
    I would appreciate any tips of what I can try next.

    Yours,

    美月
  • In reply to Mitsuki:

    Tkank you for your information.
    Could you attach bin file here ? I will try that. If I couldn't access SD, it seems hardware problem.
    Now I don't have a Sakura, I will try tomorrow.
  • In reply to Okamiya Yuuki:

    Dear Okamiya-さん

    I have attached the .bin file. The serial monitor is running at 9600 baud.

    SD reading.zip

    I hope you can help me further tomorrow.

    Yours,

    美月

  • In reply to Mitsuki:

    Hi Mitsuki-san,

    It works fine on my Sakura as seen below screen. There seems to be no problem on your software.

    I used 4GB micro SD. Arduino library supports SD, SDHC so I think there is no problem with your SD. Please confirm your Sakura if it had physical damage at SD socket.

  • In reply to Okamiya Yuuki:

    Dear Okamiya-さん

    The Sakura is brand new, it has been in use for a few weeks now. There is no visible damage to the SD socket. Is there a way to easily test the electrical connections?

    Yours,

    美月
  • In reply to Okamiya Yuuki:

    Dear Okamiya-さん

    Thanks for all the help you provided. The problem has been resolved now.

    It appeared that my DUT messed up the connection. Once I removed all connections to the DUT, the SD card function worked flawlessly.

    The SPI pins, pins 11, 12, 13, should be avoided, apparently. Maybe it would be nice to add this to the reference page at http://gadget.renesas.com/en/reference/sakura/library_sdmmc.html to avoid future problems. 

    Yours,

    美月

  • In reply to Mitsuki:

    Hi 美月-san

    Sounds great!

    About pins11, 12, 13, do you mean that these pins are shared with SD, so do not used for other GPIO ?
  • In reply to Okamiya Yuuki:

    I understood. Your DUT was used pins 11, 12, 13. So it didn't work, right ?
    Ok, I'll write that in the reference. I'm sorry to bother you in this time.
  • In reply to Okamiya Yuuki:

    Dear Okamiya-さん

    This is correct. My DUT was using pin 11, so it didn't work. Pin 12 and pin 13 gave the same result.
    Great to hear it will be put in the reference, might save someone a headache someday.

    Thanks for trying to help though! 


    Yours,

    美月