Greetings all, i hope everyone is well...
I havn't posted here in a long time, i've not hit problems i couldn't solve till now... 
First time playing with SPI, so, i may have a noob mistake...
Ok, would love to read and write files to SD using 18F46K22 @ 64MHz so since the 46K22 is 'almost' pin compatible with the 4550 i thaught i'd start with what already works befor writing my own.
I renames SDFS to SDFS16 because i have the fat32 version to which is called SDFS32... just so their was no confusion...
I'm aware the 46K22 has two hardware SPI ports, the necessary register changes have been made.
Here is my code with the include.
Code:
@ __config _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_ON_1H & _FCMEN_ON_1H & _IESO_ON_1H
@ __config _CONFIG2L, _PWRTEN_ON_2L & _BOREN_OFF_2L & _BORV_220_2L
@ __config _CONFIG2H, _WDTEN_ON_2H & _WDTPS_32768_2H
@ __config _CONFIG3H, _CCP2MX_PORTC1_3H & _PBADEN_OFF_3H & _CCP3MX_PORTE0_3H & _HFOFST_OFF_3H & _MCLRE_INTMCLR_3H
@ __config _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
@ __config _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
@ __config _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __config _CONFIG6L, _WRT0_OFF_6L
@ __config _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@ __config _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
@ __config _CONFIG7H, _EBTRB_OFF_7H
OSCCON = %01110000
OSCTUNE.6 = 1 ;PLL enable
ANSELA = %00000000
ANSELB = %00000000
ANSELC = %00000000
ANSELD = %00000000
ANSELE = %00000000
TRISB = 255
TRISC = 0
PORTC = 0
TRISD = 0
PORTD = 0
TRISE = 0
PORTE = 0
TRISA = 0
WPUB = 255
IOCB = 255
Define OSC 64 ' Set clock speed
;SDFS defines
' Alias PIC pins and registers
SD_WE Var PORTA.4 ' SD card write protect
SD_WE_TRIS Var TRISA.4 ' SD card write protect direction
SD_WE_used var bit 'flag to determine if WE is used or not
SD_WE_used = 0 'SD_WE not used
SDI Var PORTC.4 ' SPI data in
SDI_TRIS Var TRISC.4 ' SPI data in direction
SCL Var PORTC.3 ' SPI clock
SCL_TRIS Var TRISC.3 ' SPI clock direction
SD_CS Var PORTA.5 ' SD card chip select
SD_CS_TRIS Var TRISA.5 ' SD card chip select direction
SD_CD Var PORTB.4 ' SD card detect
SD_CD_TRIS Var TRISB.4 ' SD card detect direction
SD_CD_used Var Bit 'flag to determine if CD is used or not
SD_CD_used = 0 'SD_CD not used
SDO Var PORTC.5 ' SPI data out
SDO_TRIS Var TRISC.5 ' SPI data out direction
SSPEN Var SSP1CON1.5 ' SSP enable
WCOL Var SSP1CON1.7 ' SSP write collision
BF Var SSP1STAT.0 ' SSP buffer full
SSPIF Var PIR1.3 ' SSP interrupt flag
PAUSE 100
INCLUDE "SDFS16/sdfs.pbp"
SDC_UseHardSPI = TRUE
;DEFINE NO_SOFTWARE_SPI
DEFINE LCD_DREG PORTD ' LCD data port
DEFINE LCD_DBIT 0 ' LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTE ' LCD register select port
DEFINE LCD_RSBIT 0 ' LCD register select bit
DEFINE LCD_EREG PORTE ' LCD enable port
DEFINE LCD_EBIT 2 ' LCD enable bit
DEFINE LCD_RWREG PORTE ' LCD read/write port
DEFINE LCD_RWBIT 1 ' LCD read/write bit
DEFINE LCD_BITS 8 ' LCD bus size 4 or 8 data bits
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 2000 ' LCD Command delay time in us
DEFINE LCD_DATAUS 50 ' LCD Data delay time in us
LCDOUT $FE, 1, "FSINIT"
PAUSE 1000
:MAIN
GOSUB FSINIT
IF FAT_ERROR > 0 THEN
LCDOUT $FE, $80, "FSINIT ERROR"
LCDOUT $FE, $C0, DEC FAT_ERROR, " ", Dec SDC_status, " ", Dec SDC_response," "
ELSE
LCDOUT $FE, $80, "FSINIT OK "
LCDOUT $FE, $C0, DEC FAT_ERROR, " ", Dec SDC_status, " ", Dec SDC_response," "
ENDIF
PAUSE 100
GOTO MAIN
So, how do i have the hardware, first off i'm using plug board...
Two SD cards are old ones, i plugged them into my PC and formatted them to FAT16 before i soldered on some sip pins. (stop cringing)
Pic and LCD running from 3.3V so connections are direct...
Pull ups on SDI, SDO and CLK lines... (no huggies)
For diagnostics i placed some LEDs inline with the pull up 1k resistors so i could see they flash. this includes the CS line...
On the LCD it said FSINIT ERROR then 2 6 0
so thats FAT_ERROR = 2, SDC_STATUS = 6 and SDC_RESPONSE = 0
In the SDFS file, SDC_STATUS 6 is labeled as initialisation error which isn't helpfull since it was doing the initialisation subroutine when it errored... SDC_RESPONSE i have no idea what this refers to, is it the status byte returned by the card?
If so, i swapped SDO and SDI around between straight and crossover just incase and same symptoms...
So, I'd appreciate any help as both cards do the same.
Thanks (bangs head on wall)
Bookmarks