|
|
View previous topic :: View next topic |
Author |
Message |
martind1983
Joined: 22 Mar 2013 Posts: 16
|
fatopen function with SD card writing |
Posted: Sun Mar 31, 2013 3:47 am |
|
|
Hi everybody.
I have question. I want to make data logger. The device should write data to SD card memory(in text form). I already found out every thing about SD card communication and I also found out, that I cannot write any data directly to root directory because there are not readable in OS (windows)
So I formated card in PC and created simple text file.
My question sounds. Can I open this text file on SD card (created in PC) by using function fatopen(char fname[], char mode[], FILE* stream)), when I lead parameter "char fname[]" as the name of my text file?
For example . First off I create variable "char FileName[] = "text.txt" and then I use it in fatopen function. Because when I try to build it, there is always error, that "a numeric expression must appear here" or "Attempt to create a pointer to a constant". I use mmcsd.c and fat.c libraries everything is included well and Before using faopen I also use fat_init function, but the result is the same. Do I have to first create file in my PIC (24F16KA102) by using function mk_file() or can I directly open the text file in my SD (creted in PC) by using function fat_open()?
Thank you very much for your help. Martin |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Mon Apr 01, 2013 4:00 am |
|
|
fatopen, does work, and do what you want.
I'd guess the problem might be the mode string, rather than the filename.
If you are using (say):
fatopen(FileName,"r",file);
then the problem is the "r", which is a constant string and can't be accepted.
Add the line
#device PASS_STRINGS=IN_RAM
up at the top of your code immediately after the processor include line.
Best Wishes |
|
|
martind1983
Joined: 22 Mar 2013 Posts: 16
|
|
Posted: Mon Apr 01, 2013 12:07 pm |
|
|
Thanks for hint.
I already found it before. But there was one different problem. I didn't notice, that compiler put g_mmcsd_buffer variable to reserve range of debbuger memory, but I solved this issue too.
Thanks again. Martin |
|
|
martind1983
Joined: 22 Mar 2013 Posts: 16
|
|
Posted: Tue Apr 02, 2013 4:49 am |
|
|
Hi Ttelmah.
I already tried to do all the changes you adviced me. Compiling was goog, compiler buit and linked program.
But fatopen() function always returns EOF value. I didn't understand your reply very well so I am asking you again. Can I open file (for example test. txt) which was created in windows after formatting SD card in windows directly from SD card using by fatopen() function or do I have to make new file in PIC MCU with the same name to be able open it by function fatopen().
Next I seem that the function fat_init is buggy too. First when I lead it before fatopen() it should load all necessary variables for FAT form, but when I debug program, I always see, that only first (sector 0) is loaded to g_mmcsd_buffer. There are some information, but I am not sure, that there are FAT table statements. Neither statements(like bytes per sector, sectors, root directory, sectors per cluster...) loaded to FILE variable doesn't seem to be good. I would just like to read file directly from SD card (without creating it in PIC MCU memory) to the stream by means of function fatopen();
Thanks for your help |
|
|
|
|
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
|