View previous topic :: View next topic |
Author |
Message |
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
fat32 |
Posted: Thu Feb 11, 2010 3:11 pm |
|
|
Hi,
In the examples folder of the tcpip there is a "fat" folder which contains a "fat_pic.c" and a "fat_spi.c" file. These are for reading the mpfs web page stored in a sd/mmc card.
Anyway I hooked a microsd card on a 18f4520 and with a little effort I was able to create, open and read files from the card!
Now, everything is OK as far as I read txt files. But the main goal here is to read wav files and play them back. When I try to read wav files the resulting data is -1,-1,-1,-1 which means the end of file!
I thought it is because the wavs are signed so I saved them as unsigned but nothing changed.
I need some help on this or any other working fat32 code.
Any help is welcome. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Thu Feb 11, 2010 10:22 pm |
|
|
I have not looked at the CCS driver however, my guess is you are reading data into an array (a string) and then treating it like a string. The problem is that you can expect binary data to include 0x00 which is a terminator for a C string. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
georpo
Joined: 18 Nov 2008 Posts: 281 Location: Athens, Greece.
|
|
Posted: Fri Feb 12, 2010 9:23 am |
|
|
Thanks for the reply. Here is part of the code.
I think that you are right but what can I do to treat the incoming data as binary?
code:
char filename[20];
int8 data;
FILE fstream;
sprintf(filename, "/test.wav");
if(fatopen(filename, Read, &fstream)!=GOODEC) {
printf("\n\rERROR OPENING FILE %s",filename);
while(1);
}
else
printf("\n\rFile %s open OK.\n\r",filename);
while(data!=EOF){
data=fatgetc(&fstream);
putc(data);
}
printf("\n\rEnd of file.");
while(1); |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Fri Feb 12, 2010 9:47 am |
|
|
There are two problems.
Data is never initialized so it is possible it will fail the initial test of the while loop.
This is a text mode function. Testing the value of a single character read to see if it is equal to some predefined EOF value. In binary data, such as a wav file, data will be interpreted incorrectly as EOF.
As already mentioned, I am not familiar with this CCS code so maybe someone else can help. For a binary data stream I would expect as a minimum you could use the file length to determine EOF or your read function would return an error code indicating EOF. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|