打印
[Atmel]

跑一下SAM4N例程(二十一):SD卡

[复制链接]
500|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主


在这个例程里,可以执行基本的SD、MMC、SDIO栈
可以自动分辨卡是什么卡并且通过MCI或SPI接口读写,并不需要文件系统。

执行以下顺序:

      等待卡插入

      初使化卡

      如果是SD或MMC卡,测试读/写操作。

      写数据到卡上。

      读数据从卡上。

      效验卡。

      如果插入的是SDIO卡:

      出始化SDIO卡。

      读写测试通过CIA




以下是主函数循环:

while (1) {
                if (slot == sd_mmc_nb_slot()) {
                        slot = 0;
                }
                printf("Please plug an SD, MMC or SDIO card in slot %d.\n\r", slot+1);

                // Wait for a card and ready
                do {
                        err = sd_mmc_check(slot);
                        if ((SD_MMC_ERR_NO_CARD != err)
                                        && (SD_MMC_INIT_ONGOING != err)
                                        && (SD_MMC_OK != err)) {
                                printf("Card install FAILED\n\r");
                                printf("Please unplug and re-plug the card.\n\r");
                                while (SD_MMC_ERR_NO_CARD != sd_mmc_check(slot)) {
                                }
                        }
                } while (SD_MMC_OK != err);
       
                // Display basic card information
                main_display_info_card(slot);
       
                /* Test the card */
                if (sd_mmc_get_type(slot) & CARD_TYPE_SDIO) {
                        // Test CIA of SDIO card
                        main_test_sdio(slot);
                }
                if (sd_mmc_get_type(slot) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
                        // SD/MMC Card R/W
                        main_test_memory(slot);
                }       

                printf("Test finished, please unplugged the card.\n\r");
                while (SD_MMC_OK == sd_mmc_check(slot)) {
                }
                slot++;
        }
以下是运行结果:


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2398

主题

6948

帖子

66

粉丝