Go Down

Topic: SD card using ICSP pins (Read 1 time) previous topic - next topic

newbie

Hi!

I am trying to interface SD card using card module. The Arduino that I am using also has an Adafruit motor shield mounted on it. Due to this, I was forced to take parallel connections from the ICSP ports.

When I tried to run Quickstart from SDFat library, it gives the following error:


SPI pins:
MISO: 12
MOSI: 11
SCK:  13
SS:   10

Be sure to edit DISABLE_CHIP_SELECT if you have
a second SPI device.  For example, with the Ethernet
shield, DISABLE_CHIP_SELECT should be set to 10
to disable the Ethernet controller.

SD chip select is the key hardware option.
Common values are:
Arduino Ethernet shield, pin 4
Sparkfun SD shield, pin 8
Adafruit SD shields and modules, pin 10

Enter the chip select pin number: 19

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

SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Does another SPI device need to be disabled?
Is there a wiring/soldering problem?

errorCode: 0x25, errorData: 0x0

Restarting

Enter the chip select pin number:


I have checked and rechecked the connections. Is the problem because I am using analog pin (A5) as digital (19) or because I am using ICSP?

Should I declare extra pins for using ICSP?


P.S. Thanks in advance

MorganS

On some Arduinos there is no MISO or MOSI available on the regular pins. You have to use the 2x3 ICSP pins. But that doesn't give you a chip-select line. (The chip-select there is for a programmer to select the Arduino, not the other way around.)

Most Arduinos will accept 11,12,13 as aliases for MOSI, MISO and SCLK. Except for the ones which don't have SPI on those pins. Then most libraries will just use the hardware SPI without actually knowing which pins they're using.

Which pin did you wire the SD chip select? A5? Then use A5 in your program.

Hold on, let me back up a few steps.... Which Arduino?
"The problem is in the code you didn't post."

newbie

I'm using Arduino Uno. The ICSP pins should function without any further hardware specifications, as far as I know.

I used pin A5 but I declared it as 19 as I'm using it as a digital pin.

MorganS

Do you have a level translator? The 5V UNO will destroy many 3.3V SD cards.
"The problem is in the code you didn't post."

newbie

Okay, So I am now using another analog pin (A0) as digital to give vcc to SD module.(I read somewhere that digital pins give 0.6 Vcc = 3 V as output.)  

The simple SD card read/write example gives the following error:

/*

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

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


*/


Also, I cannot give A5 as the input for CS pin as I'm using it as a digital pin. It shows invalid pin no. when I type that.

MorganS

The Arduino UNO will emit almost exactly 5V on any pin used as a digital output HIGH. It is limited in how much current it can deliver and if you are using a lot of current (more than 20mA) then the voltage will drop.

This is not enough current to cause your SD card to burst into flames but it may permanently damage the card.

Quote
I cannot give A5 as the input for CS pin as I'm using it as a digital pin.
Now it's time to show us your code. In [ code ] tags, please. A wiring diagram might help - I don't know how  you've wired to the SD VCC.
"The problem is in the code you didn't post."

newbie

#6
May 12, 2017, 02:26 am Last Edit: May 12, 2017, 02:41 am by Newbie Reason: attachment
This is the example sketch from SD library of arduino

Code: [Select]
/*
  SD card test

 This example shows how use the utility libraries on which the'
 SD library is based in order to get info about your SD card.
 Very useful for testing a card when you're not sure whether its working or not.

 The circuit:
  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
 Pin 4 used here for consistency with other Arduino examples


 created  28 Mar 2011
 by Limor Fried
 modified 9 Apr 2012
 by Tom Igoe
 */
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8

const int chipSelect = 19;  // changed this to 19 to correspond with A5

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);


  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {

}


It gives the following output:

newbie

I snapped a photo of my connections. Attached herewith.

Nick_Pyner

If the card is detected, there can't be much wrong. Have you formatted the card in the proper manner? There is a sticky on this matter at the head of this forum.

newbie

Actually, I am unable to format this card by using the tool. But all of the cards that I've tried with so far, generate the same o/p. Should I get a new card specifically dedicated for this job?

CrossRoads

"Okay, So I am now using another analog pin (A0) as digital to give vcc to SD module."

Don't do that!  SD cards need 150-200mA or more of current. The 40mA Absolute Max from an IO pin at 5V with an Uno will not do it and may have damaged the IO pin.  The 150mA from the Uno's 3.3V regulator may not be enough even and many SD/uSD card adapters include a 3.3V regulator and 5V to 3.3V level adapters.

"(I read somewhere that digital pins give 0.6 Vcc = 3 V as output.)  "
Also incorrect.  What you read is that  0.6 x Vcc is the minimum level guaranteed to be read in as a HIGH input, so 3V with Vcc = 5V.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

"Actually, I am unable to format this card by using the tool. "
You used the tool here
https://www.sdcard.org/downloads/formatter_4/index.html
and you can't format the card?  I would say it's time for a new card then.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up