求助:初始化SD卡SPI模式的程序
刚刚接触这方面~
要写一个SD卡在SPI模式下的简单的读写程序~~
这两天光看文档没什么思路,而且对语言运用也不熟~
想找个初始化的程序看看,但没有找到合适的~~请高人指点~~
对C语言嵌入式开发不是很了解,请问有什么比较好的书么?
[解决办法]
SPI模式的初始化函数
INT8U SD_Init(void) { INT8U retry, temp; INT8U i = 0; INT8U CMD[] = {CMD0, 0x00, 0x00, 0x00, 0x00, 0x95}; MSPI_Init(0); SD_Enable(); for(i=0;i<250;i++) __asm { NOP } for(i = 0; i < 0x0f; i++) { SPI_RW(0xff); //发送至少74个时钟 } //Send Command CMD0 to SD/SD Card retry = 0; do { //retry 200 times to send CMD0 command temp = Write_Command_SD(CMD); retry++; if(retry >= 200) { //time out return(INIT_CMD0_ERROR); //CMD0 Error! } } while(temp != 1); //Send Command CMD1 to SD/SD-Card CMD[0] = CMD1; //Command 1 CMD[5] = 0xFF; retry = 0; do { //retry 100 times to send CMD1 command temp=Write_Command_SD(CMD); retry++; if(retry>=100) { //time out return(INIT_CMD1_ERROR);//CMD1 Error! } } while(temp != 0); MSPI_Init(1); SD_Disable(); return(0);}