This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Reading a Wave file from microSD

Sir, I am having trouble reading wave files from a microSD card. 

I wanted to know if SSI functions are required and if yes what is the syntax .

Can i directly use FATF functions to access the files or is there any other way.

Please help.

  • Hi Arun,

         Provide more relevant details. See sticky posts in this forum for guidance.

         There is a sd_card example program at Tivaware that you can review.

    - kel

  • Markel Robregado said:
    Provide more relevant details

    Some may wish for, "More relevant response, too."  (not a single, poster specific issue targeted - although the sd_card program (poster must hunt for it) is helpful)

    Such volume, "blanket responses" may not be fully representative of your best/most caring work...

    Note poster's, "I am having trouble" near kin to, "Not working" was allowed to pass - uncommented.  (less gratuitious salutation - more poster details - as always - remain required)

  • Sir,
    I have one wave file by the name "abc.wav" stored in a microSD card. i have included a fatf library and declared various file type variables like
    FRESULT rc; /* Result code */
    FATFS fatfs; /* File system object */
    FIL fil; /* File object */
    DIR dir; /* Directory object */
    FILINFO fno; /* File information object */
    UINT i;
    BYTE buff[50]; /* Buffer to store data read from SD Card*/

    i have then used following code line for opening the file:
    rc=f_open(&fil,"abc.wav",FA_READ);
    if(rc != FR_OK)
    {
    LCDWriteString("Error Opening");
    }
    and i see " Error Opening " in 16x2 LCD .

    Also the reason i am using LCD for display is that my serial monitor(putty) is not displaying anything .
    Is there any possible problem in my Break Out Board??

  • I believe that, "KISS" will best assist you - to that end suggest the following:

    a) Might that wave file be more complex - thus harder to process & successfully open?  And - how do you know that the wave file is correct/proper - and fully suitable for fatf file format?  (I don't know these answers - but questions seem logically correct)

    b) Suggest - at least in the beginning - that you shift to smallest, simplest, "known good" fatfs file you can find - and attempt to, "Open and then further process it."  If you cannot open even a simple, proven file - attacking a more complex one has little, "odds of success" does it not?

    c) You speak (now) of a, "Break Out Board" yet that appears nowhere described/detailed.  Of course you're in a hurry - & frustrated - but we helpers are distant - know "nothing" of your set-up.  (perhaps helps you to think more from your "remote helpers'" perspective - we don't know you - nor your project - must rely entirely upon you to detail/describe...)

    Poster Kel directed you to a good beginning program - had you read/reviewed that?  Perhaps there are others - which further build your knowledge - have you made a fair search for these?

    You are ahead of many as demonstrated by the fact that you've gotten your Lcd to work.  (many cannot)  Appears that bit more read/review of SD Card and specific fatfs examples is a logical, "next step."

  • Hello Arun

    What board do you have? If you're using fatfs library from Tivaware, you should take a look at files in "port" folder (Tivaware\third_party\fatfs\port), and set the defines with the correct SSI in use. Then, before any "f_open" or "f_read" functions, you should call "f_mount" with your file system object. Something like this (I'm using the last fatfs update):

    FATFS FatFs;    /* Work area (file system object) for logical drive */
    FIL fil;        /* File object */
    
    FRESULT fr;     /* FatFs return code */
    UINT br;    /* File read count */
    
        fr = f_mount(&FatFs, "", 1);
    
        if( fr == FR_OK )
        {
            if( f_open(&fil, "fread.txt", FA_OPEN_EXISTING | FA_READ) == FR_OK )
            {
                BYTE buffer;
    
                // Read one byte at time and print at terminal
                while(1)
                {
                    fr = f_read(&fil, &buffer, 1, &br);
                    if( (fr != FR_OK) || (br == 0) ) break;  // Error or EOF...
    
                    UARTprintf("%c",buffer);
                }
                // Close file!
                f_close(&fil);
            }
            else UARTprintf("Fail to open file!\n");
            //
    
            // Unmount SD Card
            f_mount(NULL, "", 1);
        }
        else UARTprintf("Fail to mount! Check SPI!\n");

  • @Pedro,

    Our posts just crossed.  (and yours far more precise/targeted than mine)

    That's quite detailed - appears quite good.  Do you know if the wave file format fits correctly w/in fatfs file format?  (I don't.) 

    Great that you directed poster directly to file source and especially helpful is your precise listing of the "order" in which poster should make his function calls.  Clearly you've provided him a most useful (and usable) start...

  • Hello cb1, thanks a lot! I'm not an expert, but if I can help... why not? =)

    Well, I worked with wav files before, in some Arduino projects... I stored some converted MP3 in a microSD, read the bytes (one bye one, with tinyfat library), and put them to work with a PWM routine. That's a very simple WAV player, lol. So I think it's ok with fatfs either.

    I don't know what Arun is planing, but there's a lot of information about WAV format on Internet, also very good examples!

  • @Pedro,

    You've a great attitude - and sharing your focused experience is a great benefit to any forum - again thanks.

    Again - you've given him a great, general, "heads-up" and should get him well on his way...

  • Ok i will first try to read simple text file. 

    Thanks a lot

  • I am using TIVA TM4C123G1H6PZ launchpad.And also i did mounting as well. No problem in mounting though.

    Still i will try again and get back to you. Thanks a lot