Problem putting sd card in spi mode

Thread Starter

Saeed Abdoli

Joined Oct 31, 2017
1
I'm trying to connect an sd card to the stm32f091cct6 microcontroller using FatFs driver. After sending some clock while MOSI and CS are high, I send idle command (CMD0) but receive no response from sd card. I pulled up MISO pin with a 100K resistor and clk pin with a 10K resistor. sd card isn't dead because I tried to communicate with it with another processor (TI ARM cortex M3) and it was a success. I pulled up all signals interally. (I tried different configurations of internal and external pull-ups but nothing happend). This is spi initialization code:



/* SPI Config */
heval_Spi.Instance = EVAL_SPIx;1.jpg 2.jpg



// PCLK1 = 48MHz
heval_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
heval_Spi.Init.Direction = SPI_DIRECTION_2LINES;
heval_Spi.Init.CLKPhase = SPI_PHASE_1EDGE;
heval_Spi.Init.CLKPolarity = SPI_POLARITY_HIGH;
heval_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
heval_Spi.Init.CRCPolynomial = 7;
heval_Spi.Init.DataSize = SPI_DATASIZE_8BIT;
heval_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB;
heval_Spi.Init.NSS = SPI_NSS_HARD_OUTPUT;
heval_Spi.Init.TIMode = SPI_TIMODE_ENABLE;
heval_Spi.Init.Mode = SPI_MODE_MASTER;

SPIx_MspInit(&heval_Spi);
HAL_SPI_Init(&heval_Spi);



I've attached spi signals

yellow: MISO

cyan: CLK

purple: MOSI

blue: CS
 

nsaspook

Joined Aug 27, 2009
16,255
Your init clock speed might be too high, reduce it to about 150KHz until the SD card responds properly.

http://elm-chan.org/docs/mmc/mmc_e.html
Power ON or card insersion
After supply voltage reached 2.2 volts, wait for one millisecond at least. Set SPI clock rate between 100 kHz and 400 kHz. Set DI and CS high and apply 74 or more clock pulses to SCLK. The card will enter its native operating mode and go ready to accept native command.

Software reset
Send a CMD0 with CS low to reset the card. The card samples CS signal on a CMD0 is received successfully. If the CS signal is low, the card enters SPI mode and responds R1 with In Idle State bit (0x01). Since the CMD0 must be sent as a native command, the CRC field must have a valid value. When once the card enters SPI mode, the CRC feature is disabled and the CRC is not checked by the card, so that command transmission routine can be written with the hardcorded CRC value that valid for only CMD0 and CMD8 with the argument of zero. The CRC feature can also be switched with CMD59.
 
Top