CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Writing a text file / data to a MMC card

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest PIC
Guest







Writing a text file / data to a MMC card
PostPosted: Thu Sep 27, 2007 2:02 pm     Reply with quote

Hi,

I would like a little advice from anyone out there please!

I am trying to improve on a project I have been working on. At the current time I store 8 bits of data (256) every second into external memory via i2r. Access to this data is via rs232 / hyperterminal. I am using a 16f877 running at 20Mhz.

My idea is to store this data onto a MMC card so all I have to do for access is unplug it from the hardware and plug it in to a pc to download the data from there.

Question 1: How hard is it to create a '.txt' file using c?

Question 2: Would it be easier to create the file first and then write the data to it?

Question 3: Is SPI the best way to go (or the only way)?

I have already looked into changing my hardware - this is no problem.

I have read into this in some detail - loading 512K per write, creating a FAT32 file... and have looked on the forum at other code to do the task. However, my knowledge of c is 4/10 and I would just like to understand the bare bone to start me off.

Any help would be great, thanks!

Guest PIC
mickent



Joined: 18 Feb 2007
Posts: 22
Location: TN, USA

View user's profile Send private message

PostPosted: Thu Sep 27, 2007 3:42 pm     Reply with quote

There is a good book on this subject.

USB Mass Storage by Jan Axelson

It covers MMC / SD cards as well as USB
_________________
Mick
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Sep 27, 2007 4:02 pm     Reply with quote

It is far easier to use a PIC such as PIC18F4620 with 3900 bytes of memory (pin compatible with PIC16F877). This makes it easier to maintain file buffers.

SPI is the easiest way to deal with SD interfacing - it is straight forward.

The key if the flexibility of the file system driver. With the appropriate driver, you open a file and perform byte by byte writes as and when required. The file driver is responsible to maintaining and flushing file buffers at 512 byte boundaries. This is the same as if you were developing under DOS - you open a file, write to the file and close the file - you do not need to be concerned with how the driver handles the process.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Fri Sep 28, 2007 1:52 am     Reply with quote

Theoretically you can use a stripped down version of a SD driver if you use 'preformatted' media (create a single large file with the PC spanning all the card, filled with 0xFF or whatever).
All you do with the PIC is to replace the data of this file (leaving the directory and the fat table intact). You can even use less than 512 bytes of RAM in the PIC if you are willing to sacrifice the rest of the blocks' data (ther're filled with 0xFF where not used for storage, so you don't have to buffer the unused part of the blocks in RAM, just write the 0xFFs back from a loop)
...but it think it is not worth the hassle, you rather change to a bigger PIC as others advised.
Guest 1
Guest







PostPosted: Tue Oct 02, 2007 6:49 am     Reply with quote

Quote:
Theoretically you can use a stripped down version of a SD driver if you use 'preformatted' media (create a single large file with the PC spanning all the card, filled with 0xFF or whatever).


What a good idea. Do you think that the single large file could be a text file that was previously created via a pc? If there was a known destination, it would be possible to get the code to structure the data before it was stored.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group