read all files on SD card

General discussion on mikroC PRO for AVR.
Author
Message
cris52
Posts: 7
Joined: 15 May 2012 12:08

read all files on SD card

#1 Post by cris52 » 15 May 2012 12:20

Hello,

I'm using the XMEGA for AVR and planning to make an mp3 player. Perhaps someone can give me mikroC code example for reading all files on sd and listing them on tft or putting them in a .txt .

Thanks in advance.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#2 Post by janko.kaljevic » 16 May 2012 09:19

Hello,

Please take a look at this topic.
It demonstrates how to do DIR and save result in a txt file:
http://www.mikroe.com/forum/viewtopic.p ... ir#p183856

Best regards.

cris52
Posts: 7
Joined: 15 May 2012 12:08

Re: read all files on SD card

#3 Post by cris52 » 16 May 2012 10:44

I've already tried to modify that example before , unsuccesfully. it's in mikroBasic i think?
I need example for mikroC.
i'm new to this. can you please give an example in mikroC?

thanks.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#4 Post by janko.kaljevic » 16 May 2012 11:08

Hello,

Code: Select all

char buffer[256];
char fhandle, i;

void fillbuffer(char ch){
  buffer[i] = ch;
  i++;
}
....
    Mmc_Fat_Dir(&fillbuffer);
    buffer[i] = 0;

    fhandle = Mmc_Fat_Open("newfile.txt", FILE_APPEND, 0xA0);
    Mmc_Fat_Write(buffer, strlen(buffer));
Best regards.

cris52
Posts: 7
Joined: 15 May 2012 12:08

Re: read all files on SD card

#5 Post by cris52 » 16 May 2012 14:37

thanks, this is my code:

Code: Select all


/*************************************************************************************************
*read_dir
**************************************************************************************************/

char buffer[256];
char fhandle, i, ch;


void fillbuffer(char ch){
  buffer[i] = ch;
  i++;
}


/**************************************************************************************************
* main function
**************************************************************************************************/

void main(){


  InitMCU();
  DrawMP3Scr();
  
  MP3_Start();
  MP3_Test(&ucMP3_run_test);
  
   fillbuffer(ch);
    Mmc_Fat_Dir(&fillbuffer);
    buffer[i] = 0;

    Mmc_Fat_Assign("test.doc", 0xA0);
    mmc_fat_rewrite();
    Mmc_Fat_Write(buffer, strlen(buffer));

}


there are supposed to be 20 files on the sd card, and the result i get is

" 1:63:62 Dp
--A----- 2492289 28/04/2007 00:12:40 THCE51~1.MP3
----LSHR 31/15/2107 31:63:62 Dm
--A----- 2806177 28/04/2007 00:08:58 TH9B22~1.MP3
--A----- 3326954 28/04/2007 00:11:34 SOUND.MP3 "

what am missing or what am I doing wrong?

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#6 Post by janko.kaljevic » 17 May 2012 09:11

Hello,

At the moment our FAT library supports short file name format (DOS8.3).

Please try to rename your files on the SD card according to this standard and try again.

Best regards.

cris52
Posts: 7
Joined: 15 May 2012 12:08

Re: read all files on SD card

#7 Post by cris52 » 20 May 2012 07:43

Hello,

does fat32_dir() work the same way, and is there any way to read LFN?


thanks.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#8 Post by janko.kaljevic » 21 May 2012 10:25

Hello,

FAT32_dir works the same way.
At the moment LFN is not supported in FAT32 library.
Only short (8.3) format.

Best regards.

cris52
Posts: 7
Joined: 15 May 2012 12:08

Re: read all files on SD card

#9 Post by cris52 » 21 May 2012 11:53

thank you.

when i try the same routine, but instead of mmc_fat_dir(&fillbuffer), I use fat32_dir(&fillbuffer), it says, "to many actual parameters".
and also mmc_fat_open doesn't work for me, for both fat and fat32 libraries, it says "undeclared identifier".

thanks.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#10 Post by janko.kaljevic » 22 May 2012 11:41

Hello,

DIR function in FAT32 library has default function which is used for output.
Please check FAT32_Put_Char function in help file.

You can declare this function as I did in my example with fillbuffer function.

You are getting undeclared identifier because you need to include proper header file in your project.
With regular FAT library add:

Code: Select all

#include "__Lib_MmcFat16.h"
Just like we did in our example.

Best regards.

cris52
Posts: 7
Joined: 15 May 2012 12:08

Re: read all files on SD card

#11 Post by cris52 » 05 Jun 2012 19:13

hello,

I was wondering if there is a solution for the floating point results that is displayed in the calculator example for the mikromeadia for xmega board. for example 56/2 returns 27.99999, instead of 28. I am looking for a mikroC solution.


thanks.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#12 Post by janko.kaljevic » 06 Jun 2012 10:23

Hello,

I believe that this is fixed in latest version of the VisualTFT Tool.

You can also try with following calculation:

Code: Select all

         result = first_operand + second_operand;
         IntToStr((int)ceil(result), Label6_Caption);
Best regards.

cris52
Posts: 7
Joined: 15 May 2012 12:08

Re: read all files on SD card

#13 Post by cris52 » 06 Jun 2012 16:01

hello,

yes, but if the result is float not integer, as in 55/2 = 27.5, ceil function will make it 28. This does'nt happen all the time and only with random numbers. for example 1/4 returns 0.25, but as said before 56/2 always returns 27.99999.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: read all files on SD card

#14 Post by janko.kaljevic » 13 Jun 2012 14:06

Hello,

You can try to implement some algorithm for rounding results.
It is known that float point numbers have issues with accuracy and this kind of number representation may occur.

Best regards.

alikilavuz
Posts: 13
Joined: 15 Feb 2014 17:00

Re: read all files on SD card

#15 Post by alikilavuz » 16 Feb 2016 14:41

Hi ,

I am using EasyPIC V7. with SmartMP3 Board and Fat32 Lib.

Fat32 Lib commands doesn't return LFN File Names but returns 0x0F attributes with empty file names.

I don't want to get LFN File Names but i just want to play them without knowing names.(For example StartCluster value)

Can i do this with Mikroe FAT32 Lib and how?

Best Regards,

Post Reply

Return to “mikroC PRO for AVR General”