Pages: [1] 2   Go Down
Author Topic: MicroSD: New Card Issues  (Read 3663 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a sketch project that is working well with a 2G MicroSD card that I bought locally for a high price.  After shopping around, I was able to locate a much better price on 1G cards and bought a bunch of them.  When I use the new 1G cards though, they do not seem to work.  The most interesting part is that both cards respond well to the example SD library sketch of "CardInfo" and display the proper parameters and directory readings.  When I attempt to run any sketches (canned examples or my own) that need to open a file and write to the newer 1G card, it fails.  When I say fail, I will see a series of files created in some cases, but they all have zero bytes in size.  Some varieties of the SD libraries simply report an error when attempting to initialize the card.  The exact same sketch works on the 2G card without issue.  I tried a few other varieties of the available SD libraries, such as FAT16.  I also tried formatting the new 1G card with the official SDFormatter utility to ensure I had a good format, but still no luck. The cards do seem to have a FAT16 filesystem on them from the factory. 

Other things I tried:  insert delay(200) statements around the operations that write to the card to simply slow the logic down.  Changed the speed of the compiled project 1MHz, 2MHz, 8MHz & 16MHz.

The new 1G cards do work with a USB adapter on my desktop computer as well as working well in my Android device.  I can read/write/delete to the card with no issues.  My suspicion is that these newer cards do not perform well with an SPI interface, but work fine for MMC mode.  Any thoughts are welcome. 

Thanks.

John

I'm reaching out to see if there are any other options or suggestions to try to get these to work that I've not tried yet.  Perhaps I simply got what I paid for, but I'd like to find a way to use them since I did end up with 100 of them.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27114
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

Tell us about the arduino hardware you use to access the cards.
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
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As for hardware, I'm currently running my prototype as a Teensy 2.0++, modified for 3.3V operation.  I have an CF adapter with legs soldered on poked into my breadboard, where I wire it directly up to the SPI port on the Teensy++.  It is just straight wired and everything running 3.3V.  I've also tried this on my own hardware board of my own design (a sort of derivative of the Teensy++, but my own twist) that has much the same connectivity, but instead has its own MicroSD push-push slot.

Thanks for checking it out.

John
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27114
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

Going to need fat16lib's help I think. He's done testing using a lot of cards.
Mine is limited to a couple of Sandisk cards.
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.

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1638
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote SdFat, Fat16, and the base code for SD.h.  These three libraries have similar code but the new beta of SdFat supports more SD cards than other libraries so download and install SdFatBeta20120825.zip http://code.google.com/p/beta-lib/downloads/list.

Run these three examples: QuickStart, SdInfo, and bench.

Post the error codes if any of the above examples fail.  Also post the results of the bench example if it runs without errors.

If all examples run O.K. change this line in bench.ino from this
Code:
#define FILE_SIZE_MB 5
to
Code:
#define FILE_SIZE_MB 25
And rerun it.  This should do a write stress test.
Logged

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

Wow, these look like great tools you have written to really drill down to what the issue might be.  Here is the output of one of the cards using just the default format that comes on them from the factory.  I'm formatting another one with SDFormatter v3.1 and will run the tests again.  It is interesting that these come labeled as 1G cards, but all indications are that they are 2G cards.  Wondering if they are the 2G seconds that were rejected and reformatted as 1G.

::::::::::: SdInfo :::::::::::::::::::::

SdFat version: 20120719

type any character to start

init time: 5 ms

Card type: SD2

Manufacturer ID: 0X0
OEM ID:
Product: APPSD
Version: 3.0
Serial number: 2290649224
Manufacturing date: 10/2010

cardSize: 4014080 (512 byte blocks)
flashEraseSize: 128 blocks
eraseSingleBlock: true

SD Partition Table
part,boot,type,start,length
1,0X0,0X6,245,4013835
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT16
blocksPerCluster: 32
clusterCount: 62679
freeClusters: 62643
fatStartBlock: 251
fatCount: 2
blocksPerFat: 245
rootDirStart: 741
dataStartBlock: 773
Data area is not aligned on flash erase boundaries!
Download and use formatter from www.sdcard.org/consumer!



:::::::: QuickStart:::::::::


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: 20

Card successfully initialized.

Card size: 2055 MB (MB = 1,000,000 bytes)

Volume is FAT16, Cluster size (bytes): 16384

Files found (name date time size):
PWMGR          2000-01-01 01:00:00 0
TEST.TXT       2000-01-01 01:00:00 0

This card should be reformatted for best performance.
Use a cluster size of 32 KB for cards larger than 1 GB.
Only cards larger than 2 GB should be formatted FAT32.
Try reformatting the card.  For best results use
the SdFormatter sketch in SdFat/examples or download
and use SDFormatter from www.sdcard.org/consumer.

Restarting

:::::::::::: SdFormatter::::::::::::::::

Enter the chip select pin number: 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

Options are:
E - erase the card and skip formatting.
F - erase and then format the card. (recommended)
Q - quick format the card without erase.

Enter option: F
Card Size: 1960 MB, (MB = 1,048,576 bytes)

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

Formatting
Blocks/Cluster: 64
FAT16
error: write MBR
SD error: 13,b


::::::::::::::::: Bench ::::::::::::::::::::::::

SdFat version: 20120719

type any character to start
Free RAM: 7301
Type is FAT16
error: open failed
SD errorCode: 0X13
Logged

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

After formatting one of the cards with SDFormatter v3.1 and running the tests again, here are the results:

:::::::::::::::: Bench :::::::::::::::::::::
Free RAM: 7301
Type is FAT16
error: open failed
SD errorCode: 0X13

::::::::::::: QuickStart :::::::::::::::::::

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: 20

Card successfully initialized.

Card size: 2055 MB (MB = 1,000,000 bytes)

Volume is FAT16, Cluster size (bytes): 32768

Files found (name date time size):
BENCH.DAT      2000-01-01 01:00:00 0

Success!  Type any character to restart.


:::::::::::::::::: SdInfo :::::::::::::::::

type any character to start

init time: 4 ms

Card type: SD2

Manufacturer ID: 0X0
OEM ID:
Product: APPSD
Version: 3.0
Serial number: 2290649224
Manufacturing date: 10/2010

cardSize: 4014080 (512 byte blocks)
flashEraseSize: 128 blocks
eraseSingleBlock: true

SD Partition Table
part,boot,type,start,length
1,0X0,0X6,245,4011595
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT16
blocksPerCluster: 64
clusterCount: 62673
freeClusters: 62673
fatStartBlock: 246
fatCount: 2
blocksPerFat: 245
rootDirStart: 736
dataStartBlock: 768
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1638
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This card fails by returning an error status after a 512 byte data block is sent to the card during a write. The following error code is for a CRC error for the data block.  
Quote
error: write MBR
SD error: 13,b
SD cards should ignore a block's CRC by default in SPI mode.

Try enabling CRC checking by editing SdFatConfig.h and setting USE_SD_CRC to 1 or 2.
Code:
/**
 * To enable SD card CRC checking set USE_SD_CRC nonzero.
 *
 * Set USE_SD_CRC to 1 to use a smaller slower CRC-CCITT function.
 *
 * Set USE_SD_CRC to 2 to used a larger faster table driven CRC-CCITT function.
 */
#define USE_SD_CRC 0
Try the SdFormatter example again.  If this fixes the problem, the card does not function correctly in SPI mode.  The Arduino has no CRC hardware so enabling software CRC will reduce write performance.

Another possible cause is a bad MOSI SPI signal.  I don't think this is the problem with your 3.3V setup.
« Last Edit: September 30, 2012, 03:46:56 pm by fat16lib » Logged

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

Thanks for the reply, but unfortunately, the same error still persists if I set USE_SD_CRC to either 1 or 2.  I see a variety of other settings in the SdFatConfig.h file.  Perhaps one of them would help.

-John
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1638
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think other configuration options will help.

If possible try the card in another Arduino and SD module.  This is a long shot since read operations seem to work with the Teensy.

It may be that the card has problems with single block write commands in SPI mode.
Logged

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

I did try the card in with another microprocessor and card reader that I had soldered up this afternoon, which is my own hardware that is very similar to a Teensy++, however, the results remain the same.  I too don't believe it is an SPI hardware issue as the 2G "expensive" card works every time without fail.  Do you think that there is any remedy that can be made to adapt to this card?  I wouldn't mind to send you one or two or run more tests if that would help. 

I bought these from a distributor, direct from China, and had them shipped to me.  Judging by the manufacturing date that is seen in the tests we have run recently, they are not exactly new.  More than likely, the price was too good to be true and I simply got what I paid for.  A cheap product for a cheap price.  I'm thinking it may be best to seek out another source for cards unless you think you would be able to work with in in some way.  I'm not needing extreme performance as I'm just reading and writing about 100 simple text files that are 24 or 32 bytes long in most cases.  I just needed removable storage for my application and EEPROM isn't so removable.

Thanks again.

-John
Logged

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

I went ahead and just ordered some new cards from a state-side vendor, hoping to put these issues behind me.  Not sure what I'll do with these, but if you get any ideas, let me know.  Maybe I'll just give away my resume on them or send them to family members with pictures on them. 

-John
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1638
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ordering new cards seems like a good idea.

I noticed that BENCH.DAT was created even though open failed.  This means data was written to the card but a failed status was returned.

I am curious to see what happens if you edit Sd2Card.cpp to accept the incorrect return status.

At about line 670 of Sd2Card.cpp change this
Code:
  status_ = spiRec();
  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
    error(SD_CARD_ERROR_WRITE);
    goto fail;
  }
  return true;
