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

fat32

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



Joined: 18 Nov 2008
Posts: 278
Location: Athens, Greece.

View user's profile Send private message

fat32
PostPosted: Thu Feb 11, 2010 3:11 pm     Reply with quote

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: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Feb 11, 2010 10:22 pm     Reply with quote

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: 278
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Fri Feb 12, 2010 9:23 am     Reply with quote

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: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 12, 2010 9:47 am     Reply with quote

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