Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

FAT on MMC with just ONE file

Status
Not open for further replies.

kar2on

Member level 1
Joined
Jul 30, 2005
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,728
avr mmc fat

Hi, I've designed a hardware project to write data from a PIC to an MMC card, however now I need to write the data to MMC with a FAT file system. I'm using mikroC (freeware version) so I'm unable to use the fat file system commands. My project is simple, so I don't want to splurge US240 for a program just for one command.

Let me explain a bit about my project:-

I take in analog data, sample it and then store it in the MMC (512 bytes at a time)

So in the MMC card, there is one file, that grows 512bytes at a time.

How do I determine the starting location of the file, and how do I increase the file size . I downloaded the Microsoft Fat File System information, but nothing helps. I know the fat file table is at the beggining of the MMC, i know roughly which numbers they correspond to, but the numbers don't add up. Is it because the numbers are little-endian or something like that. Please help.
 

techie

Advanced Member level 3
Joined
Feb 5, 2002
Messages
839
Helped
58
Reputation
116
Reaction score
9
Trophy points
1,298
Location
Pakistan
Activity points
7,800
fat in mmc

Writing your own FAT file system is going to be very tough if not impossible. I suggest that you get some readymade FAT file system and port it for your application. There are many references in this forum on where to get the FAT file system.
 

kar2on

Member level 1
Joined
Jul 30, 2005
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,728
avr mmc library

I'm not looking to design my own FAT table, just use the one already there after a format .

I'll format the MMC via a card reader from windows...

then i'll work into creating the file system....

I also know I need to use chaining at the end of each 512 byte block... how do i do that ...
 

techie

Advanced Member level 3
Joined
Feb 5, 2002
Messages
839
Helped
58
Reputation
116
Reaction score
9
Trophy points
1,298
Location
Pakistan
Activity points
7,800
mikrobasic fat32

Did you search edaboard for FAT file system files. There are many references
 

Zedman

Full Member level 6
Joined
Oct 13, 2003
Messages
331
Helped
9
Reputation
18
Reaction score
6
Trophy points
1,298
Location
Hungary
Activity points
3,510
microchip an1003

Hi,

you have to read that FAT specification carefully, and you will see that:
(assuming a FAT32 formatted MMC card)

- you have to calculate the position of the FAT table and the root directory from several data bytes stored in the boot record, partition table etc,
- search for the filename you want in the root directory
- the directory record contains the starting cluster of the file

cluster == a branch of sectors (for example 4 or 8 etc)

After you found the starting cluster you can write sectors to that cluster on the disk. If you want to write more than a cluster (and you will:) than you have to allocate another (not used) cluster in the FAT table for that file. And you can write the next sectors to the newly allocated cluster and so on.

How the cluster chain works and how to allocate a new cluster is all written in that doc.

I strongly recommend Acronis Disk Editor or another disk editor and a card reader,
format to FAT place just one file on it (with 0 size), search it on the card with the disk editor,
find out bytes/sector sectors/cluster values and try to grow the file slowly and watch how the windoz allocates new cluster for the file.
Do it with nothing else on the disk/card and you'll see how it works.

Remember FAT32 stores the filename in unicode so try with a 8.3 filename first.

It's not really easy, but not impossible :)

Zed
 

banjo

Advanced Member level 2
Joined
Dec 24, 2005
Messages
651
Helped
127
Reputation
254
Reaction score
8
Trophy points
1,298
Activity points
8,064
mmc avr lib

I would use FAT16, not FAT32. The standard format for smaller size MMC cards is FAT16. Often people will reformat to FAT32 and it causes problems with many devices.

There is a free AVR library that you could port.

https://hubbard.engr.scu.edu/avr/avrlib/

Since you are working on a PIC, you mainly have to port the MMC IO stuff, the remainder of FAT should compile and run since it is not hardware specific.

From an AVR, I was able to open a FAT16 file, add data and then close the file. This was for a project that got discontinued, so I never went farther than proof of concept. However, after doing this, I was able to retrieve the data with a standard PC.

To help you figure out how FAT works, download a demo copy of WINHEX. This will allow you to view sectors on the MMC card. Remember the MMC controller makes the flash memory appear as a hard drive. The FAT tables are stored twice in memory after the bootloader. With the demo copy, you can only view. You cannot modify. However, this is enough to get hints on how FAT works.

Since you only need one file total open at a time, you can simplify or hardcode alot of stuff.

--- Steve
 

Zedman

