集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 3400|回复: 4

SD卡可以初始化,却读不出来数据,求解

[复制链接]
lilieboy 发表于 2011-8-5 11:34:12 | 显示全部楼层 |阅读模式
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd55
send acmd41
send cmd2
SD_card_init success
Find SD card.
send cmd0
send cmd55
send acmd41
send cmd55
send acmd41
send cmd2
SD_card_init success
the partition type is not supported.
SD card mount fail.

最前面的省略了,因为都是那两个命令
 楼主| lilieboy 发表于 2011-8-5 11:35:36 | 显示全部楼层
  1. #include <stdio.h>
  2. #include "my_includes.h"
  3. #include "my_types.h"
  4. #include "FatFileSystem.h"  // FAT16 lib
  5. #include "SDCardDriver.h"   // SDCard HAL
  6. #include "bitmap.h"         // bmp lib

  7. #define WAITING_SEC 5
  8. // bmp file list parameter  bmp文件列表参数
  9. #define MAX_FILE_NUM 128  // maximum file number in file list
  10. #define FILENAME_LEN 32   // length of file name

  11. typedef struct {
  12.   int  filenum;
  13.   char filename[MAX_FILE_NUM][FILENAME_LEN];
  14. } BmpFileList;

  15. static BmpFileList bmp_file_list;

  16. // bmp parameter bmp参数
  17. #define BMP_WIDTH 800
  18. #define BMP_HEIGHT 480
  19. #define BMP_RGB_OFST 54
  20. #define NUM_RGB 3
  21. #define OFST_R 2
  22. #define OFST_G 1
  23. #define OFST_B 0

  24. // wait sdcard insert into socket
  25. void wait_sdcard_insert(void) {
  26.   bool bFirstTime2Detect = TRUE;
  27.   
  28.   while(!SD_card_init()) {
  29.     if (bFirstTime2Detect){
  30.       printf("Please insert SD card.\n");
  31.       bFirstTime2Detect = FALSE;
  32.     }
  33.   }
  34.   
  35.   printf("Find SD card.\n");
  36. }

  37. // build bmp file list
  38. int build_bmp_play_list(void) {
  39.   int filecnt = 0;                   // number of bmp
  40.   FAT_BROWSE_HANDLE hFileBrowse;     // FAT browse handle
  41.   FAT_DIRECTORY Directory;           // FAT directory
  42.   FAT_FILE_HANDLE hFile;             // FAT file handle
  43.   alt_u8 header[BMP_RGB_OFST];
  44.   char filename[FILENAME_LEN];

  45.   bmp_file_list.filenum = 0;
  46.   
  47.   // FatFileSystem.h
  48.   if (!Fat_FileBrowseBegin(&hFileBrowse)){
  49.     printf("browse file fail.\n");
  50.     return 0;
  51.   }

  52.   // FatFileSystem.h
  53.   while (Fat_FileBrowseNext(&hFileBrowse, &Directory)) {
  54.     // only bmp in file list
  55.     if (strncmpi(Directory.Extension, "BMP", 3))
  56.       continue;
  57.    
  58.     // compose filename  
  59.     Fat_ComposeFilename(&Directory, filename);

  60.     // fopen() (FatFileSystem.h)
  61.     if (!Fat_FileOpen(&hFile, filename)) {
  62.       printf("bmp file open fail.\n");
  63.       continue;
  64.     }

  65.     // fread() (FatFileSystem.h)
  66.     if (!Fat_FileRead(&hFile, header, sizeof(header))) {
  67.       printf("bmp file read fail.\n");
  68.       continue;
  69.     }

  70.     // fclose() (FatFileSystem.h)
  71.     Fat_FileClose(&hFile);
  72.       
  73.     // convert to bmp header (bitmap.h)
  74.     BitmapHeader *bmp_header = get_bmp_header(header);

  75.     // check valid bmp format
  76.     if (!chk_valid_bmp(bmp_header)) {
  77.       printf("%s is invalid bmp for DE2-70 LTM.\n", filename);
  78.       continue;
  79.     }

  80.     // copy filename into file list      
  81.     strcpy(bmp_file_list.filename[filecnt], filename);
  82.     filecnt++;
  83.   } // while
  84.    
  85.   bmp_file_list.filenum = filecnt;
  86.   
  87.   return filecnt;
  88. }

  89. // play bmp by filename
  90. bool play_bmp(char *filename){
  91.   FAT_FILE_HANDLE hFile; // FAT file handle
  92.   
  93.   // fopen() (FatFileSystem.h)
  94.   if (!Fat_FileOpen(&hFile, filename)){
  95.     printf("Fat_FileOpen fail.\n");
  96.     return FALSE;
  97.   }
  98.   
  99.   printf("BMP file name is %s.\n", filename);
  100.   
  101.   if (!Fat_FileSeek(&hFile, FILE_SEEK_BEGIN, BMP_RGB_OFST)) {
  102.     printf("Fat_FileSeek fail.\n");
  103.     return FALSE;
  104.   }
  105.    
  106.   // bmp RGB array   
  107.   alt_u8 buff_bmp[BMP_WIDTH * BMP_HEIGHT * NUM_RGB];

  108.   // fread() (FatFileSystem.h)
  109.   if (!Fat_FileRead(&hFile, buff_bmp, sizeof(buff_bmp))) {
  110.     printf("Fat_FileRead fail.\n");
  111.     return FALSE;
  112.   }
  113.         
  114.   // move to sdram frame buffer//
  115.   int x, y;
  116.   for(x=0; x < BMP_WIDTH; x++) {
  117.   for(y=0; y < BMP_HEIGHT; y++) {
  118.       // get RGB
  119.       int r = buff_bmp[(y * BMP_WIDTH + x) * NUM_RGB + OFST_R];
  120.       int g = buff_bmp[(y * BMP_WIDTH + x) * NUM_RGB + OFST_G];
  121.       int b = buff_bmp[(y * BMP_WIDTH + x) * NUM_RGB + OFST_B];


  122.     }
  123.   }
  124.                
  125.   printf("Finsh reading FAT16\n");
  126.   // file close
  127.   Fat_FileClose(&hFile);
  128.   
  129.   return TRUE;
  130. }

  131. int main() {
  132.   int play_index = 0;
  133.   alt_u8 filename[FILENAME_LEN];
  134.   
  135.   // check SD card
  136.   wait_sdcard_insert();
  137.   
  138.   // Mount SD-CARD
  139.   if (!Fat_Mount(FAT_SD_CARD)) {
  140.     printf("SD card mount fail.\n");
  141.     return -1;
  142.   }
  143.   
  144.   // build wave list in gWavePlayList
  145.   if (build_bmp_play_list() == 0) {
  146.     printf("There is no bmp file in the root directory of SD card.\n");
  147.     return -1;
  148.   }
  149.   
  150.   while(1) {
  151.     strcpy(filename, bmp_file_list.filename[play_index]);
  152.    
  153.     if (!play_bmp(filename)){
  154.       printf("bmp play fail.\n");
  155.       return -1;
  156.     }
  157.         
  158.     play_index++;
  159.    
  160.     // repeat
  161.     if (play_index >= bmp_file_list.filenum)
  162.       play_index = 0;
  163.   
  164.     // waiting 5 sec between bmp
  165.     printf("Waiting %d sec...\n", WAITING_SEC);   
  166.     usleep(WAITING_SEC * 1000 * 1000);
  167.   }

  168.   return 0;
  169. }
复制代码
 楼主| lilieboy 发表于 2011-8-5 11:36:44 | 显示全部楼层
main文件是别人做液晶屏显示图片的,那段忽略了,只要求能读取sd就行
 楼主| lilieboy 发表于 2011-8-5 13:52:15 | 显示全部楼层
发现这个只能读2G的卡~
 楼主| lilieboy 发表于 2011-8-9 16:54:17 | 显示全部楼层
果断沉掉了啊~
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-24 04:04 , Processed in 0.067578 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表