kristt2001
New Member
hi all, i am stuck with interfacing the pic18f with a microSD card. all i want to do is read and write to a text file.
i am using SPI mode, with
hardware connections:
DI -> RC5
DO -> RC4
SCK -> RC3
code so far:
void MMC (void){
unsigned char SPI_data;
unsigned char SPI_Read[10];
unsigned char SPI_Write[10] = "MICROCHIP";
TRISCbits.TRISC3 = 1;
TRISCbits.TRISC4 = 0;
TRISCbits.TRISC5 = 1;
PORTCbits.RC3 = 1;
PORTCbits.RC4 = 1;
PORTCbits.RC5 = 1;
Nop();
OpenSPI(SPI_FOSC_4,MODE_01,SMPMID);
SSPCON1 |= SPI_FOSC_16;
SSPBUF = 0x00;
while(1)
{// SPI_data = ReadSPI();
putsSPI(SPI_Write);
if(DataRdySPI())
{
getsSPI(SPI_Read,10);
}
}
CloseSPI();
}
however, it isnt writing to the SD.
can anyone help.
i am using SPI mode, with
hardware connections:
DI -> RC5
DO -> RC4
SCK -> RC3
code so far:
void MMC (void){
unsigned char SPI_data;
unsigned char SPI_Read[10];
unsigned char SPI_Write[10] = "MICROCHIP";
TRISCbits.TRISC3 = 1;
TRISCbits.TRISC4 = 0;
TRISCbits.TRISC5 = 1;
PORTCbits.RC3 = 1;
PORTCbits.RC4 = 1;
PORTCbits.RC5 = 1;
Nop();
OpenSPI(SPI_FOSC_4,MODE_01,SMPMID);
SSPCON1 |= SPI_FOSC_16;
SSPBUF = 0x00;
while(1)
{// SPI_data = ReadSPI();
putsSPI(SPI_Write);
if(DataRdySPI())
{
getsSPI(SPI_Read,10);
}
}
CloseSPI();
}
however, it isnt writing to the SD.
can anyone help.