SD / MMC card are SPI interfaced , it should not be a problem in interfacing it....
check this
**broken link removed**
yes i checked that link and got some idea...There after, i collected some more information about the mmc initialization via spi.
Those information is given below:
MMC Initialization
1. Set chip select pin
2. Clear chip select pin
3. Pass 0xff, 0x40(for initialize), 0x00 (4 times- for reset), 0x95 (check error sum) to the MMC card
4. Read from MMC.
5. Check receive data is equal to 0x01
6. If received data is not equal to 0x01 then repeat step 6 up to 1000 times.
7. If 0x01 not received go to step 15.
8. Set chip select pin
9. Clear chip select pin
10. Pass 0xff, 0x50(for block select), 0x00 (2 times- for reset), 0x 02, 0x00(block length,512) 0xff (check error sum) to the MMC card
11. Read from MMC.
12. Check receive data is equal to 0x01
13. If received data is not equal to 0x01 go to step 15
14. If 0x01 received send a message to LCD
15. Set chip select pin
16. If card not initialized send a message to the LCD or send data through USART
MMC Data Write
1. Clear chip select pin
2. Pass 0xff and 0x58 (for write) to the MMC card
3. Write location number to the MMC card
4. Read from MMC.
5. Check receive data is not equal to 0x05 then repeat step 4 up to 100 times.
6. Before 1000 times the 0x05 is received go to step 8
7. If received data is equal to 0x00 send a error message
8. Set chip select pin
9. Write data to the MMC card
10. After 512 data writes, select the location number (location number+512) and go to step 1.
MMC Data Read
1. Clear chip select pin
2. Pass 0xff and 0x51 (for read) to the MMC card
3. Write location number to the MMC card
4. Read from MMC.
5. Check receive data is equal to 0x00 then repeat step 4 up to 1000 times.
6. After 1000 times go to step 8
7. If received data is equal to 0x00 send a error message
8. Set chip select pin
9. Read data from MMC card
10. Send these data to the computer through USART
11. After 512 data writes, select the location number (location number+512) and go to step 1.
There after, i wrote a program (below)
Code:
#include<pic.h>
#define _XTAL_FREQ 20e6
#define CS RC2
unsigned char t,rec,dat,tempbuf,readdata;
unsigned int count;
void usrt_init()
{
TRISC6=0;
TXSTA=0b00100110;
RCSTA=0b11010000;
SPBRG=10;
}
void string(const char *p)
{
while(*p)
{
TXREG=*p;
while(TRMT==0);
p++;
}
}
void spi_init()
{
TRISC4=1;
RC2=0;RC3=0;RC5=0;
TRISC2=TRISC3=TRISC5=0;
SSPCON=0b00100000;
SSPEN=1;
SMP=1;
CKE=0;
CKP=1;
}
////////////////////////////////////////////////////
void spi_write()
{
SSPBUF=dat;
while(BF==0);
tempbuf=SSPBUF;
}
////////////////////////////////////////////////////
void spi_read()
{
SSPBUF=0xff;
while(BF==0);
readdata=SSPBUF;
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////
void mmc_init()
{
CS=1;
CS=0;
dat=0xff;
spi_write();
dat=0x40;
spi_write();
dat=0x00;
spi_write();
dat=0x00;
spi_write();
dat=0x00;
spi_write();
dat=0x00;
spi_write();
dat=0x95;
spi_write();
spi_read();
count=0;
while((count<1000)&&(readdata!=0x01))
{
spi_read();
count++;
}
if(count>=1000)
{
string("FIRST ERROR");
}
else
{
CS=1;
CS=0;
dat=0xff;
spi_write();
dat=0x50;
spi_write();
dat=0x00;
spi_write();
dat=0x00;
spi_write();
dat=0x02;
spi_write();
dat=0x00;
spi_write();
dat=0xff;
spi_write();
spi_read();
count=0;
while((count<1000)&&(readdata!=0x01))
{
spi_read();
count++;
}
if(count>=1000)
{
string("SECOND ERROR");
while(1);
}
{
CS=0;
string("INITIALIZATION COMPLETE ");
}
}
}
main()
{
TRISD=0;
PORTD=0;
usrt_init();usrt_init();
spi_init();__delay_ms(10);
spi_init();__delay_ms(10);
spi_init();__delay_ms(10);
mmc_init();
while(1)
{
CS=0;
dat=0xff;
spi_write();
dat=0x58;
spi_write();
dat=0x01;
spi_write();
d:spi_read();
if(readdata==0x05){string("data write mode activated ");while(1);}
else {string("trying ");goto d;}
}
}
Now i am getting "SECOND ERROR".
Since i am not getting "FIRST ERROR" i think my connections are right.
What should i do?