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.

[SOLVED] Micro SD card returns 0xC1 to CMD25 and 0xC2 to CMD18

Status
Not open for further replies.

Kosh

Junior Member level 2
Joined
Jun 16, 2007
Messages
22
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,388
Hi,

I've got some 2GB and 1GB micro SD cards that returns 0xC1 to CMD25 and 0xC2 to CMD18. They don't accept any write or read.
Any other micro SD returns the expected response on my hardware. It's a Mega8 talking to the card via SPI.
These cards also work ok on W7.

Any ideas?

Thanks.
 

Some SD cards require a one byte read after the response code on ALL commands (discard the data read), other cards do not require this delay.
 
  • Like
Reactions: Kosh

    Kosh

    Points: 2
    Helpful Answer Positive Rating
Thank you, that solved the problem.
I had to do two byte reads after CMD9 response to get CMD25 and CMD18 working.
 

I had to do two byte reads after CMD9 response to get CMD25 and CMD18 working.

I don't know why you had to do that, the data returned after the response data by CMD9 is 128 bits long, maybe you are not reading all of it?
 
Last edited:

Well, I don't know. The 128 bytes are all read and I can calculate the correct card size based on them.

I deleted the two read bytes after CMD9 and modified the read sector routine. Now it is working ok. See below:

read_sector:
rcall read_SD ; Read one byte
sbi PORTC, SDSEL ; Unselect SD card
rcall read_SD ; Read one byte
cbi PORTC, SDSEL ; Select SDcard
rcall read_SD ; Read one byte

ldi temp, $52 ; CMD18 to SD card (Read Blocks)
rjmp send_cmd
 

I don't know why you need to deselect the SD card, on my working code to do the same thing I do not deselect the SD card.
 

That part of the code was copied from an example I found on the Internet.
I just rewrote it maintaining the SD card selected all the time and it is running ok.
 

Some SD cards require a one byte read after the response code on ALL commands (discard the data read), other cards do not require this delay.

I think that the above quote needs some clarification for other readers of this thread. What I meant to say was that a dummy read should be performed after any command has been issued and all of the data (response code, CRC, SD data etc) has been read or sent. The easiest way to do this is to perform the dummy read before issuing a new command like Kosh has done. Unfortunately the requirement for the dummy read is not specified in the data sheets for SD cards other than for those SD cards that require it and so is often overlooked. This caused me a lot of grief when I wrote my own SD card routines and I hope that this thread will help others.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top