SD card library?


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    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,

  2. #2
    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...

  3. #3
    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

  4. #4
    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 : 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