I've managed to get the precompiler working consistently, but I'm worried about the compilation not working if I the software for another project. For example, if another project does not require an SD Card then I see no reason to keep the precompiler on and so would need to disable it. However, for the past several hours the precompiler would not kick in even if the option was ticked in library manager. Anyway, it's working now.

As part of understanding the basics for the SD Card library I tweaked the program that was available in the HELP routine. I've included it below:

I've tried with _04, _16 and _64. I've tried to Print the Response at various places but nothing seems to help.


'*********************** SD Card Test

;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 18F26K22

Config_Start
FOSC = INTIO67 ;Internal oscillator block
PLLCFG = Off ;Oscillator used directly
PRICLKEN = On ;Primary clock enabled
FCMEN = OFF ;Fail-Safe Clock Monitor disabled
IESO = OFF ;Oscillator Switchover mode disabled
PWRTEN = OFF ;Power up timer disabled
BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
BORV = 190 ;VBOR set to 1.90 V nominal
WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
WDTPS = 32768 ;1:32768
CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
PBADEN = On ;PORTB<5:0> pins are configured as analog input channels on Reset
CCP3MX = PORTB5 ;P3A/CCP3 input/output is multiplexed with RB5
HFOFST = On ;HFINTOSC output and ready status are not delayed by the oscillator stable status
T3CMX = PORTC0 ;T3CKI is on RC0
P2BMX = PORTB5 ;P2B is on RB5
MCLRE = EXTMCLR ;MCLR pin enabled, RE3 input pin disabled
STVREN = On ;Stack full/underflow will cause Reset
LVP = OFF ;Single-Supply ICSP disabled
XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Debug = OFF ;Disabled
Cp0 = OFF ;Block 0 (000800-003FFFh) not code-protected
CP1 = OFF ;Block 1 (004000-007FFFh) not code-protected
CP2 = OFF ;Block 2 (008000-00BFFFh) not code-protected
CP3 = OFF ;Block 3 (00C000-00FFFFh) not code-protected
CPB = OFF ;Boot block (000000-0007FFh) not code-protected
CPD = OFF ;Data EEPROM not code-protected
WRT0 = OFF ;Block 0 (000800-003FFFh) not write-protected
WRT1 = OFF ;Block 1 (004000-007FFFh) not write-protected
WRT2 = OFF ;Block 2 (008000-00BFFFh) not write-protected
WRT3 = OFF ;Block 3 (00C000-00FFFFh) not write-protected
WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
WRTD = OFF ;Data EEPROM not write-protected
EBTR0 = OFF ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
EBTR1 = OFF ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
EBTR2 = OFF ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
EBTR3 = OFF ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Declare Xtal = 16
OSCCON = %01110110 ' 16Mhz INTERNAL OSC.
'Optimiser_Level = 3

Declare All_Digital = TRUE
Declare PortB_Pullups = OFF

TRISA = %10000000
TRISB = %11111111
TRISC = %10010011 ' RX PIN SHOULD ALWAYS BE INPUT

Declare LCD_Type 0 ' Type of LCD Used is Alpha
Declare LCD_DTPin PORTA.0 ' The control bits
Declare LCD_RSPin PORTA.5 ' RS pin on A4
Declare LCD_ENPin PORTA.4 ' E pin on A5
Declare LCD_Interface 4 ' Interface method is 4 bit
Declare LCD_Lines 4 ' 16x2 TYPE


'-----------------------------------------------------------

Dim SD_IO As Byte
Dim Response As Byte 'SD Card Response
' SD PIN DEclares
Symbol SD_CS PORTC.2 ' RC2 (ANY) >> CS (MMC Card) 'SPI CS to SD CS
Symbol SD_CLK PORTC.3 ' RC3 (SCK) >> SCK (MMC Card) 'SPI CLK to SD CLK
Symbol SD_DO PORTC.4 ' RC4 (SDI) >> DO (MMC Card) 'SPI DI to SD DO
Symbol SD_DI PORTC.5 ' RC5 (SDO >> DI (MMC Card) 'SPI DO to SD DI

Include "SDCARD_Lib.pbp"

'-----------------------------------------------------------
GoTo Over_Sub 'Jump over the subroutines
'-----------------------------------------------------------
Over_Sub:
DelayMS 200
Cls
'-----------------------------------------------------------
Main_Prog:
Print At 1,1, "INSERT SD OR MMC"
Repeat
Response = SD_Init_FS_MSSP SD_SPI_FOSC_16
Until Response = 0
Print At 2,1, Dec Response
'-----------------------------------------------------------
Open_New_File:
SD_File_Name = "TESTFILE" 'File Name, upper case only!
SD_File_Ext = "TXT" 'File Ext, upper case only!
Response = SD_Check_For_File 'Check if file exists already
If Response = 0 Then
Print At 2,1, "FILE EXISTS - STOPPING"
Stop
Else
Print At 2,1,"OPENING FILE"
SD_New_File 'Open new file
EndIf
'-----------------------------------------------------------
Write_To_File:
Print At 3,1, "WRITING TO FILE"
SD_IO_String = "SD/MMC Code by S Wright"
SD_Write_String_To_File 'Write SD_IO_String to file
SD_Write_Byte_To_File 13
SD_Write_Byte_To_File 10
'-----------------------------------------------------------
Close_File:
SD_Close_File 'Close file
Print At 4,1,"FILE CLOSED"
Stop

I've tried using OSCTUNE as read on the forums here, and tried setting the PLL x 4 to see if the _64 option would work. But that too came up negative.

I'm using a standard micro SD Card which is formatted for 16KB FAT, earlier it was set for 32KB but that didn't work either. Would the SD Library card use a switch that detects if the card is inserted or not, if yes, then I'm in trouble, I haven't designed for this

I'm running on 3v3 and so I've not included the resistors as shown in the HELP diagram which I believe is a voltage divider?

What am I missing?

Thank you for your time.

Regards

Terence