小编Abd*_*uor的帖子

在STM32F303上使用SPI的SD卡初始化问题

当我发送CMD0命令(0x40 0x00 0x00 0x00 0x00 0x95)时,我试图在STM32F303上使用SPI初始化SDCard,我试着看一下示波器上来自MOSI的信号,我看到了不同的信号,如下图所示.请注意,SPI速度为281.25kBits/s.任何帮助,将不胜感激.

以下是我用来测试MOSI输出的部分代码

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

  FATFS_CS_LOW;

while(1){

      HAL_SPI_Transmit(&hspi1, (uint8_t *)cmd0[0], 1, 10);

      HAL_SPI_Transmit(&hspi1, (uint8_t *)cmd0[1], 1, 10);
      HAL_SPI_Transmit(&hspi1, (uint8_t *)cmd0[2], 1, 10);
      HAL_SPI_Transmit(&hspi1, (uint8_t *)cmd0[3], 1,10);
      HAL_SPI_Transmit(&hspi1,(uint8_t *) cmd0[4], 1, 10);
      HAL_SPI_Transmit(&hspi1, (uint8_t *)cmd0[5], 1, 10);

    }
Run Code Online (Sandbox Code Playgroud)

现在我发送正确的命令,我可以在范围内看到它.但是,我没有得到SD01的0x01响应(我一直得到0xff)(SanDisk Ultra 40MB/s ... 16GB)我使用下面的代码:

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; …
Run Code Online (Sandbox Code Playgroud)

c microcontroller hal spi stm32

3
推荐指数
1
解决办法
685
查看次数

标签 统计

c ×1

hal ×1

microcontroller ×1

spi ×1

stm32 ×1