News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

SD Card DIR issue

Started by Wimax, Jan 17, 2025, 11:09 PM

Previous topic - Next topic

Wimax

Hello Everybody,

I have used the code given below several times to display the directory of a FAT32 SD.  It worked perfectly on custom boards with PIc24fj64gp202 and pic24hj128gp202, while I had problems never solved by switching to a pic24hj128gp204 (44 pin TQFP). Basically the same file is always displayed in an endless loop.
Now I have tried the same code on DSPic33CK256MP508 on Curiosity board (SPI HW at 10 MHz) and the problem is always present, but as in the previous cases, initialization, writing and reading to SD work perfectly..
I just can't figure out what is the source of the problem.


'----------------------------------------------------------------------------------------------------------------------------------------
' Transmit the disk directory to a serial terminal
'
Proc DirListing()

    Dim DirName   As String * 12
    Dim FileName  As String * 12
   
       
    While
        DirName = File_GetDir()                                            ' Look for directories
        If DirName_0 = 0 Then                                              ' Are there any more directories?
            While                                                          ' No. So...
                FileName = File_GetFile()                                  ' Look for files
                If FileName_0 = 0 Then ExitProc                              ' Exit when no more files
                MyFileName = Left$(FileName,8) + "." + Right$(FileName,3)
                HRSOutLn MyFileName, " : ", Dec File_dSize, " bytes"                                            ' Transmit the file name and its size
     Wend
        EndIf
        HRSOutLn DirName, " <DIR>"                                          ' Transmit the Directory name
    Wend

EndProc



trastikata

Hello Wimax,

try the modified version of the FAT32 library I posted on https://picgraphic.com/SDCard1.html I fixed some issues and additional commands. I remember there was an anomaly with the DIR function which I fixed, I can't remember what exactly but if you are interested you could compare the original and modified file.


Wimax

Hello Trastikata,

Thank you very much for the suggestion.
I compared the libraries and I think I finally found the problem. In the "FileSys24.inc" library, at the FAT_FindRootDirEntry procedure there is a Select/Case for the input variable pType which, in the case of the "Dir" command takes a value of two. In the code that appears after "Case 2" the assignments involving the variable containing the file name and extension were incorrectly reporting the variable FileName_Name rather than Global_sFileName.
Made the substitution now seems to be working correctly.

I think I finally solved a latent problem that I had been dragging around for months, thanks again !