SD card problem on Mega, can a card go faulty via SPI but still work in PC?

Hi all,

I am driving myself slightly nuts trying to get an SD card going on a Mega 2560.

I've had this card working in the past and I've been using the same code (and tried all the examples) but the card refuses to play ball.

The card works fine when plugged into the PC card reader.

Is it possible for it to go faulty when being read via SPI and still work when being read from a PC?

I have these connections:
SD card Mega
5v 5v
Gnd Gnd
MOSI 51
MISO 50
SCLK 52
CS 53

(i've tried CS on other port pins and set 53 to output regardless)

What's bugging me is this has all worked fine before!

On the scope I can see clock and MOSI going and there are just single pulses coming back on MISO.

There's no level shifter on the SD card interface board and I've never used one in the past either. (it's an lc studio card module)

This uses pin 45 for CS

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

void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);
  
  pinMode(45,OUTPUT);
  pinMode(53,OUTPUT);

  Serial.println("check for SD card");
  
  if(SD.begin(45))
    {
      Serial.println("SD card found");
    }
   else
   {
     Serial.println("SD card NOT found");
   }
  

}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

Any ideas or suggestions would be most welcome!

lc studio card module

Got a link? Maybe it provides the 3.3V regulation and level translators.

I suppose Richard is using this module

I am using the same module, having the same issue.
Differences is my board is 328 based UNO & his MEGA2560.

Could try the SDfat.h library instead of Sd.h
http://code.google.com/p/sdfatlib/

fat16lib updates it regularly and is in the forum quite frequently as well.

Thanks for the link CrossRoads. Tried to format the sd card using the SdFormatter example.
Connections...
SD Module--------------------- Arduino
MOSI----------------------------D11
MISO----------------------------D12
SCK------------------------------D13
CS-------------------------------D10

The error report

This sketch can erase and/or format SD/SDHC cards.

Erase uses the card's fast flash erase command.
Flash erase sets all data to 0X00 for most cards
and 0XFF for a few vendor's cards.

Cards larger than 2 GB will be formatted FAT32 and
smaller cards will be formatted FAT16.

Warning, all data on the card will be erased.
Enter 'Y' to continue: Y
// I pressed Y
Options are:
E - erase the card and skip formatting.
F - erase and then format the card. (recommended)
Q - quick format the card without erase.
// I pressed F
Enter option: F
Card Size: 3782 MB, (MB = 1,048,576 bytes)

Erasing
..............................
All data set to 0x00
Erase done

Formatting
Blocks/Cluster: 64
FAT32
error: write MBR
SD error: 13,80

Formatted the SD using Windows. FAT32.... Default allocation size......... Quick format.....
Then re-inserted the card in the module & run thhe sketch. still showing same error.
The card is working fine in my computer.
Perplexed indeed!

Yes, that the module.
Crazy thing is, I had it working fine a few days ago! I had stripped the board down to do something else and today I wanted to use the SD card again.
I thought I may have blown the card but it reads and writes fine on a PC.
I must be missing something really obvious, but I have checked and triple checked wiring. I have tried 2 cards and 2 interfaces.
I know the spi port worked as I used in with a radio module.
Maybe I will have a eureka moment tomorrow!

Hope you fin the fix tomorrow... Waiting.

Just tried SDfat and the SDinfo example returns :

card.init failed
SD errorCode: 0XA
SD errorData: 0X1F

(that's ACMD41 initialization process timeout)

and with no card in the slot :

card.init failed
SD errorCode: 0X1
SD errorData: 0XFF

So it is detecting something.

OK looks like its a ground problem.

I connected both GND pins on the card module to the Gnd pins on a Nano (either side of the usb socket) and the card works!

Or maybe it had actually locked up the card because no I can put the grounds back to before - one ground wire to the GND pin next to the Vin pin and it still works!

i have been swapping cards between a Nano and a Mega 2560 and I also formatted the card again with the pc.

For some reason it's just decided to go again...

Maybe it got corrupted at some point but the PC never had any problems reading it....

Now I can get on with what I wanted to do two days ago!!!

After some more playing, way way too late at night, I have come to the conclusion that is odd problem must just be down to the 5v SPI levels causing reliability problems.

After finally getting the reader working again by connected both grounds, It decided to stop working and then to only work with both grounds disconnected!

I'm going to ditch the cheaper SD card modules and go for the micro SD reader with the proper level shifter. It's 4 times more expensive but at least I know it will keep working from one day to the next!

It's amazing that something that worked fine for months can suddenly decide to stop, but that's what comes of using things out of spec...

In the mean time, if anyone has a source of really economical 5V compatible SD card modules, in the UK, let me know. At the moment I'm looking at the one Hobby Components have for £4.50.

Found something - http://www.instructables.com/id/Arduino-DIY-SD-Card-Logging-Shield/
Need a level shifter.
Bad product...
:frowning:

Hi,

it definitely looks like mine problem which I tried to solve few weeks ago. Its good to know that version with level shifter is probably extremely (not "just") recommended (even these are really few % of market).

Thats why I have ordered shield from ebay which has level shifter IC. Also it has ICSP header, so it could be used on Mega an also on Uno. I am using Mega2560.
It will arrive in next days (I hope), and it costs under 10$ with shipping :wink:

I may post a link of that if you want...

Sure, that'd be nice. post the link. I shall try to find it in our region.
Thanks for your response.

Here you have it:

http://www.ebay.com/itm/Arduino-SD-TF-card-expansion-board-Shield-module-Stackable-module-building-block-/171183223678?pt=LH_DefaultDomain_0&hash=item27db50b37e

They are shipping almost woldwide. I have already purchased it from this seller.

Thanks for the link. This is strange but true that the seller is from our neighboring country & doesn't ship here! Bad luck... :cold_sweat:

My favorite SD shield is from ADAFRUIT that combines a SD socket with level shifters as well as the well supported 1307 RTC with battery backup socket. A good value for two features that are often used together.

Thanks retrolefty for the link. The tutorial page attached to the product is also very helpful.

retrolefty:
My favorite SD shield is from ADAFRUIT that combines a SD socket with level shifters as well as the well supported 1307 RTC with battery backup socket. A good value for two features that are often used together.

Adafruit Assembled Data Logging shield for Arduino : ID 1141 : Adafruit Industries, Unique & fun DIY electronics and kits

Are you sure that this is compatible with Mega also? There is no mention about ICSP header, and in place of PCB where it should be is drilled array.... Also they dont show bottom of shield.

BTW i dont think that DS1307 is good solutin. Personally use only DS3231 module because DS1307 had big problems in long term accuracy.

nightcrawler218:

You can try ask seller if they will ship in your country with extra cash. Or look for other sellers, but hope you will find a good supplier, as I mention - only few shields/modules with level shifters are on market for reasonable price....
Also look at this shield:
http://www.ebay.com/itm/TFT-SD-Shield-for-Arduino-MEGA-2560-LCD-Module-SD-level-translation-2-8-3-2-DUE-/121161179201?
It also has level shifter. But it more proposed for usage with color tft modules (has STM32 compatible connectors). Thats why it is not so cheap, but shtill costs less than Adafruit :wink:

EDIT:
While searching for some components for my project, found this seller which ships worldwide - hope you are not from Hong Kong or China (these are exceptions):
http://www.ebay.com/itm/Arduino-SD-TF-card-expansion-board-Shield-module-Stackable-module-building-block-/310735773715?