AnsweredAssumed Answered

STM32F103 and SDHC over SPI

Question asked by longchair.m on Oct 1, 2012
Latest reply on Oct 3, 2012 by Clive One
Hello,

Recently I need to use an SDHC in order to store some data for my application.

I have studied the documentation in order to find out some samples and came out with the following :

- sdio samples use SD cards but they require the sdio pins which are not available on my 64 pin LQFP stm32F103.
- spi_sd sample seem to be doing the spi communication. I have tried to use the sample code, connecting the SD to my controller on SPI1 (SCK, MISO, MOSI are connected to the SPI1 adequante pins), I have used PC10 to toggle the CS, and Power and GND ar directly connected to permanent supply.

I am having big diffuculties to get all this working together.

So first I have the following questions 

- Is there is a lib / code samples that I should use other than the samples in the stdperiph lib ?
- Is the spi_sd sample supposed to work with a regular SDHC card ? (I am using an olimex H103 board which has no specific SD features, but I have connected a 4Go SDHC Card to the proper pins mentionned above).

When using the spi_sd code sample, After the spi Init, the code will stop and wait un definitely on the code in    SD_WriteByte:

/*!< Wait until the transmit buffer is empty */
  while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
  {
  }
 
  /*!< Send the byte */
  SPI_I2S_SendData(SD_SPI, Data);
 
  /*!< Wait to receive a byte*/
  while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
  {
  }


The first while loop will never exit as if the transfer was not complete and I cannot figure out why. I have checked the pinout many times and it seems ok. Any other suggestions ?

Thanks in advance.

Lionel.

Outcomes