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

CCS SD CARD ex_fat.c problem PIC18f

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



Joined: 23 Jul 2012
Posts: 2

View user's profile Send private message

CCS SD CARD ex_fat.c problem PIC18f
PostPosted: Mon Jul 23, 2012 11:10 am     Reply with quote

Hi All,

I am having some issues with regards to SD card reading/writing and pic uC.

General Setup details:
CCS Compiler v4.133
Windows 7 x64
SD Card 2Gb Formatted as FAT32
MCU = PIC18f452

I have edited my mmcsd and fat drivers as andrew details in these threads.

I have a voltage divider setup for 5V to 3.3V conversions for the SD card input. I have a regulated 3.3V Vdd input for the SD card and I am doing up conversion to 5V of the 3.3V DO to the uC with a transistor level converter. I have pullups on the 3.3V lines.

I can initialize and communicate between PIC and SD card fine. From the PIC I can create a file, append data to it and then see it when I display the folder contents. I can even create a new directory, a file within that directory, append data to it and it is visible within display_folder_contents. These files are then visible on the PC.

Well, then it's working, you say, and why are you posting here?

Interestingly, there are a few things I CANNOT do:
    -Create a file/folder on the SD card with the PC and have it visible from uC
    -Create file/folder on SD card with uC, reboot and then open or view that file.
      -File must be created with mk_file, opened and written sequentially. Even though this file will be visible on PC the uC cannot find it (or any other file on the card) after it has rebooted


I have tried formatting as FAT16 and FAT32 from windows PC. I have formatted via uC. Tried many things.

Again, I can read and write files/folders on the filesystem from uC, though they are only visible during that session, even though they are persistent and maintain visibility on PC.

Any idea, or suggestions?

Thanks for any help. I didn't post code because it is only a slightly modified version of ex_fat.c. The modifications I made to the drivers are exactly as detailed by andrewg.

-Seth
_________________
Thanks for reading. Maybe I will put something witty here, sometime. Stay posted.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Jul 23, 2012 12:36 pm     Reply with quote

While I have not worked with that code, I would suggest using a program on the PC that allows you to look at the raw directory (hex data) and see if you see anything obvious that is causing the issue. I ran into something like that years ago in basic where I could (not realizing I did it) create a file name with lower case letters while the old version of the OS could show the files, but when I tried to do something to them, it kept giving me "file not found" when I could plainly see it in the directory listing (where the case was masked from my view).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
PicMePicMe



Joined: 23 Jul 2012
Posts: 2

View user's profile Send private message

PostPosted: Mon Jul 23, 2012 8:42 pm     Reply with quote

Mikey,

Thanks for the suggestion and for offering your help, I appreciate it. Unfortunately, I am but a pygmy standing on the shoulders of giants and, as such, do not know if what I am seeing in the hex editor makes sense with respect to what the uC is expecting. I will post what I have found based on your suggestions.

In the uC I can print out the address that my pic18f thinks is the root directory (1064960). This address, to my untrained eye appears correct based on the image below. Does it appear correct to you. There are other files that I added to root to test to see if uC would see them (second image - these don't show up in root directory of hex editor and they are not visible from uC). I purposefully kept file names under 8 characters but doesn't make a difference (I have tried long filenames as well).


Explorer


Same symptoms: I can create the file, then open it and append data to it, BUT ONLY if it is done sequentially.
For instance:
WORKING CODE (the functions are taken exactly from ex_fat.c so I will not post the individual functions.
Code:

   MakeFile(filename);
   
   AppendFile(filename,"the test worked - written to by PIC");
   AppendFile(filename,"Second append - written to by PIC");
   PrintFile(filename,0);
     
   disp_folder_contents(g_CWD);


I can verify on the PC that the file is created and contains the data I would expect.

The uC, though cannot see, read, append to or enumerate files or folders that already exist on the SD card. Even if the uC created the file in the first place. If I run the above code and then run the following code:
Code:

   AppendFile(filename,"the test worked - written to by PIC");
   AppendFile(filename,"Second append - written to by PIC");
   PrintFile(filename,0);
     
   disp_folder_contents(g_CWD);


I get an error saying that the: "Error opening file" and there are no files or folders printed out via disp folder contents.

Any ideas anyone??? Seems very strange to me. As if the act of creating a file initializes something somewhere so that the uC can open the freshly created file. Though I have tried to create a dummy file, and open an existing file and that does not work. So I am at a loss.

Thanks!!!
-Seth
_________________
Thanks for reading. Maybe I will put something witty here, sometime. Stay posted.
JJones



Joined: 23 Aug 2012
Posts: 1

View user's profile Send private message

SD card
PostPosted: Wed Aug 29, 2012 8:18 am     Reply with quote

Hello PicMePicMe.

I am doing a project where i want to store data sequentially. Can you direct me to your sources?

Best regards,

Josué Jones
_________________
Josué Jones
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