| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Wizard 
 
 
 Joined: 27 Mar 2006
 Posts: 9
 
 
 
			        
 
 | 
			
				| MMC SPI interfacing |  
				|  Posted: Mon Mar 27, 2006 2:55 pm |   |  
				| 
 |  
				| Hi there! 
 I'm adding a mmc card to my data adquisition project. I'm using a pic18f4550 with usb conection implemeted. I use a 1.8k and 3.3k voltage divider circuit to convert the 5V from the pic to aporx. 3V to the card. As in: http://www.cc5x.de/MMC/
 I know that it doesn't suit the standart but peolple have it working. So far I have tried the mmc_spi.c drivers, without good results. I have tested it with two mmc cards(32mb and 256mb) I got nothing from the 256 one. With the 32mb card I can reset it with some problems:
 
  	  | Code: |  	  | int mmc_status;
 mmc_status=mmc_init();
 printf(lcd_putc, "MMC status: %u", mmc_status);
 
 | 
 I got a 0(MMC_EC_OK) from mmc_init so I guess its working, if I disconect the card I get a 1(MMC_EC_NOT_IDLE).
 
 The very problem is when I write a sector in the mmc and after that I read it. After write and read I get the commands that all have gone well, but I read diferents values from those which I wrote previously
  . So something its pointing to a bad direction. 
 I would like someone to give some information about the best circuit(or a working one
  ) to interface a 5V pic with a mmc card. I have used the functions from the mmc_spi.c because its a fast way to begin around the mmc card instead I dont like that they dont use the SPI hardware module, I would be pleased to see others codes. Also it would be useful to se an example of using the mmc_spi functions. 
 here its my MMC testing code:
 
 
  	  | Code: |  	  | #include <18F4550.h>
 
 #fuses HS
 #fuses PLL5
 #fuses CPUDIV1
 #fuses USBDIV
 #fuses VREGEN
 #fuses NOWDT
 #fuses NOPROTECT
 #fuses NOLVP
 #fuses NODEBUG
 
 #use delay(clock = 20000000)
 
 #define Led_on          PIN_E1
 #define Led_USB_ready   PIN_E2
 #define Led_Red         PIN_C6
 #define Led_Yellow      PIN_C7
 
 
 #define MMC_CLK   PIN_B1
 
 #define MMC_DI    PIN_B0
 
 #define MMC_DO    PIN_B3
 
 #define MMC_CS    PIN_B2
 
 #include "files/mmc_spi.c"
 #include "files/LCD420.c"
 
 void main(void)
 {
 
 int mmc_status=35;
 int mmc_hex[512];
 int16 i;
 
 SETUP_ADC_PORTS(NO_ANALOGS);
 
 for(i=0;i<512;i++)
 {
 mmc_hex[i]==175;//0xAF
 }
 
 
 lcd_init();
 output_high(Led_Yellow);
 lcd_gotoxy(1,1);
 printf(lcd_putc, "System Init");
 printf(lcd_putc, "\nMMC status: %u", mmc_status);
 delay_ms(1000);
 output_low(Led_Yellow);
 
 mmc_status=mmc_init();
 
 lcd_putc("\f");
 lcd_gotoxy(1,2);
 printf(lcd_putc, "MMC status: %u", mmc_status);
 
 output_high(Led_Yellow);
 delay_ms(2000);
 output_low(Led_Yellow);
 
 mmc_status=mmc_write_block(0, 512, mmc_hex);
 
 lcd_gotoxy(1,2);
 printf(lcd_putc, "MMC status: %u", mmc_status);
 delay_ms(2000);
 
 mmc_status=mmc_read_block(0, 512, mmc_hex);
 
 lcd_gotoxy(1,2);
 printf(lcd_putc, "MMC status: %u", mmc_status);
 lcd_gotoxy(1,3);
 printf(lcd_putc, "MMC byte 0: %X", mmc_hex[0]);
 lcd_gotoxy(1,4);
 printf(lcd_putc, "MMC byte 512: %X", mmc_hex[511]);
 
 while (TRUE)
 {
 }
 }
 
 
 | 
 
 thanks in advance guys, all information about mmc and pics its kindly acepted
 _________________
 Tomas L.
 |  |  
		|  |  
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 |  |  
		|  |  
		| ckielstra 
 
 
 Joined: 18 Mar 2004
 Posts: 3680
 Location: The Netherlands
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Mar 27, 2006 3:57 pm |   |  
				| 
 |  
				|  	  | Code: |  	  | mmc_hex[i]==175;//0xAF | 
 change to
 
  	  | Code: |  	  | mmc_hex[i]=175;//0xAF | 
 |  |  
		|  |  
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Tue Mar 28, 2006 6:02 am |   |  
				| 
 |  
				| Thanks ckielstra, that was my fault. Now, when the card its reseted I can write and read from the mmc card without problems. BUT the problem its to reset the card   
 I explain, when I power on th system and the card it's inserted, it can't be reseted, so nothing is going to work, I cant read neither write due it hasn't been reseted to spi mode. But if after the power on I extract the card from the MMC connector and insert it again, and later reset the pic to run again the program, the card it is mysteriously reseted and initiated OK:exclaim:, after that I can write and read.
 
 Also if I switch off the 5V power of the system but not the 3.3V voltage supply of the card and after that I power on the pic to run the program, it reset the card ok. I tried also to switch off the 3.3V supply of the mmc when the system and pic it's running and after that to reset the pic to execute the test program and It can't reset the mmc, like the card was disconnected, but if I extract the mmc and connect it again, the program works as I said before.
 
 So when I turn on the embedded system, if I want to use the mmc card I have to extract it and plug it again and reset the system. Thats really strange, any ideas??????
 
 the code it's still the same, with the change that ckielstra pointed:
 
  	  | Code: |  	  | for(i=0;i<512;i++)
 {
 mmc_hex[i]=175;//0xAF
 }
 
 | 
 |  |  
		|  |  
		| Wizard 
 
 
 Joined: 27 Mar 2006
 Posts: 9
 
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Tue Mar 28, 2006 6:06 am |   |  
				| 
 |  
				| It was me, I forgot to login before to post. 
 Waiting for any ideas ot information about the issue and mmc staff
 _________________
 Tomas L.
 |  |  
		|  |  
		| ckielstra 
 
 
 Joined: 18 Mar 2004
 Posts: 3680
 Location: The Netherlands
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Mar 28, 2006 5:38 pm |   |  
				| 
 |  
				| Looks like you have major problems in initializing the MMC card. Did you check out the thread mentioned by PCM Programmer? If you did you have noticed I'm not happy with the hardware design from that particular site. It's a quick-and-dirty design with some flaws in it and I don't feel like giving support on it. 
 Your program is incomplete, the file mmc_spi.c is missing.
 |  |  
		|  |  
		| Wizard 
 
 
 Joined: 27 Mar 2006
 Posts: 9
 
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Wed Mar 29, 2006 2:18 am |   |  
				| 
 |  
				| I know the interfacing circuit doesn't compile with the mmc specification, but I'm using the PIC18F4550 running on 5V. So I can't connect the mmc card spi lines directly with the pic pins with the pull-up resistors. I have thought to use a inverter with open collector outputs (ie. 74LS05) with 1.8K resitors to 3.3V at the outputs. Any ideas?
 _________________
 Tomas L.
 |  |  
		|  |  
		| C-H Wu Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| MMC level |  
				|  Posted: Wed Mar 29, 2006 8:01 pm |   |  
				| 
 |  
				| Suppose PIN_B3 is TTL level input, then you don't need level translator. 
 #define MMC_DO    PIN_B3
 
 For the other pins, all you need is simple voltage divider.
 
 #define MMC_CLK   PIN_B1
 #define MMC_DI    PIN_B0
 #define MMC_CS    PIN_B2
 
 For the power, I simply use two 0.7V diode like 1N4001 to get the voltage down to 3.6V from 5V with a 1 uF bypass capacitor.
 
 It works fine for me.
 
 Best wishes
 |  |  
		|  |  
		| Wizard 
 
 
 Joined: 27 Mar 2006
 Posts: 9
 
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Thu Mar 30, 2006 1:14 am |   |  
				| 
 |  
				| Thanks for the point, I think you mean that I dont need voltage divider in the #define MMC_DI PIN_B0 Line, which it's the data output of the MMC. That's how I have the circuit. 
 Thanks for the point of the diodes, I'll inform about any progress.
 _________________
 Tomas L.
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |