你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 3297|回复: 2

SD 卡 SPI 模式初始化过程,带流程图。

[复制链接]

3

主题

5

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2012-2-3 14:51:26 | 显示全部楼层 |阅读模式
流程图如下,该代码能识别 MMC V3, SD V1.X 和 SD V2.00及其后续版本,其中 SD V2.00及其后续版本又可分为标准容量和大容量版本。
 
sd_init.png
回复

使用道具 举报

3

主题

5

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2012-2-3 14:56:30 | 显示全部楼层

回复:SD 卡 SPI 模式初始化过程,带流程图。

SD SPI 发送命令 API 如下,所有实现代码参考附件。
/**
  * @brief  Send 6 bytes command to the SD card.
  * @param  Cmd: The command send to SD card.
  * @param  argument: The command argument.
  * @param  response_type: the SPI command response type.
  * @param  *response: the SPI response returned.
  * @retval The SD Response.
  */
uint8_t ARC_sd_send_command(uint8_t cmd, uint32_t argument, 
                            SD_Response response_type, uint8_t *response)
{
    int32_t i = 0;
    uint8_t crc = 0x01;
    int8_t response_length = 0;
    uint8_t tmp;
    uint8_t Frame[6];
    if (cmd & 0x80)  /* Send a CMD55 prior to ACMD */
    { 
        cmd &= 0x7F;
        ARC_sd_send_command(SD_CMD_APP_CMD, 0, R1, response);
        if (response[0] > 0x1)
        {
            ARC_SD_CS_HIGH();
            ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
            return response[0];
        }
    }
    ARC_SD_CS_LOW();
    if(cmd == SD_CMD_GO_IDLE_STATE)
        crc = 0x95;
   
    if(cmd == SD_CMD_SEND_IF_COND)
        crc = 0x87;
   
    /* All data is sent MSB first, and MSb first */
    /* cmd Format:
    cmd[7:6] : 01
    cmd[5:0] : command */
    Frame[0] = ((cmd & 0x3F) | 0x40); /*!< Construct byte 1 */
    Frame[1] = (uint8_t)(argument >> 24); /*!< Construct byte 2 */
    Frame[2] = (uint8_t)(argument >> 16); /*!< Construct byte 3 */
    Frame[3] = (uint8_t)(argument >> 8); /*!< Construct byte 4 */
    Frame[4] = (uint8_t)(argument); /*!< Construct byte 5 */
    Frame[5] = (uint8_t)(crc); /*!< Construct CRC: byte 6 */
    for (i = 0; i < 6; i++)
    {
        ARC_SPI_SendByte(SPI1, Frame); /*!< Send the Cmd bytes */
    }
   
    switch (response_type)
    {
        case R1:
        case R1B:
            response_length = 1;
            break;
        case R2:
            response_length = 2;
            break;
        case R3:
        case R7:
            response_length = 5;
            break;
        default:
            break;
    }
   
    /* Wait for a response. A response can be recognized by the start bit (a zero) */
    i = 0xFF;
    do
    {
        tmp = ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
    }while ((tmp & 0x80) && --i);
    response[0] = tmp;
   
    /* Just bail if we never got a response */
    if (i == 0)
    {
        ARC_SD_CS_HIGH();
        ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
        return response[0];
    }
    if((response[0] & SD_ILLEGAL_COMMAND) == SD_ILLEGAL_COMMAND)
    {
        ARC_SD_CS_HIGH();
        ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
        return response[0];
    }
    i = 1;
    while(i < response_length)
    {
        tmp = ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
        response = tmp;
        i++;
    }
   
    /* If the response is a "busy" type (R1B), then there's some
     * special handling that needs to be done. The card will
     * output a continuous stream of zeros, so the end of the BUSY
     * state is signaled by any nonzero response. The bus idles
     * high.
     */
    if (response_type == R1B)
    {
        do
        {
            tmp = ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);;
        }while (tmp != 0xFF);
        ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
    }
   
    ARC_SD_CS_HIGH();
    ARC_SPI_SendByte(SPI1, SD_DUMMY_BYTE);
    return response[0];
}
 

ARC_SD.rar

下载

2.12 KB, 下载次数: 24, 下载积分: ST金币 -1

回复 支持 反对

使用道具 举报

3

主题

5

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2012-2-3 14:45:21 | 显示全部楼层

回复:SD 卡 SPI 模式初始化过程,带流程图。

使用手册。
 

14_SD.pdf

下载

323.53 KB, 下载次数: 44, 下载积分: ST金币 -1

回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版