SD card library?


Closed Thread
Results 1 to 23 of 23
  1. #1
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68

    Default SD card library?

    Hi All,

    Is there a library for reading/writing files on SD card?

    Thank you

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


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Wow! Thank you Mackrackit, will try. I was afraid may have to use another language which I always try to avoid...

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


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Hello Macrackit,

    Thank you very much for the very good data logging sample! Also thank you for attaching the file as the link http://www.melabs.com/resources/samples/pbp/sdfs3.zip seems to be no longer available (page not found)

    Best regards

  6. #6
    Join Date
    Oct 2007
    Location
    Vancouver, BC, Canada
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    ________________
    KV

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


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Quote Originally Posted by KVLV View Post
    And you only had to search as far as post #2 of this thread
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Oct 2007
    Location
    Vancouver, BC, Canada
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Quote Originally Posted by mackrackit View Post
    And you only had to search as far as post #2 of this thread
    oh, already posted.
    ________________
    KV

  9. #9
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Makrackit, KVLV, thanks again, I really enjoy SDFS3.zip and http://www.picbasic.co.uk/forum/cont...USB-SD-LOGGING

    Alexey
    Last edited by Alexey; - 15th December 2011 at 02:58.

  10. #10
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Hello Mackrakit,

    The code you advised works just fine, I only have one issue - when I reset MCU my program can not reinitialize the SD card until I replace it. Is this something related to the card itself or correct software should do it? I use SDC_UseHardSPI = FALSE if this matters

    Than you,

    Alexey

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


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    I will guess that the SD card is not booted fully before your code tries to access it.
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    tried to add pause at start and it did not help, but then I learnt that I was resetting the controller at the time when the card is being accessed and this was hanging the card. Adding indication when not to reset helped

  13. #13
    Join Date
    Jan 2012
    Location
    colombo,srilanka
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Hi all

    i also have been working with sd filing system with number of lang: including pic basic and hi-tec c . all of them worked very well with proteus simulation environment(isis). but all of them were very unstable when i build them in practical world. Can anyone give me some tips to make them stably working?? ive used home made p.c.bs for my systems. Are there any specific potential dividing resisters to be used at port outputs and sd card input? ive been using 1k + 10k combination.any caps mabe?? im using pic 18f 2550 for all of my sd card based systems.

  14. #14
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    How much current sd card is draw when writing file?

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


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Run the whole system at 3.3 volts and then you will not have to use dividing resistors.
    Dave
    Always wear safety glasses while programming.

  16. #16
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    I meant on power supply pin.
    I'm waiting for test pcb to arrive from manufacturer....

  17. #17
    Join Date
    Jan 2012
    Location
    colombo,srilanka
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Quote Originally Posted by mackrackit View Post
    Run the whole system at 3.3 volts and then you will not have to use dividing resistors.
    Thanks, but will pic 18f2550 can run on 3.3v? because its hard to find any other lo power versions in our electronic shops.

    thanks.

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


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Yes, the 2550 and 4550 will run on 3.3 volt. See the link in post #4.

    Use a 4MHz external OSC and the chip can be PLL'ed to 48 MHz if needed. The electrical section of the data sheet shows what can be done.
    Dave
    Always wear safety glasses while programming.

  19. #19
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    I've been playing with this code for a couple days now with no joy. My biggest question revolves around my SD card. I have several. They ALL have 9 pins. As does the socket on my development board. Yet the code seems to be written for an SD card with 12 pins? I have no "Write Protect" or "card detect" lines, nor can I find reference to them anywhere but on this site. Do I fake the pins? High or low?
    To further add to the confusion, I'm using an 18F2550 and I need the hardware serial port. Since a pin is shared with the hardware SPI port, I'm trying to use SHIFTOUT / SHIFTIN. Things seem to be getting to the SD card, but it does not reply (I get 0's).
    Am I missing something simple? Response from an INIT is 6...

  20. #20
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Hi Charlie,

    I use PIC18F25K22

    and do it this way:

    '--------------SD CARD----------------------

    'SD_DO VAR PORTC.0
    ' Alias PIC pins and registers for SD/MMC cardYTE
    SDI VAR PORTC.0 ' SPI data in SD #7 (SD_DO)
    SDI_TRIS VAR TRISC.0 ' SPI data in direction
    SCL VAR PORTC.1 ' SPI clock SD #5
    SCL_TRIS VAR TRISC.1 ' SPI clock direction
    SDO VAR PORTC.2 ' SPI data out uSD #3
    SDO_TRIS VAR TRISC.2 ' SPI data out direction
    SD_CS VAR PORTC.3 ' SD card chip select uSD #2
    SD_CS_TRIS VAR TRISC.3 ' SD card chip select direction

    'SD_CD VAR bit: SD_CD = 1 PORTC.0 ' SD card detect
    'SD_CD_TRIS VAR TRISC.0 ' SD card detect direction

    INCLUDE "SDFS.PBP"
    SDC_UseHardSPI = FALSE ' Use hardware SSP port for SPI.

    ...


    all lines in the SDFS.PBP that refer to the card write protection, card inserted and so on things I disabled like this:

    ' Subroutines for communicating with an SD/MMC card
    ' Subroutine to initialize SD card pins
    InitIO:
    SD_CS = 1 ' SD card not selected.
    SD_CS_TRIS = 0 ' Output SD card chip select.
    ''' SD_CD_TRIS = 1 ' Input card detect.
    ''' SD_WE_TRIS = 1 ' Input write protect.
    SDO = 1 ' Start SPI data out high.
    SDO_TRIS = 0 ' Output SPI data out.
    SDI_TRIS = 1 ' Input SPI data in.
    SCL = 1 ' SPI clock idles high.
    SCL_TRIS = 0 ' Output SPI clock.
    Return




    ' Subroutine to initialize hardware SSP for SPI at less than 400kHz
    OpenSPIM:
    If (SDC_UseHardSPI) Then
    ''' SSPSTAT = 000000 ' Sample at middle of data output time, Mode 1, 1: Transmit on idle to active clock transition.
    ''' SSPCON1 = 010010 ' SPI master mode, clock = Fosc/64, Mode 1, 1: Clock idle high.
    ''' SSPEN = 1 ' Enable hardware SPI port.
    Endif
    Return




    ' Subroutine to initialize hardware SSP for SPI at full speed
    OpenSPIMFast:
    If (SDC_UseHardSPI) Then
    ''' SSPSTAT = 000000 ' Sample at middle of data output time, Mode 1, 1: Transmit on idle to active clock transition.
    ''' SSPCON1 = 010000 ' SPI master mode, clock = Fosc/64, Mode 1, 1: Clock idle high.
    ''' SSPEN = 1 ' Enable hardware SPI port.
    Endif
    Return




    I use micro SD card. You might notice the pins used for card interface are shared with ICSP, but the card can not work while the programmer is connected. Programmer probably does not like such neighbor too (one needs pull up and the other has internal pull down, but it works.

    I could not attach the file - error happens - "invalid file" I do not know why, but you see the idea - just comment everything you do not use

    Best regards,

  21. #21
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Thanks, Alexey.

    I had done something similar, but tried your solution anyway. Still not working. It's possible my SD card is simply not happy with this initialization sequence - I can see clock and "data in" pins (Pic "data out") moving as they should (as best as I can judge with LED's) but the device does not respond. If I put a pullup on it's "data out" line (PIC "data in") I can read FF, otherwise I read 00. To me this means the card is not driving the line.

    I know I should post my code, but it's about 8K. After your post, I did try the SDFS3.PBP program with tweaks for my hardware specifics and it did not run either. I might have to go back to a 24L series device...

  22. #22
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Hi Charlie,

    You need to have pull-ups on both, data and clock lines

  23. #23
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: SD card library?

    Just FYI, I finally resolved the issue... turns out my development board has a schematic error. I guess I should have bought the expensive one . Wait... considering it just cost me several days of my life - looks like I did.

Members who have read this thread : 1

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