Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

About MMC Card Read/Write

Status
Not open for further replies.

conkhicon

Advanced Member level 4
Joined
Aug 31, 2004
Messages
107
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Activity points
1,015
mmc pic read write

Dear all,
I developing PIC 18F8720 project use MMC with hardware SPI function in MCU interface, I had successfully to do reset and initialize the MMC and Read OCR, CSD Register OK, and may be read-singleBolck(CMD17) OK (Status return OK but don't know data is true),
but when i want to write-block (CMD24) to the MMC, the response-data is strange, it is 0x07 (the correct one is 0xE5). any one can help me, what mistake?? (I use KingMax and Sandisk Card).
Block Size = 512Bytes, address is boundary of 512
If I use Nokia,Seimen MMC Card and I only Write OK (belong to status return)
and read failure.
 

cmd24 spi

I´ve only got strange responses from SD/MMC when I missed a certain step.
Can you describe the exact sequence you are using to issue a CMD24 and perform the write?
 

sandisk card response 0x07

#define BLOCK_LEN 512
unsigned char readBlockMMC(unsigned long int DWAddr,unsigned char *pdes)
{
extern unsigned char tmpkd[];
unsigned char localRD;
unsigned char commandResponse;
unsigned char dataToken;
unsigned int localc;

SetCSSPI();
WriteSPI(0xff); // Dummy
ClearCSSPI(); // Card Active
writeCMD(17,DWAddr,0xff); // READ COMMAND (None CRC)
commandResponse = MCCResponse();
if(commandResponse!=0) {
SetCSSPI(); // Card In-Active
WriteSPI(0xff); // Dummy
MMC_Err = 0x30;
return(1);
}
localc = 0;
while(1) { // Waiting DATA TOKEN or ERROR TOKEN
dataToken = ReadSPI();
if(dataToken==0xfe) break; // Success
localc++;
if((dataToken&0xe0)==0) { // Error Token
if(dataToken!=0) {
MMC_Err = 0x31;
return(1);
}
}
}
Nop();
for(localRD=0;localRD<BLOCK_LEN;localRD++) {
*pdes = ReadSPI();
tmpkd[localRD] = *pdes;
pdes++;
}
ReadSPI(); // CRC
ReadSPI();
SetCSSPI(); // Card In-Active
WriteSPI(0xff); // Dummy
return(0);
}
 

writespi

There is a very good application given in circuit cellar #176. Maybe you can check and see that to compare if you are doing anything wrong.
 

If I didn't misunderstand your code, you are wating for data tokens...
But, when you issue a CMD24 you have to send data tokens,

Here is piece of working code:

mmc_CS_on;

r_value = mmc_cmd(CMD24,address,0); //internally waits for response R1
mmc_putchar(0xFF);
mmc_putchar(0xFE); //sends DATA token

for(i = 0; i < 512; ++i)
mmc_putchar(buffer); // sends 512B data

mmc_putchar(0x00); // sends DUMMY 16bits CRC
mmc_putchar(0x00);

while(mmc_read_r1()==0xFF);
if((U0RXBUF & 0x1F) != 0x05)error_data_write_count++;
while(mmc_read_r1()==0x00);// waits for WRITE to end..

mmc_CS_off;
 

I fix my problem
Any one use hardware Pheripral SPI in PIC interface MMC Card attend:

when you read SPI() for waiting a response, clock is shift out, data is shift in PIC
but the same time, data in SSPBUF shift out into MMC is ramdom, because this MMC Card refuse.
Replace code:
response = ReadSPI();
With:
WriteSPI(0xff);
response = SSPBUF;
 

i have similar problem with MMC Card also,
i make a data logger, previously i used SD Card for storage, then after do many test and success, i want it able to use MMC card too, so i change the SDCard with MMC Card. but when using MMC Card the system is hang during Write file.. i don't know the reason..
during initialisation both of card give ready status, so i think it's okay in initialisation.. please show me my mistake..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top