2017-02-05 07:28 AM
Hi,
I am trying to interface SD card to stm32l432kc micro controller over SPI and using sparkfun's sd card breakout board.
https://www.sparkfun.com/products/12941
. I am using sandisk 2GB memory for test.I did connections in following way.
PA1(SCLK) - SCLK(SD)
PA6(MISO) - D0(SD)
PA7(MOSI) - CMD(SD)
PB4(CS) - D3(CS in SPI mode)
3.3V - Vcc(SD)
Gnd - Gnd (SD)
In this controller there are two SPI's. I tried both but not able to pull SD card out of Idle mode. Tried using different CS pin other than NSS pins, tried with all alternate functions available on pins. But the results are same. Following is the sequence that i am using.
1. CS high
2. Initial sequence of 80+clock pluses
3. CS low
4. Send 0x40,0,0,0,0,0x95 to put sd card in Idle mode.
I could see the MOSI and clock pulses on logic analyzer (USB) and SD card is expected to send 0x01 response for CM0.
But i am getting 0xFF only.
code for SPI init
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_SPI1_CLK_ENABLE();GPIO_InitStruct.Pin = SPI1_CLK ;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_PULLDOWN;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);GPIO_InitStruct.Pin = SPI1_MISO;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);GPIO_InitStruct.Pin = SPI1_MOSI;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);SPIHandle[SPI1_HANDLE_INDEX].Instance = SPI1;SPIHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;SPIHandle.Init.Direction = SPI_DIRECTION_2LINES;SPIHandle.Init.CLKPhase = SPI_PHASE_1EDGE;SPIHandle.Init.CLKPolarity = SPI_POLARITY_LOW;SPIHandle.Init.DataSize = SPI_DATASIZE_8BIT;SPIHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;SPIHandle.Init.TIMode = SPI_TIMODE_DISABLE;SPIHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;SPIHandle.Init.CRCPolynomial = 7;SPIHandle.Init.CRCLength = SPI_CRC_LENGTH_8BIT;SPIHandle.Init.NSS = SPI_NSS_SOFT;SPIHandle.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;SPIHandle.Init.Mode = SPI_MODE_MASTER;HAL_SPI_Init(&SPIHandle);I tried the same module with arduino and its working fine. I am using HAL drivers to transmit and receive the data.
Help me out for this...!!!
Thanks
Solved! Go to Solution.
2017-02-05 05:51 PM
Dear Nikhil Ingale,
It seems lack of external pullup to initialize SD/MMC.Insert 10~22kohm pullup resistor on MISO,MOSI and CS line.Don't rely on internal pullup setting.Best Regards,
Nemui.2017-02-05 05:51 PM
Dear Nikhil Ingale,
It seems lack of external pullup to initialize SD/MMC.Insert 10~22kohm pullup resistor on MISO,MOSI and CS line.Don't rely on internal pullup setting.Best Regards,
Nemui.2017-02-06 11:41 PM
Hi Nemui Trinomius,
Thanks a lot for your help. It worked for me....!!!
Regards,
Nikhil