MicroSD Cards and SDFS


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    mackrackit,

    I probably found a way to speed up the process of writing to the TFT display. If you write bytes to the SD card with values from 0 to 255, which is what I need

    Code:
    ' Write to file
    FOR I = 0 TO 255
        FAT_src[0] = I
        FAT_count = 1
        Gosub FSfwrite
        Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    NEXT I
    The program will sucessfully write 256 bytes to the txt file (a bunch of weird characters ). Now, when you try to read them back, it will always give you wrong values between the byte 210th and the byte 250th. However, by using only 7 bits in every byte (from 0 to 127) I can make my display work pretty fast. Have you seen this happen to you? Any comments?

    Now, for some strange reason my SD card is only working the first time after I reprogram the 18F4550 chip. The second time that I restart the chip I get the following errors for the FSinit

    Code:
    FAT_error = 6
    SDC_status = 2 
    SDC_response = 63
    I know what the FAT_error = 6 is (Init error), but the others I'm not sure what they are. Have you encounter these kind of errors before? Remember, it always works right after I reprogram the MCU. Any ideas?

    Thank you for all your help

    Robert

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Not sure about the writing problem.

    The errors.
    Open SDFS and about 70 lines down it has the errors listed. #2 is "card not present", #63 I do not see.

    But, to get around the problem I have this in my "SDINIT" routine.
    Code:
    IF (FAT_error = 6) THEN SD_MAIN
    Here is a snippet from my code template.
    Code:
    '###############################################
     SD_MAIN:
        TOGGLE PORTD.7
        GOSUB SDINIT
        GOSUB SDFILENAME
        GOSUB SDOPEN_W
        GOSUB SD_WRITE
        GOSUB SDCLOSE
     RETURN      '##############################################################
    SDINIT:
    ' FSInit initializes the card and reads all the preliminary information from it
    Gosub FSInit
    Serout2 PORTC.6, 16572, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
        IF (FAT_error = 6) THEN SD_MAIN
        If (FAT_error != 0) Then Stop
        ' Display card directory
        Gosub FINDfirst        ' Find first file on card
        While (FAT_error = 0)
            Serout2 PORTC.6,16572, [Str FAT_FileName\11, $d, $a]
            Gosub FINDnext    ' Find next file on card
        Wend
        RETURN
     '################################################################
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    mackrackit,

    Thank you for your help. I will try that as soon as I get out of work. I will keep you posted.

    Robert

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Speed between SDFS(FAT16) and SDFS32(FAT32) from the guy that modified SDFS for FAT32.
    Compared to SDFS, SDFS32 should access the SD cards at almost the same speed, maybe a few microseconds difference here and there.
    The speed difference really comes into play when dealing with large files. Each sector read or write has to traverse the entire FAT cluster chain. The larger the file, the longer it takes to access a sector.
    In other words, for example, writing 1 sector takes 1 ms. Appending a 2nd sector might take an extra 1.1ms, a third sector takes another 1.2ms, and so on.

    Kinda like writing a book. Only instead of turning the page to add another page of writing, each time you want to add another page of something, you have to close the book, reopen the book, and re-read thru everything you've already written to find the end, before you can start adding stuff again.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Code:
    '###############################################
     SD_MAIN:
        TOGGLE PORTD.7
        GOSUB SDINIT
        GOSUB SDFILENAME
        GOSUB SDOPEN_W
        GOSUB SD_WRITE
        GOSUB SDCLOSE
     RETURN      '##############################################################
    SDINIT:
    ' FSInit initializes the card and reads all the preliminary information from it
    Gosub FSInit
    Serout2 PORTC.6, 16572, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
        IF (FAT_error = 6) THEN SD_MAIN
        If (FAT_error != 0) Then Stop
        ' Display card directory
        Gosub FINDfirst        ' Find first file on card
        While (FAT_error = 0)
            Serout2 PORTC.6,16572, [Str FAT_FileName\11, $d, $a]
            Gosub FINDnext    ' Find next file on card
        Wend
        RETURN
     '################################################################
    mackrackit,

    Thank you. It worked. I wrote a loop

    Code:
    WHILE FAT_error = 6
         GOSUB FSInit
    WEND
    Robert

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default Upgrading to pbp 2.60

    Dave,

    I have my SDFS program working fine with PBP 2.50 thanks to your help . Now, I think it's time for me to upgrade to PBP 2.60. My main concern with the upgrade is that I think (I hope I'm wrong) that half of my programs won't work with the new PBP version. I know from reading other threads that I will need to modify the USB part of my programs.

    Now, what about SDFS; does it work with PBP 2.60? Or, do I need to make some changes or modifications to it? Have you tried SDFS with the new version?

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    PBP 2.60 and SDFS work fine together. I have not had to change anything.

    I do plan to try to make use of the ARRAY WRITE feature of PBP 2.60 with the next SD project. If that works like I think it will tehn the basic routines will be much cleaner. Imagine changing the SD write array length on the fly!!!
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    PBP 2.60 and SDFS work fine together. I have not had to change anything.
    Nice !! What about programming memory space? Is it true that PBP 2.60 compiles the program with less programming words in a more compact manner? SDFS takes many words of programming space. I think the FAT16 version takes around 12k words (I don't remember the exact number). Do you see any space utilization improvements with PBP 2.60?


    Quote Originally Posted by mackrackit View Post
    I do plan to try to make use of the ARRAY WRITE feature of PBP 2.60 with the next SD project. If that works like I think it will tehn the basic routines will be much cleaner. Imagine changing the SD write array length on the fly!!!
    Are you referring to the FAT_BUFFER_SIZE constant?

    Code:
    ' Create constants and variables used by the FAT subroutines
    FAT_BUFFER_SIZE	Con	MEDIA_SECTOR_SIZE
    I replaced its value from 512 to 16 bytes in my program because it was killing my 18F4550 RAM memory. I left MEDIA_SECTOR_SIZE equal to 512 like it should be.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do not really have a good comparison but looking at the LST files between to similar programs. I have 2.50 on one machine and 2.6 on another.

    The PBP 2.5 code is using 23196 Bytes
    The PBP 2.6 code is using 16220 Bytes

    Both are with an 18F4550

    This is the part I think ARRAY WRITE will be handy for
    Code:
    ' Write to file
        FAT_src[0] = "X"
        FAT_src[1] = "B"
        FAT_src[2] = "C"
        FAT_count = 3
        Gosub FSfwrite
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts