你好: 我也发现了这个问题,我用的是2G的金士顿的,由于不同的SD卡读写速度是有区别的,其SPI操作时序上有点区别,在ZLG提供的SPI+SD和u/cos+SPI+SD都存在这个问题,我修改了其中的两个地方,就好了,你仔细看看: 没有操作系统的地方: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<20;fengwei_count++ ) //FENGWEI ; ret = SD_ReadOCR(4, recbuf); /* 7. 读OCR寄存器,查询卡支持的电压值 read OCR register,get the supported voltage */ if (ret != SD_NO_ERR) goto SD_ERR; if ((recbuf[2] & MSK_OCR_33) != MSK_OCR_33) { ret = SD_ERR_VOL_NOTSUSP; /* 不支持3.3V,返回错误码 not support 3.3V,return error code */ goto SD_ERR; } SPI_ClkToMax(); /* 8. 设置SPI时钟到最大值 set SPI clock to maximum */ 而在u/cos+spi+sd中修改如下: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; INT32U i = 100,j = 0; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ do { ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if(ret == SD_NO_ERR) break; j++; for(i=100; i>0; i--); }while(j<10);
if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<50;fengwei_count++ ) //FENGWEI 你好: 我也发现了这个问题,我用的是2G的金士顿的,由于不同的SD卡读写速度是有区别的,其SPI操作时序上有点区别,在ZLG提供的SPI+SD和u/cos+SPI+SD都存在这个问题,我修改了其中的两个地方,就好了,你仔细看看: 没有操作系统的地方: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<20;fengwei_count++ ) //FENGWEI ; ret = SD_ReadOCR(4, recbuf); /* 7. 读OCR寄存器,查询卡支持的电压值 read OCR register,get the supported voltage */ if (ret != SD_NO_ERR) goto SD_ERR; if ((recbuf[2] & MSK_OCR_33) != MSK_OCR_33) { ret = SD_ERR_VOL_NOTSUSP; /* 不支持3.3V,返回错误码 not support 3.3V,return error code */ goto SD_ERR; } SPI_ClkToMax(); /* 8. 设置SPI时钟到最大值 set SPI clock to maximum */ 而在u/cos+spi+sd中修改如下: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; INT32U i = 100,j = 0; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ do { ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if(ret == SD_NO_ERR) break; j++; for(i=100; i>0; i--); }while(j<10);
if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<50;fengwei_count++ ) //FENGWEI 你好: 我也发现了这个问题,我用的是2G的金士顿的,由于不同的SD卡读写速度是有区别的,其SPI操作时序上有点区别,在ZLG提供的SPI+SD和u/cos+SPI+SD都存在这个问题,我修改了其中的两个地方,就好了,你仔细看看: 没有操作系统的地方: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<20;fengwei_count++ ) //FENGWEI ; ret = SD_ReadOCR(4, recbuf); /* 7. 读OCR寄存器,查询卡支持的电压值 read OCR register,get the supported voltage */ if (ret != SD_NO_ERR) goto SD_ERR; if ((recbuf[2] & MSK_OCR_33) != MSK_OCR_33) { ret = SD_ERR_VOL_NOTSUSP; /* 不支持3.3V,返回错误码 not support 3.3V,return error code */ goto SD_ERR; } SPI_ClkToMax(); /* 8. 设置SPI时钟到最大值 set SPI clock to maximum */ 而在u/cos+spi+sd中修改如下: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; INT32U i = 100,j = 0; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ do { ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if(ret == SD_NO_ERR) break; j++; for(i=100; i>0; i--); }while(j<10);
if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<50;fengwei_count++ ) //FENGWEI 你好: 我也发现了这个问题,我用的是2G的金士顿的,由于不同的SD卡读写速度是有区别的,其SPI操作时序上有点区别,在ZLG提供的SPI+SD和u/cos+SPI+SD都存在这个问题,我修改了其中的两个地方,就好了,你仔细看看: 没有操作系统的地方: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<20;fengwei_count++ ) //FENGWEI ; ret = SD_ReadOCR(4, recbuf); /* 7. 读OCR寄存器,查询卡支持的电压值 read OCR register,get the supported voltage */ if (ret != SD_NO_ERR) goto SD_ERR; if ((recbuf[2] & MSK_OCR_33) != MSK_OCR_33) { ret = SD_ERR_VOL_NOTSUSP; /* 不支持3.3V,返回错误码 not support 3.3V,return error code */ goto SD_ERR; } SPI_ClkToMax(); /* 8. 设置SPI时钟到最大值 set SPI clock to maximum */ 而在u/cos+spi+sd中修改如下: INT8U SD_Initialize(void) { INT8U recbuf[4],ret,fengwei_count; INT32U i = 100,j = 0; #if SD_UCOSII_EN if (pSemSD == NULL) { pSemSD = OSSemCreate(1); /* 创建访问SD/MMC卡信号量 create SD/MMC semaphore */ if (pSemSD == NULL) return SD_ERR_CREATE_SEMSD; } #endif SD_StartSD(); SD_HardWareInit(); /* 初始化读写SD卡的硬件条件 Initialize the hardware that access SD Card */ if (SD_ChkCard() != 1) /* 检查卡是否插入 check weather card is inserted */ { ret = SD_ERR_NO_CARD; goto SD_ERR; } SPI_CS_Assert(); /* 1. 置CS为低 assert CS */ SD_SPIDelay(100); /* 2. 至少延时 74 clock delay more than 74 clock */ SPI_CS_Deassert(); /* 3. 置CS为高 dessert CS */ SD_SPIDelay(10); /* 4. 延时2(8 clock) delay 2(8 clock) */ do { ret = SD_ResetSD(); /* 5. 发出CMDO命令复位SD卡 send CMD0 command to reset sd card */ if(ret == SD_NO_ERR) break; j++; for(i=100; i>0; i--); }while(j<10);
if (ret != SD_NO_ERR) goto SD_ERR; ret = SD_ActiveInit(); /* 6. 激活卡进入初始化过程. active card initialize process */ if (ret != SD_NO_ERR) goto SD_ERR; for( fengwei_count=0;fengwei_count<50;fengwei_count++ ) //FENGWEI |