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,
Bookmarks