View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
problem with FAT.c functions |
Posted: Tue Dec 10, 2013 5:45 am |
|
|
Greetings! I want to use FAT.c driver from the ccs library. I`m using CCS v 4.134, MPLab v 8.91. First I loaded the files as ex_fat.c says. The complier says this row:
Code: |
sprintf(cur_fnum, "%u", fnum);
|
is invalid. So I changed it with sprintf(cur_fnum, "%2Lu", fnum);
I made a simple program:
Code: |
void main()
{
int status=0;
char file[]="test.txt";
status = fat_init();
status=mk_file("test.txt");
while(1)
{
}
}
|
Every time the SD card is initialized correctly => fat_init() returns 0!
But after that on of the functions for creating file:check_invalid_char(char) always returns error! I tried to pass the entire string to mk_file(), pointer to the char array, or the char array - no change. I don`t think test.txt is invalid file name!
What`s wrong here??
Thanks! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 10, 2013 6:17 am |
|
|
back to basics...
We need to know what HARDWARE you've got !
Which PIC, what MMC/SD card,compiler version,etc.
jay |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Tue Dec 10, 2013 6:28 am |
|
|
I'm using PIC18F66J60. CCS v4.134, MPLAB v8.91. The micro SD card is 2G. The hardware is properly connected and works. I made a test with mdd stack and everything is fine. But the mdd stack is very large and I need something simpler. So I decided to use this, but it seems it`s not so simple for usage.
I don`t expect errors in the library. Is that correct change in the sprintf()?!
And why the passed file name is invalid?!
I tried to make a directory but in this case the function drops into unending cycle...
Thanks! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 10, 2013 6:37 am |
|
|
OK...that's good news having working hardware! As you're aware there's a LOT of confusion about getting a 3V SD card to talk correctly to a 5V PIC.
Bad news...I can't help further, software wise, as I use USB flash drives with Vinculum chips.For my dataloggers it was cheaper,faster,easier, more reliable and 100% PC compatible.
Others do use the sd cards so I'm sure they'll offer support.
cheers
jay |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Tue Dec 10, 2013 6:39 am |
|
|
The chip is on 3.3V! I can`t see any problem here! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Tue Dec 10, 2013 9:30 am |
|
|
Put in the patches in the code library. Yes, they are still needed!....
<http://www.ccsinfo.com/forum/viewtopic.php?t=43417&highlight=fat>
and the link from the top of this.
You would get behaviour like this, if the card has been formatted using MBR, without the MBR fix. The standard code only accepts what are effectively 'floppy' formatted cards without a MBR.
Best Wishes |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Tue Dec 10, 2013 12:27 pm |
|
|
Can you explain about this MBR? I sought this patches! How to format my card properly?
Thanks! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sun Dec 15, 2013 8:38 am |
|
|
OK! I`ve made a few changes and now I have this:
Code: |
int status;
status=mmc_init();
status=fat_init();
status=mk_file("test.txt");
|
mmc_init() returns 0 - Returns: 0 if initiated correctly, Non-zero if initiation failed
fat_init() returns 1 - Returns: EOF if there was a problem, GOODEC if everything went okay.
BUT mk_file("test.txt") returns -1 and the sd card has to be formatted
mk_dir("name") returns 1, but the sd card is broken again!
It`s written
Note: fname must be in the form of /filename.fil for a file in the root directory
/Directory/filename.fil for a file in a subdirectory of root
/Directory/Subdirectory/filename.fil and so on...
So I tried with "/test.txt" and "/dir/" no change!
What am I doing wrong?
Thanks! |
|
|
|