to this
Code:
  status_ = spiRec();
  return true;  // Ignore write response
  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
    error(SD_CARD_ERROR_WRITE);
    goto fail;
  }
  return true;

Run bench and see if BENCH.DAT contains text lines like this:
Quote
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRST
Logged

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

I am now getting some positive results to report, but mostly due to my own misunderstanding / mistake.  Your first inclination was correct about setting one of the CRC modes.  My mistake was that when copied the beta library you indicated to the libraries directory, I had renamed the original SdFat folder as "SdFatORIGINAL" before moving the beta copy to the libraries directory.  While observing the verbose output of the compiler, I noticed that, even though I had been choosing examples from the SdFat library, it was compiling from the SdFatORIGINAL directory.  After I completely removed the SdFatORIGINAL directory and re-started the IDE, it started compiling from the right place. 

So, the success is mixed.  The ReadWriteSdFat sketch is able to read and write to the card with the CRC check turned on.  The Bench sketch runs without error, however, never ends, even after 5 minutes.  Once I remove the card from the project and install it into my computer, I see the BENCH.DAT, but no data is in the file. 

Given this, I'm going to dig into how the ReadWriteSdFat sketch is written and try to make those changes to my own sketch to see if I can read and write properly from the card.

If I leave the CRC check turned on, will this continue to be universally compatible with both these cards and other cards, with the speed penalty?  I'm thinking with my relatively light needs, the speed penalty might be OK for this application.

Thanks.

-John
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1638
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

O.K. - I have seen the CRC problem with other cheap cards.

You can enable CRC with any card and it will increase reliability a great deal.  Data is protected by a 16-bit CRC so SPI errors will be detected. 

Performance for all cards will be reduced since calculating CRC requires CPU cycles.  Run bench using a good card with and without CRC to see the hit.

I suspect that the performance of these new cards is very low.  Edit bench.ino and decrease the file size to one MB by changing FILE_SIZE_MB like this:

Code:
#define FILE_SIZE_MB 1
#define FILE_SIZE (1000000UL*FILE_SIZE_MB)

bench.ino should run in 1/5 the time.  Wait at least three minutes.
Logged

Pages: [1] 2   Go Up
Jump to: