Page 1 of 2

SDFileSystem

Posted: Wed Jan 16, 2008 7:08 pm
by Widgetman
Hi Steven,

In the routine listed below as I using the filesize() routine correctly ?
I am expecting a long word back, but what I don't understand is does the filesize() routine only work if I have a file open so it knows which one I want ?
Thanks




If SD.OpenFile("file.bin") = errOK Then

repeat
// Do Something
// Get FileSize

MyFileSize = SD.FileSize() // My filesize now holds the size of file.bin

until SD.EOF

Posted: Wed Jan 16, 2008 9:41 pm
by Steven
Yes, you are right about having to open a file before using FileSize. In your example above though you open the file, then enter a repeat loop until you get to the end of the file, but without incrementing your way through the file by reading from it - this will lock you in the repeat loop. Try something like below:

Code: Select all

If SD.OpenFile("file.bin") = errOK Then 
   MyFileSize = SD.FileSize() // My filesize now holds the size of file.bin 
   SD.CloseFile
EndIf

Thanks Steven

Posted: Thu Jan 17, 2008 1:15 am
by Widgetman
Thanks for the help :D

Posted: Wed Jan 30, 2008 6:24 pm
by dman776
Is it possible to have more than one file open with the SD module?

The scenario that I'm looking to do is like the following...

1) open a data file and read bytes from it that would be sent to the USART
2) open an MP3 file on the SD card and stream it to a VLSI audio decoder

The data files would typically be anywhere from 2K to 20K in size (so, they won't fit in a RAM buffer).

Thanks

Posted: Wed Jan 30, 2008 6:31 pm
by Steven
Not as the module stands at the moment. It's one of my future plans and one that I've been thinking about in the last few days as it happens. When I ported the code to Swordfish I built in a fair amount of code that should make this relatively easy. I'm not promising when I'll do it, but it's in the pipeline. For now, could you get away with opening one, buffering some of it, closing it then opening the other, using FSeek to quickly move to the next point in the file, and so on...? I guess it may not be fast enough if you are sending an MP3 file?

Steve

Posted: Wed Jan 30, 2008 10:54 pm
by dman776
Steven, thanks for the info/update!

Posted: Thu Jan 31, 2008 6:26 pm
by dman776
I am also having trouble reading a file from my SD card.

Code: Select all

If SD.OpenFile("SEQ_01.DAT") <> errOK Then
        // get delay and setup timer
        vByte=SD.ReadByte()
        if SD.RWError = False then
            SetDelay(vByte)
            LCD.WriteAt(2,1,Convert.DecToStr(vByte))
        else
            LCD.WriteAt(2,1,"RWError")
        end if
    Else
       LCD.WriteAt(2,1,"!open")
    EndIf
My file byte data like this (shown in hex): FF 01 02 FF 04 05 .... etc

However the vByte variable always returns a "0".

any thoughts?

Posted: Thu Jan 31, 2008 6:48 pm
by Steven
Could you also post the code you use to initialise the card (SD.Init) and let me know if you are using the MSSP or software routines. Also, what Xtal setting?

Posted: Thu Jan 31, 2008 6:51 pm
by dman776
Here is the init using MSSP...

Code: Select all

While Not SD.Init(spiOscDiv16)
        LCD.WriteAt(2,1,"Insert card")
Wend
resonator is 10Mhz using the HSPLL (40Mhz)

Posted: Thu Jan 31, 2008 7:14 pm
by Steven
Ooops, missed an error in your first code. It should be:

Code: Select all

If SD.OpenFile("SEQ_01.DAT") = errOK Then
not:

Code: Select all

If SD.OpenFile("SEQ_01.DAT") <> errOK Then
Does that fix it, or is there more to it?

Steve

Posted: Thu Jan 31, 2008 7:23 pm
by dman776
Doh!
You're brilliant! That was the probem.

Thanks Steven.

Posted: Fri Feb 01, 2008 10:50 pm
by dman776
Steven,
Are you thinking of adding a ReadNBytes() function to the SD module?
I think it would be nice to be able to buffer a chunk of data.

I'm thinking of something like this (from the ISRRX module):

Code: Select all

Public Function ReadNBytes(ByRef pRetBuf As Byte, ByVal pCount As Word) As Word
   Dim vByte As Byte
   Dim RetBuf As POSTINC0

   FSR0 = AddressOf(pRetBuf)
   Result = 0
   While pCount>0
      vByte = SD.ReadByte()
      RetBuf = vByte
      Inc(Result)
      Dec(pCount)
   Wend
   RetBuf = 0
End Function

Posted: Fri Feb 01, 2008 11:06 pm
by Steven
Yes - I can add this. I should have a new version out soon, so I'll add it to it. I'm currently looking at how easy it would be to add FAT32 support.

Posted: Thu Feb 21, 2008 8:02 pm
by Steven
I'm now at the point of adding this to the SD module, but am not sure if you are wanting to read N bytes into an array or a string - I can't find the example you are referring to in the ISRRX module. Let me know and I'll add it.

Thanks,

Steve

Posted: Thu Feb 21, 2008 8:29 pm
by dman776
Hi Steven,
It would add N bytes to the array pRetBuf.