cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing SD card via SPI

osama
Associate II
Posted on January 03, 2013 at 05:56

Hi,

I have an STM32F4 discovery board and I want to access SD card via SPI. The reason why I want to access Sd card via SPI is that the breakout module that I have has an SPI interface. I have looked on the internet but have only found examples which are accessing SD card using the SDIO interface.

Is there any way that I can get some example code for reading SD card via SPI or some wiring alternative to convert the SPI interface to SDIO interface so that I can use the available examples.

This is the module that I have

http://www.aliexpress.com/store/product/SD-Card-Reader-Module-for-Arduino-ARM-Read-and-Write-Free-shipping/316774_526750081.html

Regards

#spi-sd-card-stm32-discovery #stm32f4-discovery #choose-appropriate-parts #spi
6 REPLIES 6
Andrew Neil
Evangelist
Posted on January 03, 2013 at 11:27

''I have looked on the internet but have only found examples which are accessing SD card using the SDIO interface''

 

 

I don't believe you!

The internet has many, many  examples of using SD Cards with microcontrollers via SPI:

http://www.lmgtfy.com?q=SD+Card+microcontroller+SPI

''Is there any way that I can get some example code for reading SD card via SPI''

 

Yes! See above.

Andrew Neil
Evangelist
Posted on January 03, 2013 at 11:34

''The reason why I want to access Sd card via SPI is that the breakout module that I have has an SPI interface''

 

So why don't you just get a breakout module that provides the full SD interface?!

eg:

https://www.sparkfun.com/products/11616

https://www.sparkfun.com/products/11403

Posted on January 03, 2013 at 14:43

I think others have asked similar questions here in the past, SPI is a fairly common implementation vector, and as Andy notes there should be plenty of examples out there. These might well take additional effort to port to your specific chip/board/tool-chain, but the core code might prove instructive.

ST has some examples in their firmware libraries, for other parts/boards, but you'll have to port them to your specific requirements.

STM32L1xx_StdPeriph_Lib_V1.1.1\Utilities\STM32_EVAL\STM32L152_EVAL\stm32l152_eval_spi_sd.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
osama
Associate II
Posted on January 03, 2013 at 17:41

Hi,

Well I think I didnt made my self clear the first time. I know that there are many examples available for SD Card via SPI for other microcontrollers but I was looking for some example code for STM32F4 microcontroller family. I have been looking at the example codes for other microcontrollers (PIC18 and Arduino). The PIC18 code was helpful to me but I was looking for some code which would save me time for porting that code to the STM32 code. Thats why I asked for some example. I will look into the example code as suggested by clive1.

''So why don't you just get a breakout module that provides the full SD interface?!''

Well because that module is not available in my area and getting it to ship from somewhere else will probably take 10 days which is too long time.

Regards

Andrew Neil
Evangelist
Posted on January 03, 2013 at 17:54

The only thing which is actually specific to the STM32 is the low-level SPI control - you should be able to work that out from the ''generic'' SPI examples from ST...

Posted on January 03, 2013 at 20:43

No, I think you were reasonably clear, however the dearth of SPI examples for the F2 and F4 platforms stems from the fact everyone is using SDIO due to the speed and obsolesce of pretty much anything below 2GB on SD Cards. The vast majority of professional use of the platform is likely to be with the MicroSDHC cards with capacities up to at least 64GB.

I could port the SPI implementation, but there are no economic drivers for me.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..