SDFilesystem ReadSector()

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

SDFilesystem ReadSector()

Post by liak » Mon Mar 02, 2009 10:33 am

Dear all, esp Steven,

I am trying to modify the ReadSector subroutine in SDFilesystem.
I understand that standard read procedure of reading SD card will have to be done in sector of 512bytes. I am wondering if it is possible to read only, say 200 bytes rather than a full 512bytes. Will the SD card controller generate error if we attempt to do so? Let's say I modify it in this way:

Code: Select all

{
********************************************************************************
* Name    : ReadSector (PRIVATE)                                               *
* Purpose : Read a full sector from card to buffer.                            *
********************************************************************************
}   
Sub ReadSector(pSector As LongWord, pBuffer As Boolean = True)
Dim TimeOut, Error As Byte
Dim Index As Word
#if SD_REINIT_SPI = TRUE
   ReInitSPIPort()
#endif
....
....
 Index = 0
            If pBuffer Then
               FSR0 = @Shared.CurrentSectorBuffer
               Repeat                            // Read data block
#if SD_SPI = SW                                  // Software SPI version - use SendByte
                  POSTINC0 = ReceiveByte()
#elseif SD_SPI = MSSP                            // MSSP version - use inline routine to optimise speed
                  SSPIF = 0 
                  SSPBuffer = $FF 
                  Repeat 
                     ClrWDT 
                  Until SSPIF = 1 
                  POSTINC0 = SSPBuffer
#endif
                  Inc(Index)
               Until Index = 200            // Instead of 512 bytes
            Else
               Repeat                            // Don't read data block
                  ReceiveByte()
                  Inc(Index)
               Until Index = 200           // Instead of 512 bytes
Regards,
Liak

normnet
Posts: 55
Joined: Mon Jan 01, 2007 6:32 pm

Post by normnet » Tue Mar 03, 2009 3:05 am

Obvious answer but I would complete the sector read saving only the
first 200 bytes.

Norm

liak
Registered User
Registered User
Posts: 195
Joined: Fri Oct 05, 2007 12:26 am

Post by liak » Wed Mar 04, 2009 7:06 am

Dear norm,

Thanks. I have checked the standard for SDCard by SanDisk. It would generate error. :oops: wishful thinking and didn't checked the datasheet.

Thanks for the suggestion. I would just skip or dump whatever that is read after the 200bytes.


Regards,
Liak

Post Reply