SDFileSystem

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

SDFileSystem

Post by Widgetman » Wed Jan 16, 2008 7:08 pm

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

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Wed Jan 16, 2008 9:41 pm

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

Widgetman
Posts: 136
Joined: Sun Dec 16, 2007 7:39 pm
Location: Florida

Thanks Steven

Post by Widgetman » Thu Jan 17, 2008 1:15 am

Thanks for the help :D

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Wed Jan 30, 2008 6:24 pm

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

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Wed Jan 30, 2008 6:31 pm

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

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Wed Jan 30, 2008 10:54 pm

Steven, thanks for the info/update!

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Thu Jan 31, 2008 6:26 pm

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?

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Thu Jan 31, 2008 6:48 pm

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?

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Thu Jan 31, 2008 6:51 pm

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)

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Thu Jan 31, 2008 7:14 pm

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

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Thu Jan 31, 2008 7:23 pm

Doh!
You're brilliant! That was the probem.

Thanks Steven.

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Fri Feb 01, 2008 10:50 pm

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
Last edited by dman776 on Thu Feb 21, 2008 8:27 pm, edited 1 time in total.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Fri Feb 01, 2008 11:06 pm

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.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Thu Feb 21, 2008 8:02 pm

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

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Thu Feb 21, 2008 8:29 pm

Hi Steven,
It would add N bytes to the array pRetBuf.

Post Reply