msp430 fatfs
Hello!
You can find a lot of documentation on the net which explains how the FAT file
system (16 or 32) are organized.
So apparently you have solved the raw read and write problem, and you are
able to find the MBR, etc... This is the physical layer.
Now here is how the FAT works (I am writing a new version of FAT16 for
MSP430 now).
All what follows is validfor FAT16 because I am in it, but the method is very
similar for FAT32.
First, you have to find the MBR.
1. Read the very first block of the sd card (sector 0). Find the location 1C6 and
read the location of the MBR. In my case, it is F9.
2. Read the block 0xF9.
You will get a bunch of data from which you can read the card characteristics
like bytes per secor, sector per cluster, reserved sectors, etc...
3. Form this data set, calculate the location of the root sector. And you can
also calculate the beginning of the data area.
4. Read the root sector, which is a collection of file records. A file record is a
32-byte record (therefore in a 512-byte sector, you will get at most 16 records).
In your case, one of these records should begin with "test****txt0".
The * represent a space (0x20) and the 0 represents the 0x00 value.
You have also some information about the creation date, modification date,
etc...
5. Once you found your file record, look at the 2 bytes at offset 26 (bytes 26 and
27). They represent the location of the first cluster of your file. Careful, it's
written in little endian. Therefore (supposing your file "test.txt" is the only
one in the root dir), these 2 bytes will be 02 and 00. But it does not mean 0x0200
but 0x0002. Little endian means "little end comes first".
Careful: in the beginning of the card (management areas), all the calculation
units are in sectors. But in the data area, you have to take clusters into account.
One cluster is a bunch of sectors (32 in the case of the 1GB card I am using).
6. Now you know that your file starts at the second cluster. So go past the root
directory, you will therefore be in the data area, and find the cluster # n-2,
therefore 0 in this case. It will be the cluster that follows the root.
Your test.txt will be there.
For instance, if you wrote the file test.txt with a plain text editor (notepad), and
if this file contains "hello", then you should see:
0005C200 48 45 4C 4C 4F 00 00 00 00 00 00 00 00 00 00 00
The left part is the absolute address in the SD card.
7. Last thing:
Before getting a headache, you should first:
- Format your card
- Write a single file named "test.txt"
- Download winhex
- Choose "open disk" and choose your sd card in the menu.
- Then navigate in the card's data until you (more or less) understand
what all that means.
Have fun!
Dora.
Deepak350 said:
Hi banjo,
I had given up the SD card project the past few days, I'm at it again. I will first tell you my progress. I formatted the card and wrote a 'test.txt' file onto the SD card from my desktop. So far I could detect the card and check if it is FAT formatted successfully. However the problem is that I'm not able to read a file from the SD. Please help me with that. Hope I'v provided enough information.
Best Regards.