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 CCS Technical Support

problem with FAT.c functions

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

problem with FAT.c functions
PostPosted: Tue Dec 10, 2013 5:45 am     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 10, 2013 6:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 10, 2013 6:28 am     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 10, 2013 6:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 10, 2013 6:39 am     Reply with quote

The chip is on 3.3V! I can`t see any problem here!
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Dec 10, 2013 9:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 10, 2013 12:27 pm     Reply with quote

Can you explain about this MBR? I sought this patches! How to format my card properly?
Thanks!
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sun Dec 15, 2013 8:38 am     Reply with quote

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!
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