Go Down

Topic: Card failed or not present error (Read 2396 times) previous topic - next topic

BSDETristan

Aug 11, 2016, 08:38 am Last Edit: Aug 12, 2016, 12:23 am by BSDETristan Reason: Changed from using a quote for code to the code tags
Hello,

I am having an issue when attempting to use a SD card breakout board to write a file to an SD Card. My output is stating that there is no card or an issue with the card. I can read the card on my OS just fine. I have even downloaded the SD Formatter program, as I read that formatting with the OS can be an issue.

I am relatively new to electronics/Arduino (but I am a web application programmer if that helps).

This is the SD Card breakout board that I am using:

http://www.jaycar.com.au/medias/sys_master/images/8895839895582/XC4598-dataSheetMain.pdf

These are the specifications:
http://linksprite.com/wiki/index.php5?title=SD_Card_Breakout_Board

I have double checked my wiring, and all appears correct. Below is my code:

Code: [Select]
/*
 *  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK(SCK) - pin 13
 ** CS(SS) - pin 4
 *
 */

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

//Select PIN 4 as the chip select PIN
const int chipSelect = 4;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);

  Serial.print("Initializing SD card...");

  //Set PIN 4 to be an ourput PIN
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "Test 1, 2, 3\r\n";

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile)
  {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else
  {
    Serial.println("error opening datalog.txt");
  }
}


This is the output that I am getting in my serial monitor:

Quote
Initializing SD card...Card failed, or not present
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
At this point, I am not sure what is causing the error. Any suggestions/help is much appreciated.

Thanks.

el_supremo

Code: [Select]
 //Set PIN 4 to be an ourput PIN
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);

Don't do this. Pin 4 is an INPUT and the SD library will take care of it.

Pete
Don't send me technical questions via Private Message.

BSDETristan

Thanks Pete. I have removed these lines, however I am still getting the same error/experiencing the same issue.

chucktodd

Hello,

I am having an issue when attempting to use a SD card breakout board to write a file to an SD Card. My output is stating that there is no card or an issue with the card. I can read the card on my OS just fine. I have even downloaded the SD Formatter program, as I read that formatting with the OS can be an issue.

I am relatively new to electronics/Arduino (but I am a web application programmer if that helps).

This is the SD Card breakout board that I am using:

http://www.jaycar.com.au/medias/sys_master/images/8895839895582/XC4598-dataSheetMain.pdf

These are the specifications:
http://linksprite.com/wiki/index.php5?title=SD_Card_Breakout_Board

I have double checked my wiring, and all appears correct. Below is my code:

Code: [Select]
/*
 *  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK(SCK) - pin 13
 ** CS(SS) - pin 4
 *
 */

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

//Select PIN 4 as the chip select PIN
const int chipSelect = 4;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);

  Serial.print("Initializing SD card...");

  //Set PIN 4 to be an ourput PIN
  pinMode(chipSelect, OUTPUT);
  digitalWrite(chipSelect, HIGH);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "Test 1, 2, 3\r\n";

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile)
  {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else
  {
    Serial.println("error opening datalog.txt");
  }
}


This is the output that I am getting in my serial monitor:

At this point, I am not sure what is causing the error. Any suggestions/help is much appreciated.

Thanks.

Have you read the first post in this forum?
Don't Format SD cards with OS utilities!


The Arduino expects a 'correctly' formatted SDcard.  Windows uses it's on rules.

Chuck.
Currently built mega http server, Now converting it to ESP32.

BSDETristan

Hi Chuck,

Yes I did read that and I have used the SD Formatting program which was mentioned in that post:

Quote
I have even downloaded the SD Formatter program, as I read that formatting with the OS can be an issue.
I have another SD card reader on an Ethernet shield, and that works just fine with the SD card that I am using, it's just this device in particular.

I was thinking that there is an issue with my code that might be specifically for this style of breakout board.

Thanks for your help.

el_supremo

Can you change the wiring and code to use pin 10 for CS? It's the default pin for CS and shouldn't make any difference but you never know!

Pete
Don't send me technical questions via Private Message.

BSDETristan

Thanks for the suggestion Pete. I gave it a go, but got the same errror.

cattledog

Quote
I have another SD card reader on an Ethernet shield, and that works just fine with the SD card that I am using, it's just this device in particular.
Can you supply details on the SD card reader which does work.

There appear to be two types of SD modules in the market, those with an IC for level shifting of the SPI signals, and those with a resistor network. The module your showed the XC4598 looks to have the resistors

If the modules are indeed different, than could explain why the card works in one and not the other. That specific card may require the signal quality of the IC level shifted modules.

Go Up