Em thiết kế mạch để chạy thử trên Proteur thì nó bão lỗi như ảnh phía dưới.E gửi cả project lên trong đo có File hex các bác xem hộ em nó bị lỗi gì mà nó lại báo "Can't create or open card image file".Cảm ơn các bác trước
Thông báo
Collapse
No announcement yet.
Giúp em về lỗi MMC
Collapse
X
-
Chạy giả lập thế này ko ổn đâu.
Tuy nhiên tui có thể giúp bạn fix lỗi này. Bởi vì cái MMC nó dùng 1 file để giả lập nên dùng file bình thường không được đâu. Down cái WinImage ở đây để tạo file cho nó: http://www.winimage.com/winimage.htm|
Comment
-
- Mô phỏng MMC trên proteus V7 Sp2> ổn mà, tuy nhiên nó chỉ ổn ở phần ghi theo kiểu dữ liệu raw thôi, chứ không theo fat phiếc gì hết. Cậu chỉ có thể kiểm tra đã ghi vào block thế nào, dữ liệu trên một block thế nào ... thôi, chứ không thể burn ngược từ file ảnh MMC sang một cái MMC thật rồi đút vào PC để check lại etc..
- Có một cách tạo file ảnh cho MMC, nếu winimage không tạo trực tiếp file ảnh cho MMC dạng *.MMC thì có thể save ảnh của nó dưới dạng raw ( tôi dùng All Image V1.1 down trên www.download.com), sau đó save lại dạng *.img, đổi đuôi thành *.MMC là không thắc mắc gì nữa.
Tôi chưa test thử, vì đang trong giai đoạn tìm hiểu nốt mấy cái FAT. Có một đoạn mô phỏng cho MMC ở dưới. Bạn nào hứng thú thì down
- Proteus có nhiều cái chuối, nhưng có rất nhiều cái hay. Check thử sample có phần data logging qua HDD ATA cũng hay phết. Nó cho phép tự tạo device dựa theo chuẩn giao tiếp, dữ liệu ... cơ mà
Attached FilesMồm chó vó ngựa
Comment
-
Đó là khoảng cách giữa lý thuyết và thực tế thôi, cái Proteus nó lý tưởng hóa quá trình khởi tạo cái MMC còn thực tế thì chuối hơn nhiều, có nhiều chỗ còn không ghi trong reference toàn phải tự mò. Bạn hỏi mà không có SCH, không một dòng code thì trả lời bằng ... niềm tin ahNguyên văn bởi sonbka2002 Xem bài viếtGiờ thì làm lý thuyết chạy ầm ầm đcọ ghi Oki nhưng khổ lỗi khi ráp mạch thì nó lại không đọc ghi được vào MMC.bác có kinh nghiệm gì không ?
Comment
-
Diagram thì phía trên em đã Post.còn Code 2 File xử lý với MMC thì đây
Code:#include <Avr/io.h> #include "mmc.h" #include "uart.h" #include "rprintf.h" #include "debug.h" #include<stdio.h> char FAT_SECTOR_BUFFER_ADDR[512]; int main() { int i =0; uartInit(); // initialize UART (serial port) uartInitBuffers(); uartSetBaudRate(9600); // set UART speed to 9600 baud rprintfInit(uartSendByte); // configure rprintf to use UART for output rprintf("Hello World\r\n"); delay_ms(100); char buff[512]; #define MMC_DEBUG mmcTest(); // mmcInit(); // mmcReset(); // mmcRead(0,buff); // for(i =1;i<=32;i++) // { // buff[i]=i+64; // } // memset(buff,'A',512); // mmcWrite(0,buff); // rprintfStr(buff); } void delay_ms(unsigned short ms) { unsigned short outer1, outer2; outer1 = 200; while (outer1) { outer2 = 1000; while (outer2) { while ( ms ) ms--; outer2--; } outer1--; } } void mmcTest(void) { u32 sector=1; u08 buffer[0x200]; u08 buffRead[0x200]; int c; int i =0; for(i =1;i<=512;i++) { buffer[i]=65; } // initialize MMC interface mmcInit(); mmcReset(); // print new prompt rprintf("\r\nNhap vao ma : I-Init r-Read w-Write >"); // testing loop while(1) { // check for keypress if((c=uartGetByte()) != -1) { rprintf("%c",c); switch(c) { case 'i': // initialize card rprintf("\r\nResetting MMC/SD Card\r\n"); mmcReset(); break; case 'r': // read current sector into buffer rprintf("\r\nRead Sector %d\r\n", sector); mmcRead(sector, buffRead); delay_ms(3000); for(i =1;i<=512;i++) { rprintf("%c",buffRead[i]); } // print buffer contents //debugPrintHexTable(0x200, buffer); break; case 'w': // write current sector with data from buffer rprintf("\r\nWrite Sector %d\r\n", sector); mmcWrite(sector, buffer); delay_ms(3000); break; // move to new sector case '+': sector++; rprintf("\r\nSector = %d", sector); break; case '-': sector--; rprintf("\r\nSector = %d", sector); break; case '*': sector+=512; rprintf("\r\nSector = %d", sector); break; case '/': sector-=512; rprintf("\r\nSector = %d", sector); break; case '\r': default: break; } // print new prompt rprintf("\r\nNhap vao ma : I-Init r-Read w-Write >"); } } }Code:/*! \file mmc.c \brief MultiMedia and SD Flash Card Interface. */ //***************************************************************************** // // File Name : 'mmc.c' // Title : MultiMedia and SD Flash Card Interface // Author : Pascal Stang - Copyright (C) 2004 // Created : 2004.09.22 // Revised : 2006.06.12 // Version : 0.1 // Target MCU : Atmel AVR Series // Editor Tabs : 4 // // NOTE: This code is currently below version 1.0, and therefore is considered // to be lacking in some functionality or documentation, or may not be fully // tested. Nonetheless, you can expect most functions to work. // // This code is distributed under the GNU Public License // which can be found at http://www.gnu.org/licenses/gpl.txt // //***************************************************************************** //----- Include Files --------------------------------------------------------- #include <avr/io.h> // include I/O definitions (port names, pin names, etc) #include <avr/interrupt.h> // include interrupt support #include "global.h" // include our global settings #include "spi.h" // include spi bus support #include "rprintf.h" #include "mmc.h" // include project-specific hardware configuration #include "mmcconf.h" // Global variables // Functions void mmcInit(void) { // initialize SPI interface spiInit(); // release chip select sbi(MMC_CS_DDR, MMC_CS_PIN); sbi(MMC_CS_PORT,MMC_CS_PIN); } u08 mmcReset(void) { u08 i; u08 retry; u08 r1=0; retry = 0; do { // send dummy bytes with CS high before accessing for(i=0;i<10;i++) spiTransferByte(0xFF); // resetting card, go to SPI mode r1 = mmcSendCommand(MMC_GO_IDLE_STATE, 0); #ifdef MMC_DEBUG rprintf("MMC_GO_IDLE_STATE: R1=0x%x\r\n", r1); #endif // do retry counter retry++; if(retry>10) return -1; } while(r1 != 0x01); // TODO: check card parameters for voltage compliance // before issuing initialize command retry = 0; do { // initializing card for operation r1 = mmcSendCommand(MMC_SEND_OP_COND, 0); #ifdef MMC_DEBUG rprintf("MMC_SEND_OP_COND: R1=0x%x\r\n", r1); #endif // do retry counter retry++; if(retry>100) return -1; } while(r1); // turn off CRC checking to simplify communication r1 = mmcSendCommand(MMC_CRC_ON_OFF, 0); #ifdef MMC_DEBUG rprintf("MMC_CRC_ON_OFF: R1=0x%x\r\n", r1); #endif // set block length to 512 bytes r1 = mmcSendCommand(MMC_SET_BLOCKLEN, 512); #ifdef MMC_DEBUG rprintf("MMC_SET_BLOCKLEN: R1=0x%x\r\n", r1); #endif // return success return 0; } u08 mmcSendCommand(u08 cmd, u32 arg) { u08 r1; // assert chip select cbi(MMC_CS_PORT,MMC_CS_PIN); // issue the command r1 = mmcCommand(cmd, arg); // release chip select sbi(MMC_CS_PORT,MMC_CS_PIN); return r1; } u08 mmcRead(u32 sector, u08* buffer) { u08 r1; u16 i; // assert chip select cbi(MMC_CS_PORT,MMC_CS_PIN); // issue command r1 = mmcCommand(MMC_READ_SINGLE_BLOCK, sector<<9); #ifdef MMC_DEBUG rprintf("MMC Read Block R1=0x%x\r\n", r1); #endif // check for valid response if(r1 != 0x00) return r1; // wait for block start while(spiTransferByte(0xFF) != MMC_STARTBLOCK_READ); // read in data for(i=0; i<0x200; i++) { *buffer++ = spiTransferByte(0xFF); } // read 16-bit CRC spiTransferByte(0xFF); spiTransferByte(0xFF); // release chip select sbi(MMC_CS_PORT,MMC_CS_PIN); // return success return 0; } u08 mmcWrite(u32 sector, u08* buffer) { u08 r1; u16 i; // assert chip select cbi(MMC_CS_PORT,MMC_CS_PIN); // issue command r1 = mmcCommand(MMC_WRITE_BLOCK, sector<<9); #ifdef MMC_DEBUG rprintf("MMC Write Block R1=0x%x\r\n", r1); #endif // check for valid response if(r1 != 0x00) return r1; // send dummy spiTransferByte(0xFF); // send data start token spiTransferByte(MMC_STARTBLOCK_WRITE); // write data for(i=0; i<0x200; i++) { spiTransferByte(*buffer++); } // write 16-bit CRC (dummy values) spiTransferByte(0xFF); spiTransferByte(0xFF); // read data response token r1 = spiTransferByte(0xFF); if( (r1&MMC_DR_MASK) != MMC_DR_ACCEPT) return r1; #ifdef MMC_DEBUG rprintf("Data Response Token=0x%x\r\n", r1); #endif // wait until card not busy while(!spiTransferByte(0xFF)); // release chip select sbi(MMC_CS_PORT,MMC_CS_PIN); // return success return 0; } u08 mmcCommand(u08 cmd, u32 arg) { u08 r1; u08 retry=0; // send command spiTransferByte(cmd | 0x40); spiTransferByte(arg>>24); spiTransferByte(arg>>16); spiTransferByte(arg>>8); spiTransferByte(arg); spiTransferByte(0x95); // crc valid only for MMC_GO_IDLE_STATE // end command // wait for response // if more than 8 retries, card has timed-out // return the received 0xFF while((r1 = spiTransferByte(0xFF)) == 0xFF) if(retry++ > 8) break; // return response return r1; }
Comment
-
Khi toi viet code cho AVR toi khong bao gio dung len nhu the nay: a = (a & (1 << b)). Toi khong biet y nghia cua lenh nay nhu the nao nua.
Tai soa khong or , xor, and, cho khoe lam vay lam chi vay
Cac bac nao hieu ro chi dum cho
Tui da thu chay roi va card doc ghi tot binh thuongLast edited by sphinx; 17-10-2007, 19:28.
Comment
-
Dịch trái b 1 lần (nhân nó với 2), sau đó and kiểu bit với a và gán kết quả lại cho a. Viết thế này tận dụng đựoc tập lệnh của vi điều khiển nên tốc độ thực thi sẽ cao, mã lệnh ngắn, dễ hiểu.Nguyên văn bởi onggia Xem bài viếtKhi toi viet code cho AVR toi khong bao gio dung len nhu the nay: a = (a & (1 << b)). Toi khong biet y nghia cua lenh nay nhu the nao nua.
@sonbka2002, thay con 1K trong SCH thành con 2k2, mã lệnh thứ 2 dùng cho MMC thì đúng.
Comment
-
Nguyên văn bởi phamthaihoa Xem bài viếtDịch trái b 1 lần (nhân nó với 2)
hình như phải là dịch trái 1 đi b lần rồi and với a chứ. Xin chỉ giáo rõ hơn một chút. Hình như trong C thì đối tượng phải dịch đứng trước, đối tượng dịch đứng sau. CHECK lại hộ cái, cái này mình không rõ lắm. nhưng mình thường viết đối tượng phải dịch đứng trước.
Comment
-
bác nói chí phải!Nguyên văn bởi phamthaihoa Xem bài viếtTớ khuyên thật, cầm mỏ hàn đê, đừng mang câu hỏi giả lập bằng proteus nên diễn đàn để hỏi. Chạy thật, lỗi thật thì còn biết đường mà trả lời.
Comment
Bài viết mới nhất
Collapse
-
Trả lời cho Đấu tắt điện cho máy tính bảngbởi bqvietBqv cáo lỗi vì chưa đủ khả năng diễn giải để người đọc hiểu. Người làm kỹ thuật sâu đôi khi như thế đó. Về việc nạp pin không vào dù cell mới, khả năng cái mạch quản lý đó đã hỏng - cũng chính là nguyên nhân đám cell cũ hỏng từ đầu.
-
Channel: Thiết bị điện tử cá nhân
06-12-2025, 17:17 -
-
Trả lời cho Xin hỏi về mạch thu FM/AM trong catsettebởi nguyendinhvanTheo tôi, nó chỉ là cái Tuy- ê - nơ, hoặc là khối Trung Văn Tần, nó một phần trong cái Da đì ô thôi. Vì có thấy một chỗ có ba chân hàn, giiống như chân Cờ rít sờ tăng 455 ki nô hẹc. Còn khối Tuy ê nơ thì không nhìn thây cái Di ốt Va di cáp...
-
Channel: Điện thanh
05-12-2025, 19:59 -
-
Trả lời cho Đấu tắt điện cho máy tính bảngbởi afrendlyCó vẻ ngoài hiểu biết của mình rồi. Cuối cùng mình quyết định tìm mua 2 pin trên Shopee, giá 200K thay vào. Tuy nhận pin được 1%, sạc mãi không vào nhưng cũng mở được máy lên. Vậy cũng tạm. Cảm ơn bạn đã hỗ trợ nhé....
-
Channel: Thiết bị điện tử cá nhân
04-12-2025, 01:27 -
-
Trả lời cho Máy điện châm ?bởi nick22Đúng như bạn nói, máy điện châm hiện nay trên thị trường đã khá đa dạng về mẫu mã, chức năng và giá thành.
-
Channel: Điện tử y sinh
01-12-2025, 13:23 -

Comment