SD card free memory calculation

Status
Not open for further replies.

CCD

New Member
Hi,
someone who has worked on SD cards can help me out here. I just completed my FAT32 routines for microSD card. I've got little problem with calculating the free memory of the card. When I check on my PC, windowsXP shows free memory as 806.240256 MB but my function is showing 806.395904 MB.
What I'm ding here is counting all the clusters marked as free clusters starting from the root cluster and then multiplying with sectorPerCluster and bytesPerSector. The difference is exactly equal to 36 cluster memory.
I thought may be windows is removing bad clusters, so i put a check for bad clusters also and subtracted it from total free cluster count, but the result is same (the program is not able to find any bad cluster, may be since the card is new).
And since i'm counting from root cluster only, the reserved clusters are already removed from the calculation.

here is the link to the post:
Design with Microcontrollers: SD Card Interfacing with ATmega8 (FAT32 implementation)

What can be the reason for this 36 extra clusters?

(I'm also checking the total memory, which perfectly matches with what is displayed by Windows)
 
Ever thought that maybe Windows could be wrong.
Maybe check the card with another OS just to be sure?
 
Ever thought that maybe Windows could be wrong.
Maybe check the card with another OS just to be sure?

Since my total memory count was exactly matching with Windows', I thought its free memory count also must be correct!!
 
Since my total memory count was exactly matching with Windows', I thought its free memory count also must be correct!!

What happens if you completely erase it? Does free memory = total memory and if so do windows and your code then agree?

Mike.
 
one correction, the extra cluster count is 38, not 36 (sorry, calculation mistake).
What happens if you completely erase it? Does free memory = total memory and if so do windows and your code then agree?
I just re-formatted the card and checked with windows (no files stored): total memory is 1013.809152 MB, free memory=1013.805056 MB and with my code, total memory is same as windows' but free memory is 1013.960704 MB. Still exactly 38 clusters!

The card free memory is becoming greater than the total memory. certainly, something is wrong with my code only, not with windows!
 
Last edited:
Problem solved yesterday!
I was counting 2 reserved entries in the first FAT sector and 36 extra entries in tha last sector (i was counting till the end of the last FAT sector, whereas I was supposed to count only till the entry related to the last data cluster).

thanks!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…