Go Down

Topic: SD card initialization (Read 2390 times) previous topic - next topic

muralysunam

Oct 16, 2017, 06:37 pm Last Edit: Oct 16, 2017, 06:43 pm by muralysunam Reason: Adding more details
Hi,

I am trying to interface SD card with Arduino UNO with Ethernet shield.

I am using Strontium 2GB memory card. Firstly I downloaded SD Card Formatter as seen from some forums.

After formatting, it displays
Code: [Select]

Formatting was successfully completed.

Volume information:
File system: FAT16
Capacity: 1.84 GB (xxxbytes)
Free space: 1.84 GB (xxx bytes)
Cluster size: 32 kilobytes
Volume label: VIDEO


Then I copied two files(jpg and raw). I also tried with empty drive.

I ejected the mass storage device.

I inserted micro SD card in Ethernet shield(with Arduino UNO).

I opened and uploaded Examples->SD->CardInfo(Chipselect already 4)

I got output

Code: [Select]

Initializing SD card...initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?


Then I opened and uploaded Examples -> SD -> ReadWrite.
I got output.

Code: [Select]

Initializing SD card...initialization failed!


I tried SdFat library also.

I opened and uploaded Examples -> SdFat -> SdInfo
I got output

Code: [Select]
SdFat version: 1.0.3

Assuming the SD is the only SPI device.
Edit DISABLE_CHIP_SELECT to disable another device.

Assuming the SD chip select pin is: 10
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start
error: cardBegin failed
SD errorCode: 0X20,0X0

type any character to start


Please reply. I don't know whats happening.

muralysunam

Hi all,

I tried using Strontium 16GB memory card. Then all other program gave same result expect
Examples->SD->CardInfo(Chipselect already 4)

I got another output

Code: [Select]


Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card


Thanks for any help.

PaulS

Quote
I am trying to interface SD card with Arduino UNO with Ethernet shield.
Don't you suppose that it might be important WHICH SD card reader/writer you are using?
Don't you suppose that it might be important HOW the SD card reader/writer is connected?
The art of getting good answers lies in asking good questions.

muralysunam

Don't you suppose that it might be important WHICH SD card reader/writer you are using?
Don't you suppose that it might be important HOW the SD card reader/writer is connected?
Hi,

Thanks for reply. I am trying to interface micro SD card. I connected to laptop via a local card reader.

Thanks for any help.

PaulS

Quote
I am trying to interface micro SD card.
You can ONLY "interface" (I hate that meaningless, overused word) with a SD card reader/writer.

Quote
I connected to laptop via a local card reader.
I have NO clue what this means.
The art of getting good answers lies in asking good questions.

muralysunam

You can ONLY "interface" (I hate that meaningless, overused word) with a SD card reader/writer.
I have NO clue what this means.
Hi,

Thanks for quick reply, Sorry for the above problems. I will try to explain the scenario.

I am using a 3.5 inch RGB TFT display. I need help of SD card in order to display picture in that display. I formatted micro SD card as FAT using SD Card formatter software. Then I copied two image files to micro SD card.

I tried in arduino mega (there is an sd card slot in my display module). But it is not working. Since I never worked with micro SD card, I tried to go to UNO and Ethernet shield.

I put my formatted micro SD card to Ethernet shield. Tried running examples, I posted the outputs in my first post.


My problem is whenever I am calling  SD.begin(4)   it returns FALSE.

If I use card.init(SPI_HALF_SPEED, 4), it returns true for one of my 16GB micro sd card. But still, volume.init(card) returns FALSE.

Thanks for any reply.

muralysunam

Hi all,

I tried interfacing SD with another Arduino MEGA using Ethernet shield. Its working fine. But it is giving an error(error 0x50,0) while trying to access with display module. Please help.

I uploaded the below shown code and it worked fine(with ethernet shield)

Code: [Select]
// Quick hardware test for SPI card access.
//
#include <SPI.h>
#include "SdFat.h"
//
// Set DISABLE_CHIP_SELECT to disable a second SPI device.
// For example, with the Ethernet shield, set DISABLE_CHIP_SELECT
// to 10 to disable the Ethernet controller.
const int8_t DISABLE_CHIP_SELECT = -1;
//
// Test with reduced SPI speed for breadboards.  SD_SCK_MHZ(4) will select
// the highest speed supported by the board that is not over 4 MHz.
// Change SPI_SPEED to SD_SCK_MHZ(50) for best performance.
#define SPI_SPEED SD_SCK_MHZ(4)
//------------------------------------------------------------------------------
// File system object.
SdFat sd;

// Serial streams
ArduinoOutStream cout(Serial);

// input buffer for line
char cinBuf[40];
ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));

// SD card chip select
int chipSelect;

void cardOrSpeed() {
  cout << F("Try another SD card or reduce the SPI bus speed.\n");
  cout << F("Edit SPI_SPEED in this program to change it.\n");
}

