|
Tài trợ cho PIC Vietnam |
Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC |
|
Ðiều Chỉnh | Xếp Bài |
30-11-2009, 02:34 PM | #11 | ||
Đệ tử 4 túi
Tham gia ngày: Mar 2009
Bài gửi: 64
: |
Cảm ơn bác đã giúp. Đoạn gửi ACMD41 đúng là em hơi sơ xuất, em chỉ loop mỗi gửi ACMD41, đáng nhẽ phải loop cả CMD55 và ACMD41
Trích:
Trích:
Khi send 6 byte lệnh, có delay giữa các byte hay ko hay là gửi liên tiếp, Code:
unsigned char SD_WriteCommand(unsigned char* cmd) { unsigned int i; unsigned char response; unsigned char savedSD_CS = SD_CS; // SD Card Command Format // (from Section 5.2.1 of SanDisk SD Card Product Manual v1.9). // Frame 7 = 0 // Frame 6 = 1 // Command (6 bits) // Address (32 bits) // Frame 0 = 1 // Set the framing bits correctly (never change) cmd[0] |= (1<<6); cmd[0] &= ~(1<<7); cmd[5] |= (1<<0); // Send the 6 byte command SD_Enable(); for(i = 0; i < 6; ++i) { SPIWrite(*cmd); Delay_Us(100); //để 10 thì ăn, còn để 0 hoặc 100 là response về FF cmd++; } // Wait for the response i = 0; do { response = SPIRead(); if(i > 500) //If this value = 100, will recieved 0xFF with cmd17 { break; } i++; } while(response == 0xFF); SD_Disable(); // Following any command, the SD Card needs 8 clocks to finish up its work. // (from SanDisk SD Card Product Manual v1.9 section 5.1.8) SPIWrite(0xFF); SD_CS = savedSD_CS; return(response); } |
||
|
|