View previous topic :: View next topic |
Author |
Message |
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
ex_fat.c: nothing to see on the PC (solved) |
Posted: Wed Apr 08, 2015 9:40 am |
|
|
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: 9221 Location: Greensville,Ontario
|
|
Posted: Wed Apr 08, 2015 10:33 am |
|
|
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: 19499
|
|
Posted: Wed Apr 08, 2015 11:08 am |
|
|
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. |
|
|
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Fri Apr 10, 2015 12:42 am |
|
|
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
But: when try to open this file with the editor win7 tells me the file is corrupted.
Please - another piece of help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Apr 10, 2015 7:18 am |
|
|
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
|
|
Posted: Mon Apr 13, 2015 1:04 am |
|
|
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
|
|
|
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
Posted: Mon Apr 13, 2015 5:51 am |
|
|
Thanks for the hint, that's it!
Problem solved! |
|
|
electr0dave
Joined: 10 Aug 2014 Posts: 24
|
|
Posted: Mon Apr 13, 2015 7:19 am |
|
|
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! |
|
|
|