CardInfo reports wrong size on Logger Shield
Moderators: adafruit_support_bill, adafruit

CardInfo reports wrong size on Logger Shield

by pgrunwald on Mon Dec 24, 2012 10:40 pm

I have an 8GB Samsung Micro SD Card in an adapter. I formatted the card with the SD Formatted Utility from the SD site and it and Windows reports 7.4GB usable area.

I get this when I run CardInfo:

Code: Select all | TOGGLE FULL SIZE
Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3658711040
Volume size (Kbytes): 3572960
Volume size (Mbytes): 3489

Files found on the card (name, date and size in bytes):
DATALOG.TXT   2000-01-01 01:00:00 2886


Datalogger worked find and the file is readable in Windows. What am I missing?

Thanks,
Paul
pgrunwald
 
Posts: 33
Joined: Tue Jul 14, 2009 9:32 pm

Re: CardInfo reports wrong size on Logger Shield

by fat16lib on Wed Dec 26, 2012 4:27 pm

CardInfo has a bug that caused it to report the wrong size for cards larger than 4 GB.

CardInfo uses a uint32_t which is limited to 4,294,967,295 so you get some truncated wrong answer.
Code: Select all | TOGGLE FULL SIZE
  uint32_t volumesize;


You can change the section that prints the volume type and size like this
Code: Select all | TOGGLE FULL SIZE
  // 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
  if (volumesize < 0X800000) {
    volumesize *= 512;                        // SD card blocks are always 512 bytes
    Serial.print("Volume size (bytes): ");
    Serial.println(volumesize);
    volumesize /= 1024;
  } else {
     volumesize /= 2;
  }
  Serial.print("Volume size (Kbytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

Then an 8GB card will print something like this:
Volume size (Kbytes): 7753728
Volume size (Mbytes): 7572

And a 2GB will print the byte count:
Volume size (bytes): 1977286656
Volume size (Kbytes): 1930944
Volume size (Mbytes): 1885
Last edited by fat16lib on Wed Dec 26, 2012 8:16 pm, edited 1 time in total.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 12:54 pm

Re: CardInfo reports wrong size on Logger Shield

by pgrunwald on Wed Dec 26, 2012 4:49 pm

Thanks!
pgrunwald
 
Posts: 33
Joined: Tue Jul 14, 2009 9:32 pm