This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MMC/SD SendCmd Get Response Questions



Hello,

I am working my way through the code in SLAA281B "Interfacing the MSP430 with MMC/SD Flash Memory Cards".  In the documentation there is the function mmcSendCmd which sends SD/MMC card commands to the card.  After every command is sent there is a follow up of mmcGetResponse().  In this method there is a note that says

"Response comes 1-8 bytes after command.  The first bit will be a 0 followed by an error code.  Data will be 0xFF until response."

What I am trying to understand is what the note means.  

1. Why must there be an error?  If there is an error why are there only two options (0x00 and 0x01) and no the list of responses for R1-R3?  The SD documentation hasn't helped me much.  Maybe I am looking at the term "error" incorrectly.  

2. What is meant by data will be 0xFF until response?  Is there a continual response?

3. It looks like you must write a "Dummy Byte" following every command.  Why is this?

I know this is specific and clearly I am lost.  I apologize for confusing the issue any more then it needs to be.

Take care,

Jon

  • I have actually no experience with MMC or SD cards, but question 3 is more a generic question to SPI.

    Jon81 said:

    3. It looks like you must write a "Dummy Byte" following every command.  Why is this?

    That is because SPI is a synchronous protocol and the slave is only able to send data while there is a clock. And a clock is only provided by the master, if the master sends something. Now if you want to read something, you have to send something. Most of the time you will write a command to the slave, then the slave responds, to get that response you have to send something, the slave will ignore what you send, so you can use anything, basically a Dummy byte.

    I hope that was clear, for the other questions someone with experience on MMC/SD should answer, though the code examples have sometimes very rudimentary comments and can lead to misunderstandings.

  • Jon81 said:
    3. It looks like you must write a "Dummy Byte" following every command.  Why is this?


    Bernhard has explained it well. Just one additional thought:

    SPI has a clock for trhe transfer. So it doesn't matter whether you send an '0xff' byte whiel receiving, or just leave the line idle. But since the clock is only applied for the actual transfer (one clock pulse per bit) and not continuously, the hardware needs to know whether you want to read a byte. There could have been a separate 'start receiving a byte' bit in a config register, or you simply write a dummy byte to TXBUF. :)

    Jon81 said:
    Why must there be an error?

    Not an error, an error code. This code cna be 'no error' as well :)
    The SD controller requires some time to process your command. Since the master controls the SPI transfers, either the slave would have to signal its ready state by an external signal  (an additional port pin needed), ot just emit 'dummy' bytes until ready. Sicne the master keeps reading and doe snto knwo whethe rthe received 0xff is because teh slave jsu tdoesnt' send anything and th eline is idle-high, or whether this is a valid value.
    So the convetion is, the slave will keep the line idle until ready, and the first byte that is non-0 8acutally the first bit that is non-0) indicates that the slave is ready and responding. However, with the firs tit set to 0, the byte cannot be a data byte (which could require this bit to be 1). Also, the result of th eslave operation could be an error. So the first byte after a nubme roc 0xff bytes will be MSB 0 and the lower 7 bits giving an error code. If th eerror code is 'no error', you can continue polling the result of the operation, if not, well, something was wrong. Maybe the card not properly initialized, the CRC wrong (normally unused on serial SD transfers), a hardware problem, an error with the command, whatever.

    Jon81 said:
    2. What is meant by data will be 0xFF until response?  Is there a continual response?

    Actually, the slave will jsut idle its output, so the master reads 0xff if it keeps polling data. Until the slave is ready and sends something else.
    This is 'high-level' and not part of the low-level SPI standard. (actually, SPI does not knwo whether there is a slave at all - if yo do not have anything connected to the SPI lines, the master will read 0xff all the time).

  • Bernhard,

    Thanks for the reply. That's clears is up. Great explanation. 

    Take care,

    Jon

  • Jens-Michael,

    Excellent as usual. Thanks for the help. 

    Take care,

    Jon

**Attention** This is a public forum