SD卡使用SPI初始化stm32f303问题与CMD0

时间:2016-11-29 18:33:46

标签: initialization spi stm32ldiscovery

我正在发送正确的命令,我可以在示波器上看到它。但是,我没有从SD卡(SDHC)获得0x01响应(我一直得到0xff)(SanDisk Ultra 40MB / s ... 16GB )我使用以下代码:

uint8_t cmd0[6]={0x40,0x00,0x00,0x00,0x00,0x95};
uint8_t dumb=0xff;
FATFS_CS_HIGH;
for (int i = 0; i < 10; i++) {
   HAL_SPI_Transmit(&hspi1, &dumb, 1, 10);
   while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
}

FATFS_CS_LOW;

HAL_SPI_Transmit(&hspi1, cmd0, 6, 10);
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);

for (int i = 0; i < 10; i++) {
   HAL_SPI_Transmit(&hspi1, &dumb, 1, 10);
   while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
}
HAL_SPI_Receive(&hspi1, &c, 1, 10);// I keep getting 0xff

以下是我从cubeMX用于SPI的配置 SPI from cubeMX

0 个答案:

没有答案