void reformatMsg() {
  cout << F("Try reformatting the card.  For best results use\n");
  cout << F("the SdFormatter program in SdFat/examples or download\n");
  cout << F("and use SDFormatter from www.sdcard.org/downloads.\n");
}

void setup()
{
  Serial.begin(9600);
 
  // Wait for USB Serial
  while (!Serial) {
    SysCall::yield();
  }
  cout << F("\nSPI pins:\n");
  cout << F("MISO: ") << int(MISO) << endl;
  cout << F("MOSI: ") << int(MOSI) << endl;
  cout << F("SCK:  ") << int(SCK) << endl;
  cout << F("SS:   ") << int(SS) << endl;

  if (DISABLE_CHIP_SELECT < 0)
  {
    cout << F(
           "\nBe sure to edit DISABLE_CHIP_SELECT if you have\n"
           "a second SPI device.  For example, with the Ethernet\n"
           "shield, DISABLE_CHIP_SELECT should be set to 10\n"
           "to disable the Ethernet controller.\n");
  }
  cout << F(
         "\nSD chip select is the key hardware option.\n"
         "Common values are:\n"
         "Arduino Ethernet shield, pin 4\n"
         "Sparkfun SD shield, pin 8\n"
         "Adafruit SD shields and modules, pin 10\n");
}

bool firstTry = true;
void loop() {
  // Read any existing Serial data.
  do {
    delay(10);
  } while (Serial.available() && Serial.read() >= 0);

  if (!firstTry) {
    cout << F("\nRestarting\n");
  }
  firstTry = false;

  cout << F("\nEnter the chip select pin number: ");
  while (!Serial.available()) {
    SysCall::yield();
  }
  cin.readline();
  if (cin >> chipSelect) {
    cout << chipSelect << endl;
  } else {
    cout << F("\nInvalid pin number\n");
    return;
  }
  if (DISABLE_CHIP_SELECT < 0)
  {
    cout << F(
           "\nAssuming the SD is the only SPI device.\n"
           "Edit DISABLE_CHIP_SELECT to disable another device.\n");
           
  }
  else
  {
    cout << F("\nDisabling SPI device on pin ");
    cout << int(DISABLE_CHIP_SELECT) << endl;
    pinMode(DISABLE_CHIP_SELECT, OUTPUT);
    digitalWrite(DISABLE_CHIP_SELECT, HIGH);

  }
  if (!sd.begin(chipSelect, SPI_SPEED)) {
    if (sd.card()->errorCode()) {
      cout << F(
             "\nSD initialization failed.\n"
             "Do not reformat the card!\n"
             "Is the card correctly inserted?\n"
             "Is chipSelect set to the correct value?\n"
             "Does another SPI device need to be disabled?\n"
             "Is there a wiring/soldering problem?\n");
      cout << F("\nerrorCode: ") << hex << showbase;
      cout << int(sd.card()->errorCode());
      cout << F(", errorData: ") << int(sd.card()->errorData());
      cout << dec << noshowbase << endl;
      return;
    }
    cout << F("\nCard successfully initialized.\n");
    if (sd.vol()->fatType() == 0) {
      cout << F("Can't find a valid FAT16/FAT32 partition.\n");
      reformatMsg();
      return;
    }
    if (!sd.vwd()->isOpen()) {
      cout << F("Can't open root directory.\n");
      reformatMsg();
      return;
    }
    cout << F("Can't determine error type\n");
    return;
  }
  cout << F("\nCard successfully initialized.\n");
  cout << endl;

  uint32_t size = sd.card()->cardSize();
  if (size == 0) {
    cout << F("Can't determine the card size.\n");
    cardOrSpeed();
    return;
  }
  uint32_t sizeMB = 0.000512 * size + 0.5;
  cout << F("Card size: ") << sizeMB;
  cout << F(" MB (MB = 1,000,000 bytes)\n");
  cout << endl;
  cout << F("Volume is FAT") << int(sd.vol()->fatType());
  cout << F(", Cluster size (bytes): ") << 512L * sd.vol()->blocksPerCluster();
  cout << endl << endl;

  cout << F("Files found (date time size name):\n");
  sd.ls(LS_R | LS_DATE | LS_SIZE);

  if ((sizeMB > 1100 && sd.vol()->blocksPerCluster() < 64)
      || (sizeMB < 2200 && sd.vol()->fatType() == 32)) {
    cout << F("\nThis card should be reformatted for best performance.\n");
    cout << F("Use a cluster size of 32 KB for cards larger than 1 GB.\n");
    cout << F("Only cards larger than 2 GB should be formatted FAT32.\n");
    reformatMsg();
    return;
  }
  // Read any extra Serial data.
  do {
    delay(10);
  } while (Serial.available() && Serial.read() >= 0);
  cout << F("\nSuccess!  Type any character to restart.\n");
  while (!Serial.available()) {
    SysCall::yield();
  }
}


Please help. Thanks for any help in advance...

Go Up