完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我想学习一下文件系统fatfs,看了些资料,准备实际动手操作一下,实现SD卡的操作,是不是这样一个模块就够了?
我看了这个模块配套的程序,感觉不是像网上说的那种 移植了文件系统的那样子啊。 并没有跑文件系统啊? 我买这个对么? 是不是说,这个只是测试了一下和SD卡的通信正常?如果需要对SD卡文件进行操作,还需要移植了文件系统才行? 附上程序,大家可以简单一看,只有这一个c文件 [C] 纯文本查看 复制代码 [C] 纯文本查看 复制代码 /* * SD模块测试程序 * * 用途:SD模块测试程序 * */#include "REG52.H"////////////////////////****************/unsigned char *SDInfo1="SD Init Success.";unsigned char *SDInfo2="SD Init Fail.";unsigned int xdata ReadBuffer[128] ;unsigned int xdata WriteBuffer[128] ;unsigned int BlockSize;unsigned long int BlockNR;//***it sd_clk=P3^2;//***it sd_cse=P3^0;//***it sd_dai=P3^3; //Do//***it sd_dao=P3^1; //DI ***it sd_cse=P1^0; ***it sd_dao=P1^1;//DI ***it sd_clk=P1^2; ***it sd_dai=P1^3;//Dovoid Delay5us(){unsigned char a=0;for(a=0;a<40;a++);}//********************************************void SD_2Byte_Write(unsigned int IOData){unsigned char BitCounter;for (BitCounter=0;BitCounter<16;BitCounter++){sd_clk=0;//CLK Lowif(IOData&0x8000)//If the MSB of IOData is 1, then Do=1, else Do=0.sd_dao=1;//Do Highelsesd_dao=0;//Do Lowsd_clk=1;//CLK HighDelay5us();IOData=IOData<<1;//Because the MSB is transmitted firstly, shift to next lower bit.}}//********************************************void SD_Write(unsigned int IOData){unsigned char BitCounter;IOData=IOData<<8;for (BitCounter=0;BitCounter<8;BitCounter++){sd_clk=0;//CLK Lowif(IOData&0x8000)//If the MSB of IOData is 1, then Do=1, else Do=0.sd_dao=1;//Do Highelsesd_dao=0;//Do Lowsd_clk=1;//CLK HighDelay5us();IOData=IOData<<1;//Because the MSB is transmitted firstly, shift to next lower bit.}}//********************************************unsigned int SD_2Byte_Read(){unsigned int Buffer;unsigned char BitCounter;Buffer=0;for (BitCounter=0;BitCounter<16;BitCounter++){sd_clk=0;//CLK LowDelay5us();sd_clk=1;//CLK HighBuffer=Buffer<<1;//Because the MSB is transmitted firstly, shift to next lower bit. //Because the LSB will be damaged, we can not put this line under next line.if(sd_dai) Buffer++;//If SPI_Din=1 then the LSB_of_Buffer=1.}return Buffer;}//********************************************unsigned int SD_Read(){unsigned int Buffer;unsigned char BitCounter;Buffer=0xffff;for (BitCounter=0;BitCounter<8;BitCounter++){sd_clk=0;//CLK LowDelay5us();sd_clk=1;//CLK HighBuffer=Buffer<<1;//Because the MSB is transmitted firstly, shift to next lower bit. //Because the LSB will be damaged, we can not put this line under next line.if(sd_dai) Buffer++;//If SPI_Din=1 then the LSB_of_Buffer=1.}return Buffer;}//********************************************unsigned int SD_CMD_Write(unsigned int CMDIndex,unsigned long CMDArg,unsigned int ResType,unsigned int CSLowRSV)//ResType:Response Type, send 1 for R1; send 2 for R1b; send 3 for R2.{//There are 7 steps need to do.(marked by [1]-[7])unsigned int temp,Response,Response2,CRC,Maximumtimes;Response2=0;MaximumTimes=10;CRC=0x0095;//0x0095 is only valid for CMD0if (CMDIndex!=0) CRC=0x00ff;sd_cse=0;//[1] CS LowSD_2Byte_Write(((CMDIndex|0x0040)<<8)+(CMDArg>>24));//[2] Transmit Command_Index & 1st Byte of Command_Argument.SD_2Byte_Write((CMDArg&0x00ffff00)>>8);//[2] 2nd & 3rd Byte of Command_ArgumentSD_2Byte_Write(((CMDArg&0x000000ff)<<8)+CRC);//[2] 4th Byte of Command_Argument & CRC only for CMD0sd_dao=1;//[3] Do High//[3] Restore Do to High Level for (temp=0;temp<8;temp++)//[4] Provide 8 extra clock after CMD{sd_clk=0;//CLK LowDelay5us();sd_clk=1;//CLK HighDelay5us();}switch (ResType)//[5] wait response{case 1://R1{doResponse=SD_Read();while (Response==0xffff);break;}case 2://R1b{doResponse=SD_Read();while (Response==0xffff);//Read R1 firstlydoResponse2=SD_Read()-0xff00;while (Response2!=0);//Wait until the Busy_Signal_Token is non-zerobreak;}case 3: Response=SD_2Byte_Read();break;//R2}if (CSLowRSV==0) sd_cse=1;//[6] CS High (if the CMD has data block response CS should be kept low) for (temp=0;temp<8;temp++)//[7] Provide 8 extra clock after card response{sd_clk=0;//CLK LowDelay5us();sd_clk=1;//CLK HighDelay5us();}return Response;}//********************************************unsigned int SD_Reset_Card(){unsigned int temp,MaximumTimes;MaximumTimes=10;for (temp=0;temp<80;temp++)//Send 74+ Clocks{sd_clk=0;//CLK LowDelay5us();sd_clk=1;//CLK HighDelay5us();}return SD_CMD_Write(0x0000,0x00000000,1,0);//Send CMD0}//********************************************unsigned int SD_Initiate_Card()//Polling the card after reset{unsigned int temp,Response,MaximumTimes;MaximumTimes=50;for(temp=0;temp |
|
相关推荐
2个回答
|
|
|
|
|
|
还要加入小组才能发言。
这里看到的代码很混乱,大概看了下,这个代码只是SD卡的驱动,可以读写SD卡上的扇区之类的,属于底层操作。要做FatFs文件系统,还要移植文件系统的代码,官网有开源的代码下载,移植教程网上也有,我用的是STM32F429的,看的野火的教程。如果你的驱动没为题,移植fatfs不难的。 附上FatFs官网网址,或者百度“FatFs官网”,容易找到。 http://elm-chan.org/fsw/ff/00index_e.html |
|
|
|
只有小组成员才能发言,加入小组>>
3263 浏览 9 评论
2944 浏览 16 评论
3443 浏览 1 评论
8955 浏览 16 评论
4036 浏览 18 评论
1078浏览 3评论
558浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
551浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2286浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1848浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-10 15:27 , Processed in 1.063554 second(s), Total 81, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号