void SYSTEM_Initialize (void){ TRISFbits.TRISF12=1; //SDI Input TRISBbits.TRISB14=0; //SDO Output TRISBbits.TRISB15=0; //SCK Output } void USER_SdSpiConfigurePins_1 (void){ OSCCON = 0x46; // IOLOCK specific command sequence (p.222) OSCCON = 0x57; // IOLOCK specific command sequence (p.222) OSCCONbits.IOLOCK = 0; // Unlock PPS // Deassert the chip select pin LATBbits.LATB11 = 1; // Configure CS pin as an output TRISBbits.TRISB11 = 0; //Initialize the SPI RPINR20bits.SDI1R = 32; //SDI (F12) ANSFbits.ANSF12 = 0; //Digital input RPOR14bits.RP29R = 8; //SCK (B15) RPOR7bits.RP14R = 7; //SDO1 (B14) OSCCON = 0x46; // IOLOCK specific command sequence (p.222) OSCCON = 0x57; // IOLOCK specific command sequence (p.222) OSCCONbits.IOLOCK = 1; // Unlock PPS //enable a pull-up for the card detect, just in case the SD-Card isn't attached // then lets have a pull-up to make sure we don't think it is there. IOCPUBbits.IOCPB2=1; // Configure CD pin as an input TRISBbits.TRISB2 = 1; ANSBbits.ANSB2 = 0; //Digital input // Configure WP pin as an input TRISBbits.TRISB3 = 1; ANSBbits.ANSB3 = 0; //Digital input }