Full Member level 6
Joined
Oct 13, 2003
Messages
331
Helped
9
Reputation
18
Reaction score
6
Trophy points
1,298
Location
Hungary
Activity points
3,510
an1003 microchip

banjo is right, you should use FAT16 instead. And you can write the file sequentaly no need to fragment it. (but you still have to maintain the FAT table)

Zed
 

gidimiz

Advanced Member level 1
Joined
Feb 3, 2005
Messages
427
Helped
124
Reputation
248
Reaction score
40
Trophy points
1,308
Activity points
5,157
mikroelektronika + mmc card

Hi,

PM me and I willl send you a Microchip project that has the FAT16 on it. Its part of the AN1003 from microchip that has the MMC on a pictail with the HPC DV board.
The code is for the Microchip C18 compiler, but you can change it a bit for your needs.

Good luck.
 

kar2on

Member level 1
Joined
Jul 30, 2005
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,728
avr sd lib

HI,
thanx for your help, Now i know roughly how FAT works. I decided (for simplicity) that working with just one version of FAT enough. I choose FAT12 since my MMC card is only 16MB . I know i need to to

1) First locate the directory table (there's only one directory)
2) Then find the file name and find the FAT entry.
3) Take the FAT entry and look at the corresponding sector in Free space.

Now i know to Append to this file i need to :
1)update the size in the directory folder
2)update the FAT TABLE ENTRY.

I discovered that if you, just initialized the FAT entry by creating one arbitarily large file in windows. You would get a FAT table initialized to locate all CONTIGUOUS memory locations.

Then if you reduce the size of the file, by chaging the directory table entry for size WITHOUT modfying the FAT. Windows would read the file properly.

So now I decided to initialize the FAT (either from Windows or the MCU) preferably Windows (using VB). THen I would just need 2 write cycles to append the file in the MMC, which is

1) Write the 512byte sector for appending.
2) Change the size in the directory table entry.

I want to know whether this approach would be possible. ANd whether anyone knows how to initialize the FAT in Windows (using VB). Or even using the MCU.
 

roadrunne

Newbie level 1
Joined
Mar 4, 2006
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,290
mikroelektronika mmc

hiya, i am trying to do a simmilar thing...i have the microchip AN1003 and am trying to modify it to do something very similar to what you ae doing.....how did u get on with this....if you could let me know that woudl be great!

thanks
Matt
 

kar2on

Member level 1
Joined
Jul 30, 2005
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,728
mmc+fat+avr

hmmm.... guess many people have asked me how I got this far.. so I'm going to post this up...

I'm using a PIC 18f452, and the mikroC freeware compiler.

You can download the mikroC freeware compiler from mikroelektronika.co.yu , mikroBasic or mikroPascal woul be beter if you're more familiar to those languages.

Next the libraries inside mikroC are really good, though the documentation is lacking. The forum on the mikroelektronika website is quite good.

mikroC has a great MMC lib, where a write to the MMC card is as simple as

MMC_write_sector(96,data);

Making life a million times easier.

mikroC actually has a MMC_FAT library that would make writing to the MMC a breeze but the problem is that the freeware version cannot compile beyond 2K assembly words and the MMC_FAT lib causes it to go beyond 2K assembly words. So unless anyone would like to share/give their mikroC license to me, I gotta figure this out. Other than that, I think mikroC is the best PIC compiler out there... even the freeware version is awesome, imagine the payware.
 

davenjose

Newbie level 4
Joined
Feb 12, 2008
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,322
mmc fat avr

hi there kar2on,i am currently on a project entitled Digital Altimeter using SD Card as storage.
i am writing a file (data) to mmc with PIC 18F452 using FAT system and mikroC as compiler.
the data that i am going to write on a mmc is from the reading of our pressure sensor that would be converted to an altitude by the PIC.

i would like to ask some advice on the code for this process (or the code).
i am using mikroC that provides library on mmc, but i am still a beginner and not very confident on my code.

is it possible that i could read or open the file on my mmc with a card reader to a PC after writing data to it?

please help, i really need to finish this project a short time from now.
thank you.
 

manish12

Advanced Member level 3
Joined
Nov 21, 2006
Messages
982
Helped
66
Reputation
132
Reaction score
33
Trophy points
1,308
Activity points
6,114
get mmc fat file name microbasic

mikroc mmc given lib example is not working with the given fig , i am using mmc 512m and sd of 512m.

any one have working project ! using mikroc ??
 

adm1

Junior Member level 1
Joined
Jan 5, 2010
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,381
hi kar2on

cud you please tell how to send data from a pic18f controller to mmc... i really help on this urgently,.. thanks in advance
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top