ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Среда
10 июля
329330
mrengineer (18.05.2012 10:31, просмотров: 1720)
Не пишет на SD карточку Проблема. Не могу понять почему не происходит запись на карту памяти. Может, у кого такое было или идею кто подаст... Инициализация карты проходит нормально. Чтение идет нормально. При записи я сваливаюсь в ошибку MMC_RESPONSE_ERROR. Привожу соответствующие участки кода. Запись char mmcWriteBlock (const unsigned long address){ unsigned long i = 0; char rvalue = MMC_RESPONSE_ERROR; // MMC_SUCCESS; // Set the block length to read if (mmcSetBlockLength (512) == MMC_SUCCESS){ // block length could be set CS_LOW; // send write command mmcSendCmd (24,address, 0xFF); // check if the MMC acknowledged the write block command // it will do this by sending an affirmative response // in the R1 format (0x00 is no errors) if (mmcGetXXResponse(MMC_R1_RESPONSE) == MMC_R1_RESPONSE){ spiSendByte(0xff); // send the data token to signify the start of the data spiSendByte(0xfe); // clock the actual data transfer and transmitt the bytes for (i = 0; i < 512; i++) spiSendByte(mmc_buffer[i]); // mmc_buffer[i]; Test: i & 0xff // put CRC bytes (not really needed by us, but required by MMC) spiSendByte(0xff); spiSendByte(0xff); // read the data response xxx0<status>1 : status 010: Data accected, status 101: Data // rejected due to a crc error, status 110: Data rejected due to a Write error. mmcCheckBusy(); } else { // the MMC never acknowledge the write command rvalue = MMC_RESPONSE_ERROR; // 2 } } else { rvalue = MMC_BLOCK_SET_ERROR; // 1 } // give the MMC the required clocks to finish up what ever it needs to do // for (i = 0; i < 9; ++i) // spiSendByte(0xff); CS_HIGH; // Send 8 Clock pulses of delay. spiSendByte(0xff); return rvalue; } // mmc_write_block Это тот самый mmcGetXXResponse по которому я улетаю в ошибку char mmcGetXXResponse(const char resp){ //Response comes 1-8bytes after command //the first bit will be a 0 //followed by an error code //data will be 0xff until response int i=0; char response; while(i<=500) { response=spiSendByte(0xff); if(response==resp) break; i++; } return response; } Отметим, что response=spiSendByte(0xff); дает результат 255; 32; 255 и далее постоянно 255 и, наконец, код отправки команды void mmcSendCmd (const char cmd, unsigned long data, const char crc){ unsigned char frame[6]; char temp; int i; frame[0]=(cmd|0x40); //printf("CMD:%i\r"); for(i=3;i>=0;i--){ temp=(char)(data>>(8*i)); frame[4-i]=(temp); } frame[5]=(crc); for(i=0;i<6;i++) spiSendByte(frame[i]); } Обратите внимание, frame[0]=(cmd|0x40); к команде накидывает биты 0x40. Т.е. с команды 17 в аргументе мы получаем команду 0x58. отметим, что в других проектах есть макросы #define MMC_CMD_WRITEBLOCK 0x54 //CMD20 Write block to memory #define MMC_WRITE_BLOCK 0x58 //CMD25 Есть сомнения уж не 0x54 надо ли отправлять...