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

[复制链接]
 楼主| ddllxxrr 发表于 2015-4-8 21:10 | 显示全部楼层 |阅读模式


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

执行以下顺序:

      等待卡插入

      初使化卡

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

      写数据到卡上。

      读数据从卡上。

      效验卡。

      如果插入的是SDIO卡:

      出始化SDIO卡。

      读写测试通过CIA




以下是主函数循环:

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

  6.                 // Wait for a card and ready
  7.                 do {
  8.                         err = sd_mmc_check(slot);
  9.                         if ((SD_MMC_ERR_NO_CARD != err)
  10.                                         && (SD_MMC_INIT_ONGOING != err)
  11.                                         && (SD_MMC_OK != err)) {
  12.                                 printf("Card install FAILED\n\r");
  13.                                 printf("Please unplug and re-plug the card.\n\r");
  14.                                 while (SD_MMC_ERR_NO_CARD != sd_mmc_check(slot)) {
  15.                                 }
  16.                         }
  17.                 } while (SD_MMC_OK != err);
  18.        
  19.                 // Display basic card information
  20.                 main_display_info_card(slot);
  21.        
  22.                 /* Test the card */
  23.                 if (sd_mmc_get_type(slot) & CARD_TYPE_SDIO) {
  24.                         // Test CIA of SDIO card
  25.                         main_test_sdio(slot);
  26.                 }
  27.                 if (sd_mmc_get_type(slot) & (CARD_TYPE_SD | CARD_TYPE_MMC)) {
  28.                         // SD/MMC Card R/W
  29.                         main_test_memory(slot);
  30.                 }       

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


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部