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

ex_fat.c: nothing to see on the PC (solved)

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



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

ex_fat.c: nothing to see on the PC (solved)
PostPosted: Wed Apr 08, 2015 9:40 am     Reply with quote

Hello,
I adapted the example to my HW -design (PIC18F46K22 CCS Version 5.040, FAT32).
Data can be written on the card and it can be read back by using the terminal program.

(I wrote individual data to different 2GB SC cards and read it back. Each card responds with its individual data written; so this seems to work.)

But:
- I do not see anything on the cards when I put them into the PC (Windows 7)
- If I write data on the cards with the PC this content is not shown when I prompt the dir command.
(Card- reader of the PC works, Data can be read back).
It seems to be a formatting problem.
What is the correct setup so data be exchanged between PC and µC using the SDCard?
Thanks!


Last edited by mdemuth on Mon Apr 13, 2015 5:51 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 10:33 am     Reply with quote

What is the interface between PIC and SD card ?

Either show schematic(use 3rd party hosting site) or describe details(power, pullups, etcs.)


Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 11:08 am     Reply with quote

Have you applied the MBR fix?.

<http://www.ccsinfo.com/forum/viewtopic.php?t=43402&highlight=mmc>

This is needed if the card is formatted on the PC.

Basically the CCS drivers, if you let them format the card will format it like a floppy. The PC will then work fine. However if the card is formatted in a PC it'll be formatted like a HD, and needs the MBR fix.

It'll be writing the data, but to the wrong place on the card without this.

Sounds as if you have the hardware working right. Smile
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 10, 2015 12:42 am     Reply with quote

The Bugfix solved the problem - thanks a lot!
I know can dreate directories and files (and they are visible on the PC).
The next step is to fill a txt-file with data. Again problems:
- I use append to write data into the file.
- The file gets larger, I can see it in on PC explorer Very Happy

But: when try to open this file with the editor win7 tells me the file is corrupted. Sad

Please - another piece of help.
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Fri Apr 10, 2015 7:18 am     Reply with quote

You are closing the file after you have written the data?.

How is the txt file being created?. Problem here is that a txt file created by some programs may use Unicode encoding, not simple ASCII....
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 13, 2015 1:04 am     Reply with quote

I am using the ex_fat.c example provided by CCS (V5.040).
The only modification I made so far is the adaption to the HW (PIC18F46K22 and my schematics) and the MBR fix.
To append data I am using:
Code:

/*
Summary: Append a string to a file.
Param: The full path of the file to append to.
Param: A pointer to a string to append to the file.
Returns: None.
Example Usage: \> append "Log.txt" "This will be appended to the end of Log.txt"
Note: A "\r\n" will be appended after the appendString.
*/
void AppendFile(char *fileName, char *appendString)
{
   FILE stream;
   printf("\r\nAppending '%s' to '%s': ", appendString, fileName);
   if(fatopen(fileName, "a", &stream) != GOODEC)
   {
      printf("Error opening file");
      return;
   }
   
   fatputs(appendString, &stream);
   fatputs("\r\n", &stream);

   if(fatclose(&stream) != GOODEC)
   {
      printf("Error closing file");
      return;
   }
   printf("OK");
}


Feedback from Terminal:
//>
append ABCD.txt 12345XYZ Appending '12345XYZ' to '//ABCD.txt': OK
Size of the file ADCD.txt is enlarged by each call.
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Mon Apr 13, 2015 4:34 am     Reply with quote

Hello ...
Change the files for these link and test again ...

http://www.ccsinfo.com/forum/viewtopic.php?t=53787

First is "format xxxx" then create the file and check on the computer ...
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 13, 2015 5:51 am     Reply with quote

Thanks for the hint, that's it!
Problem solved!
electr0dave



Joined: 10 Aug 2014
Posts: 24

View user's profile Send private message

PostPosted: Mon Apr 13, 2015 7:19 am     Reply with quote

I also spent some time around this problem ...

I recently had to do the same and I lost a lot of time.

So I decided to let it all together for future reference ...


I am happy to help!
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