Giúp em về lỗi MMC

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • sonbka2002
    Thành viên mới
    • May 2007
    • 7

    #1

    Giúp em về lỗi MMC

    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
    Attached Files
  • phamthaihoa
    Thành viên hơi tích cực
    • Jul 2005
    • 1103

    #2
    Tớ 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

    • hieuacbk
      Thành viên mới
      • Sep 2006
      • 4

      #3
      duong dan cua Card mmc phai la 1 file .mmc(multimedia card) thi moi chay duoc, minh cung dang lam, trong thoi gian nghien cuu phan cung( neu ban lam chay share minh voi)
      thank!

      Comment

      • tuanpa
        Thành viên chính thức
        • Apr 2007
        • 33

        #4
        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

        • sonbka2002
          Thành viên mới
          • May 2007
          • 7

          #5
          sao em khởi tạo mãi cái thẻ nhớ nó không thèm chạy nhỉ .bác có kinh nghiệm gì không

          Comment

          • yankazaz
            Thành viên chính thức
            • Feb 2006
            • 57

            #6
            - 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 Files
            Mồm chó vó ngựa

            Comment

            • sonbka2002
              Thành viên mới
              • May 2007
              • 7

              #7
              Giờ 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

              • phamthaihoa
                Thành viên hơi tích cực
                • Jul 2005
                • 1103

                #8
                Nguyên văn bởi sonbka2002 Xem bài viết
                Giờ 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 ?
                Đó 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 ah

                Comment

                • sonbka2002
                  Thành viên mới
                  • May 2007
                  • 7

                  #9
                  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

                  • onggia
                    Thành viên mới
                    • Oct 2007
                    • 4

                    #10
                    Noi chung khong doc ghi duoc MMC , thi cau phai coi lai ki ca len goi xuong cho MMC co dung khong, neu khong dung no se khong doc ghi duoc.

                    Comment

                    • onggia
                      Thành viên mới
                      • Oct 2007
                      • 4

                      #11
                      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 thuong
                      Last edited by sphinx; 17-10-2007, 18:28.

                      Comment

                      • phamthaihoa
                        Thành viên hơi tích cực
                        • Jul 2005
                        • 1103

                        #12
                        Nguyên văn bởi onggia Xem bài viết
                        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.
                        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.

                        @sonbka2002, thay con 1K trong SCH thành con 2k2, mã lệnh thứ 2 dùng cho MMC thì đúng.

                        Comment

                        • cuongth
                          Thành viên mới
                          • Jul 2006
                          • 3

                          #13
                          Anh em nao đã lam về FAT cho MMC rồi nhỉ. Em dùng PIC, lên mạng tải mấy cai code của bọn CCS về sửa mà vẫn chưa chay. Bác nào đã làm có thể share cho em được không. Tim bên luông PIC không thấy nói j về vấn đề này

                          Comment

                          • namtuoc
                            Thành viên mới
                            • Aug 2005
                            • 5

                            #14
                            Nguyên văn bởi phamthaihoa Xem bài viết
                            Dị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

                            • hotuanhai
                              Thành viên chính thức
                              • Sep 2007
                              • 65

                              #15
                              Nguyên văn bởi phamthaihoa Xem bài viết
                              Tớ 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.
                              bác nói chí phải!

                              Comment

                              Về tác giả

                              Collapse

                              sonbka2002 Tìm hiểu thêm về sonbka2002

                              Bài viết mới nhất

                              Collapse

                              Đang tải...