This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to access a microSD card with MCBSTM32EXL

Hi,

I'm using the Keil MCBSTM32EXL development board. I would like to communicatie with a microSD card. I collected a lot of documentation from the Internet.

As I understood: the uSD card starts up in SD mode. This fast mode if for professionals only (need to pay al lot and sign a non-disclosure agreement etc). By sending a serial message to the card while holding CS low it swaps to slower general use SPI mode.

I tried all kinds of signals to get into the SPI mode but no data is coming out of the uSD card. I send 6 Bytes using CRC value of 0x95.

I use pin 2 as CS, pin 5 as CLK, pin 2 as Data-in and pin 7 as Data-out.

Where do I go wrong?

Where are the experts? ;-)

thanks

Henk

Parents
  • Hi,

    Well, let me answer myself ...now being a beginning expert...;)

    This would be the answer I was looking for:

    Accessing a (micro)SD card is more complex than one expects at first sight. If you are a newbie wanting to study SD-card access simply read this document:

    "SD Specifications Part 1 Physical Layer Simplified Specification Version 3.01 May 18, 2010"
    Page 125 - 153 from:
    www.sdcard.org/.../Part_1_Physical_Layer_Simplified_Specification_Ver_3.01_Final_100518.pdf

    And of course wikipedia:
    en.wikipedia.org/.../Secure_Digital

    My experience:
    - example code on the Internet is too complex for beginners to grasp
    - there are many dead links
    - there are more kinds of SD cards than expected (;-))

    My short info:
    - The (micro)SD card can be accessed in SD mode (after powerup) or SPI mode. The SD mode is faster but more complex and uses bi-directional data transport. The SPI mode only uses CS (pin 2=D3), CLK (pin 5=CLK) , D-IN (pin 3=CMD) and D-OUT (pin 7=D0). A Host tx-message always is 48 bits long. b47=0, b46=1, b[45:40]=CMD. b[39:8]=Argument, b[7:1]=CRC-7 and b[0]=1. Each bit is accompanied by one clock pulse. Depending on the host message command type the answer from the SD card is 1 byte (R1-format), 2 bytes (R2-format) or 4 Bytes (R3/R7-format). There are some more formats. Prior to each tx-message set CS low. Clock in 48 data bits, clock another 8 bits (with D_IN high and D-OUT will be high, function unknown) then clock another 8/16/32 bits depending on the answer Rn-format and read the D-OUT bits during these clocks. Finally raise the CS signal.
    Swap from SD mode to SPI mode by powerup the SD card and send data 0x40 0x00 0x00 0x00 0x00 0x95 and receive data 0xFF 0x01. This indicates: now in Idle mode (bit 0 set). After this, the SD card ignores the CRC-7 value.
    To get the chip initialized in SPI mode the mimimum commands to be send are (after powerup): CMD00, (R1=0x01=Idle mode) CMD55 and ACMD41. Keep polling on last 2 commands until the R1 contents is zero.

    Hope some other newbies like this info.

    Thanks for listening anyway.

    Henk

Reply
  • Hi,

    Well, let me answer myself ...now being a beginning expert...;)

    This would be the answer I was looking for:

    Accessing a (micro)SD card is more complex than one expects at first sight. If you are a newbie wanting to study SD-card access simply read this document:

    "SD Specifications Part 1 Physical Layer Simplified Specification Version 3.01 May 18, 2010"
    Page 125 - 153 from:
    www.sdcard.org/.../Part_1_Physical_Layer_Simplified_Specification_Ver_3.01_Final_100518.pdf

    And of course wikipedia:
    en.wikipedia.org/.../Secure_Digital

    My experience:
    - example code on the Internet is too complex for beginners to grasp
    - there are many dead links
    - there are more kinds of SD cards than expected (;-))

    My short info:
    - The (micro)SD card can be accessed in SD mode (after powerup) or SPI mode. The SD mode is faster but more complex and uses bi-directional data transport. The SPI mode only uses CS (pin 2=D3), CLK (pin 5=CLK) , D-IN (pin 3=CMD) and D-OUT (pin 7=D0). A Host tx-message always is 48 bits long. b47=0, b46=1, b[45:40]=CMD. b[39:8]=Argument, b[7:1]=CRC-7 and b[0]=1. Each bit is accompanied by one clock pulse. Depending on the host message command type the answer from the SD card is 1 byte (R1-format), 2 bytes (R2-format) or 4 Bytes (R3/R7-format). There are some more formats. Prior to each tx-message set CS low. Clock in 48 data bits, clock another 8 bits (with D_IN high and D-OUT will be high, function unknown) then clock another 8/16/32 bits depending on the answer Rn-format and read the D-OUT bits during these clocks. Finally raise the CS signal.
    Swap from SD mode to SPI mode by powerup the SD card and send data 0x40 0x00 0x00 0x00 0x00 0x95 and receive data 0xFF 0x01. This indicates: now in Idle mode (bit 0 set). After this, the SD card ignores the CRC-7 value.
    To get the chip initialized in SPI mode the mimimum commands to be send are (after powerup): CMD00, (R1=0x01=Idle mode) CMD55 and ACMD41. Keep polling on last 2 commands until the R1 contents is zero.

    Hope some other newbies like this info.

    Thanks for listening anyway.

    Henk

Children