|
技术交流 | 电路欣赏 | 工控天地 | 数字广电 | 通信技术 | 电源技术 | 测控之家 | EMC技术 | ARM技术 | EDA技术 | PCB技术 | 嵌入式系统 驱动编程 | 集成电路 | 器件替换 | 模拟技术 | 新手园地 | 单 片 机 | DSP技术 | MCU技术 | IC 设计 | IC 产业 | CAN-bus/DeviceNe |
给大家发个MMC卡驱动,我测试过的! |
作者:jiaxinhui 栏目:嵌入式系统 |
/////////////////// // MMC commands #define INIT_CMD0_ERROR 0xFF #define INIT_CMD1_ERROR 0xFE #define WRITE_BLOCK_ERROR 0xFD #define READ_BLOCK_ERROR 0xFC // MMC/SD commands #define MMC_RESET 0x40 + 0 #define MMC_INIT 0x40 + 1 #define MMC_READ_CSD 0x40 + 9 #define MMC_READ_CID 0x40 + 10 #define MMC_STOP_TRANSMISSION 0x40 + 12 #define MMC_SEND_STATUS 0x40 + 13 #define MMC_SET_BLOCKLEN 0x40 + 16 #define MMC_READ_BLOCK 0x40 + 17 #define MMC_READ_MULTI_BLOCK 0x40 + 18 #define MMC_WRITE_BLOCK 0x40 + 24 #define MMC_WRITE_MULTI_BLOCK 0x40 + 25 #define MMC_Disable() (PORTA|=(1<<6)) #define MMC_Enable() (PORTA&=~(1<<6)) //**************************************************************************** //Routine for Init MMC/SD card(SPI-MODE) uchar MMC_Init(void) //**************************************************************************** { uchar retry,TEMP; uchar i; //MMC_Port_Init(); //Init SPI PORT SPCR=0x53; SPSR=0x00; for (i=0;i<10;i++) { SPI_TransferByte(0xff); //send 74 clock at least!!! } MMC_Enable(); SPI_TransferByte(MMC_RESET); SPI_TransferByte(0x00); SPI_TransferByte(0x00); SPI_TransferByte(0x00); SPI_TransferByte(0x00); SPI_TransferByte(0x95); SPI_TransferByte(0xff); SPI_TransferByte(0xff); retry=0; do{ TEMP=Write_Command_MMC(MMC_INIT,0); retry++; if(retry==100) { MMC_Disable(); return(INIT_CMD1_ERROR); } }while(TEMP!=0); MMC_Disable(); SPCR=0x50; SPSR=0x01; return (1); } //**************************************************************************** //Send a Command to MMC/SD-Card //Return: the second byte of response register of MMC/SD-Card uchar Write_Command_MMC(uint cmd, ulong address) //**************************************************************************** { uchar tmp; uchar retry=0; SPI_TransferByte(cmd); SPI_TransferByte(address>>24); SPI_TransferByte(address>>16); SPI_TransferByte(address>>8); SPI_TransferByte(address); SPI_TransferByte(0xFF); do{ tmp = SPI_TransferByte(0xFF); retry++; }while((tmp==0xff)&&(retry<8)); return(tmp); } //**************************************************************************** //**************************************************************************** //Routine for reading Blocks(512Byte) from MMC/SD-Card //Return 0 if no Error. uchar MMC_read_sector(ulong addr,uchar *Buffer) //**************************************************************************** { uchar TEMP; uint i; SPI_TransferByte(0xff); MMC_Enable(); TEMP = Write_Command_MMC(MMC_READ_BLOCK,addr<<9); if(TEMP != 0x00) { MMC_Disable(); return(READ_BLOCK_ERROR); } while(SPI_TransferByte(0xff) != 0xfe); for(i=0;i<512;i++) { *Buffer++ = SPI_TransferByte(0xff); } SPI_TransferByte(0xff); SPI_TransferByte(0xff); &nbs |
2楼: | >>参与讨论 |
作者: xxdcq 于 2006/6/15 11:16:00 发布:
内容太少了! 不完整! |
3楼: | >>参与讨论 |
作者: randman 于 2006/6/15 18:23:00 发布:
楼主怎么搞的撒 |
4楼: | >>参与讨论 |
作者: lczsx2000 于 2006/6/16 21:08:00 发布:
我顶! 谢谢楼主,但是既然测试过,为何不把测试数据给出来呢?这个比程序更重要啊! |
5楼: | >>参与讨论 |
作者: robshine 于 2006/6/18 21:46:00 发布:
怎么连半点解释也没有? |
6楼: | >>参与讨论 |
作者: zzb147 于 2006/6/19 17:39:00 发布:
就是让你看不懂。 |
7楼: | >>参与讨论 |
作者: dlhjfeng 于 2006/7/1 15:07:00 发布:
没有注解呢 |
8楼: | >>参与讨论 |
作者: db10 于 2006/7/2 11:52:00 发布:
没有注释 看起来就累点 |
|
|
Copyright © 1998-2006 tgdrjb.cn 浙ICP证030469号 |