Hello,
I would like some assistance with storing information on a SD card in the format of a text file. This SD card is connected to a 8051 microcontroller. Communication with the card is done via the SPI. I'd really appreciate some sort of #include file or anything that lets me have access to functions such as fprintf and fscanf, fopen, fclose. Also if anyone can tell me weather FATfs (elm-chan.org/.../00index_e.html) files are ok to compile on a 8051.
This thread can now be closed I guess, as there really seems to be nobody that provides useful information. You ask me "new to what exactly" when I clearly explain what I have difficulties with ("I really do not understand some of the functions in ff.c and how they interact with the SD card (for example if I can simply add my own code to ff.c and use the defined functions without other complications, aside from port assignment maybe.)").
I do not understand how many of the functions included in ff.c are useful for simply creating and appending a string of characters to a file. I do not care about anything else other than being able to create a windows (xp, 7, vista whatever) recognizable file with an 8051 on a SD card.
My goal would be measuring some data for an extended period of time with the 8051 on the SD card, after which I would copy that data to my PC for further use. The PC and 8051 cannot be connected for most of the time (save maybe 30 mins per month), so I had to think of some way of saving a month's worth of data, and this is the first thing I thought about.
I would appreciate if someone who actually had to create some sort of "movable medium" (larger than 1MB) between a PC and 8051 offered insight. Otherwise just close the topic please and I'll try to figure it out.
The purpose of this forum is to discuss Keil tools & products - not to give free consultancy.
See: http://www.keil.com/forum/
If you want a consultant to help you with your project, try: http://www.keil.com/condb.
"You ask me 'new to what exactly'"
That is a perfectly reasonable question. Remember that nobody knows anything about you or your experience other than what you clearly and explicitly state in your posts.
In particular, we don't know if you are: new to any form of programming; new to the 'C' language; new to embedded systems; new to the 8051; new to dealing with file systems; etc, etc,...
"I clearly explain what I have difficulties with ("I really do not understand some of the functions in ff.c and how they interact with the SD card (for example if I can simply add my own code to ff.c and use the defined functions without other complications, aside from port assignment maybe.)"
No, that is not clear at all!
"I do not understand how many of the functions included in ff.c are useful..."
You keep saying you don't understand, but you have given no indication of having read any of the documentation at elm-chan.org/.../00index_e.html Each of the functions has a page documenting it, and many examples are available both on that site and elsewhere on the interweb.
" I do not care about anything else other than being able to create a windows (xp, 7, vista whatever) recognizable file with an 8051 on a SD card."
Clearly, a general-purpose library such as FatFs is going to contain more stuff than is going to be needed for any one specific task. Don't worry about it!
"I would appreciate if someone who actually had to create some sort of "movable medium" (larger than 1MB) between a PC and 8051 offered insight"
You should be able to find examples on the web; if you want someone to dedicate time specifically to doing it for you, that's a consultancy job.
Note that there are many low-cost development boards that come complete with an SD-Card socket & examples. If you want something "ready-to-go", that might be your best option...
It may sound trivial to append data to a text file.
But you need to load the information telling what file system type you have. And you need to locate the root directory. And you need to locate individual FAT chains in the FAT tables. And you need to find free clusters to append to the FAT chain whenever the file grows enough that the already mapped clusters are not enough for the new data.
And the need to write back the appended information. And the FAT chain changes. And any changes to the directory entry/entries involved.
Suddenly, you need quite a number of functions. You might be able to find "end-user" functions for mkdir/rmdir/delete/rename/... that you may be able to remove. But the large bulk of functions performs low-level operations that you normally never have to think about when your PC accesses and updates files on a floppy or a memory card or the HDD.
Thanks for your replies. It seems that being able to create PC recognizable files with the 8051 is really a lot of work. I'll get to it and maybe look into alternatives (loading data to PC via UART from time to time would be a viable option, but I really don't know if the 8051 has enough memory of it's own to save the 1000+ measurements I take during a month's time).
It's possible to store data on a memory card, EEPROM, ... without the use of any file system.
But then it is up to you to figure out how much area you have filled, so you know where to continue adding data.
For memory cards, the controller inside the card normally handles wear leveling. But you have to take care of any problems with power losses when you are busy writing data.
Yes, it is! And not just for an 8051.
It is quite a common misapprehension to assume that something which seems simple to the casual observer must be simple. As the old saying goes, it takes a great deal of effort to make something appear effortless!
This kind of underestimating is quite common when people are not familiar with embedded (especially small embedded) development - which is why it was important to know what you meant by, "new to this".
Having said all that, this should not be beyond the capabilities of a reasonable 8051 - as already noted, it has been done on an AVR.
"loading data to PC via UART from time to time"
That eases your 8051 development, while putting extra work onto the PC development. Only you can decide what represents the best compromise for your particular set of requirements & constraints...
"I really don't know if the 8051 has enough memory of it's own"
That really on what particular "8051" you are planning to use!
There are plenty of non-volatile memories that can easily be connected to a microcontroller.
In the absence of a file systm you will, of course, have to devise some means of your own for managing the storage...
Note that it is possible to use SD Cards as "raw" storage - without a file system...
I would really much rather store data on the SD card without complications coming from having to figure out FAT32 functions, just as long as I can later read that data so I can send it to the PC via UART. Basicly I need the 8051 (C8051F040 specifically) for it's ADC convertor. The converted data needs to be stored somewhere so that I can later access it and download it into a PC for further analysis. If I would do this on a PC, I would just use a pointer to a struct and treat that array in a FIFO way. What worries me is that this micro-controller really doesnt have enough memory to store 1000+ entries in such an array and I would like some tips as to how I can overcome this problem.
this micro-controller really doesnt have enough memory to store 1000+ entries in such an array it has (with an external RAM) 64k bytes of data storage AND with a bit of trickery I have made a device with a '51 and 2Mbyte of data storage
if that would be enough, you can get (NXP, SILabs, others?) '51 chips with 8kb of internal RAM
Erik
It's really not that complicated - once ChaN has done most of the work for you!
FatFs gives you just a couple of dozen functions - and, as already noted, many (most?) of those are not relevant to your simple application.
The functions you requested are there: f_open, f_close, f_write, f_putc, f_puts, f_printf, etc...
If you do it all yourself, you will still end up having to write equivalent functions anyhow.
And you will have to delve into the arcane world of the SD Card SPI protocol, and implement that yourself.
"I need the 8051 (C8051F040 specifically) for its ADC"
But why an 8051? Plenty of microcontrollers have on-board ADCs these days!
Since the SD Card part seems to be the big obstacle to you, why not look for a board that comes complete with SD Card socket & examples, and work from there...?
What I specifically have to store is a time stamp (from a RTC) and 2 int values every 1 minute for a month, which comes to about 30*24*60 = 43200 entries. Also this has to be versatile enough to be able to store 4 months or more if the user so desires. This seems too big for any solution other than a few MB of storage. My focus is making sense of that data, so any solution ideea that solves the storage and transfer issues as quickly as possible would be greatly appreciated.
While that is becoming a more and more obvious solution, I've only had experience with the 8051 uC and have already purchased it. Originally I had hoped for an easy way to add extra storage space to it as the rest is solvable (interfacing UART and such). The SD approach was also a suggestion from an aquaintance and I've come here in hopes of finding if there are other more convenient and easy to implement ways to store data.
"Since the SD Card part seems to be the big obstacle to you, why not look for a board that comes complete with SD Card socket & examples, and work from there...?"
I'd second that. You can go to plenty of on-line stores and buy really good little STM32 based boards for really small amounts of money. A lot have SD slots, extra memory, plenty of connectors, examples etc.
So it sounds like this is a 1-off?
Is it a student project?
The most logical approach for storing your data in case you do not want to use a memory card with a file system on it, is to use a SPI-connected EEPROM. They have much simpler SPI protocol than the SPI protocol used for SD memories.
But if you have already fixed the required hw for interfacing with a SD card, please go ahead with the referenced library. SPI in itself is not complicated, and it is mainly the SPI that must be mapped from the original processor.
you cn get directly addressable 2Mbyte flash chips for <$3. with data banking it will be a matter of straight writes, no FAT, no ..., no ....
Thank you for your answers. I will definitely look into those flash chips as they seem to be exactly what I need.