Pages: [1] 2   Go Down
Author Topic: SD card problem on Mega, can a card go faulty via SPI but still work in PC?  (Read 821 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Code:
#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!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 435
Posts: 23623
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
lc studio card module
Got a link? Maybe it provides the 3.3V regulation and level translators.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 342
YES! It is possible. Even Impossible Says I m Possible. :)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 20, 2013, 02:41:54 pm by nightcrawler218 » Logged

"Imagination is more important than knowledge."
-Einstein

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 435
Posts: 23623
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 342
YES! It is possible. Even Impossible Says I m Possible. :)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
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!
« Last Edit: December 20, 2013, 04:07:58 pm by nightcrawler218 » Logged

"Imagination is more important than knowledge."
-Einstein

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 342
YES! It is possible. Even Impossible Says I m Possible. :)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hope you fin the fix tomorrow... Waiting.
Logged

"Imagination is more important than knowledge."
-Einstein

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!! 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 342
YES! It is possible. Even Impossible Says I m Possible. :)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Imagination is more important than knowledge."
-Einstein

Czech Republic
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink

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

Offline Offline
Sr. Member
****
Karma: 1
Posts: 342
YES! It is possible. Even Impossible Says I m Possible. :)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Imagination is more important than knowledge."
-Einstein

Czech Republic
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 342
YES! It is possible. Even Impossible Says I m Possible. :)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the link. This is strange but true that the seller is from our neighboring country & doesn't ship here! Bad luck... smiley-roll-sweat
Logged

"Imagination is more important than knowledge."
-Einstein

Pages: [1] 2   Go Up
Jump to: