Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: SPI / SD on lpc2106

2005-10-11 by armqamp

I defined the commands like this:

#define CMD0 0x40	// software reset
#define CMD1 0x41	// brings card out of idle state
#define CMD2 0x42	// not used in SPI mode
#define CMD3 0x43	// not used in SPI mode
#define CMD4 0x44	// not used in SPI mode
#define CMD5 0x45	// Reserved
#define CMD6 0x46	// Reserved
#define CMD7 0x47	// not used in SPI mode

and so on...


thanks,

Wouter


--- In lpc2000@yahoogroups.com, "theothervmax" <vmax@g...> wrote:
>
> --- In lpc2000@yahoogroups.com, "armqamp" <wouter@w...> wrote:
> >
> > Hello,
> > 
> > I'm trying to make an SD card to work with the lpc2106 and later want
> > to implement FAT.
> > The problem is I don't get any response of the SD card when I try to
> > initialize it.
> > 
> > Maybe somebody can disover what I'm doing wrong?
> > 
> > here is the code:
> > 
> > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> > 
> > void ActivateSD(void){
> > 	
> > 	unsigned int ii=0;
> > 	unsigned char resp, i;
> > 	unsigned char status;
> > 	
> > 	print("Activating SD Card....\n\n");
> > 
> > 	// Turn off SD Card
> > 	SD_power_off;
> > 
> > 	// Wait for power to really go down
> > 	for(ii = 0; ii; ii++);
> > 	for(ii = 0; ii; ii++);
> > 	for(ii = 0; ii; ii++);
> > 	for(ii = 0; ii; ii++);
> > 
> > 	// Turn on SD Card
> > 	SD_power_on;
> > 
> > 	// Wait for power to really come up
> > 	for(status = 0; status < 10; ++status)
> > 	{
> > 		for(ii = 0; ii; ii++);
> > 		for(ii = 0; ii; ii++);
> > 		for(ii = 0; ii; ii++);
> > 		for(ii = 0; ii; ii++);
> > 	}
> > 	
> > 	
> > 	
> > 	
> > 	
> > 	for(i=1; i<=10; i++){	                //try 10 times to wake up
the card
> > 		
> > 		SD_disable;			//CS high
> > 		
> > 		InitSequence();			//send 80 clocks
> > 		
> > 		SD_enable;			//CS low
> > 		
> > 		SD_SendCommand(CMD0,0,0,0,0); //send Reset command
> > 		
> > 		resp = SD_Response();
> > 		if( resp == 0x01 ){          //wait for R1 response to be 0x01
> > 			break;
> > 		}
> > 		else{
> > 		
> > 		}
> > 		
> > 	}
> > 	
> > 	spiSendByte(0xFF);		   // Response received, send the required 8
> > clocks after the response to finish up (page 5-6 Sandisk Manual)
> > 
> > 	
> > 	if(i>10){
> > 		SD_disable;
> > 		print("SD activation failed\n");
> > 	}
> > 	else{
> > 		print("SD activation successfully\n");
> > 		
> > 		while( resp != 0x00){	                 //try sending CMD1 until
> > response R1 is 0x00
> > 			SD_SendCommand(CMD1,0,0,0,0);	 //activate card initialization
process
> > 			resp = SD_Response();
> > 			spiSendByte(0xFF);	         //send required 8 clocks
> > 			if(resp==0x00){		         // Ready
> > 				print("SD successfully activated!!!\n");
> > 				break;
> > 			}
> > 		}
> > 		
> > 		if(resp != 0x00){
> > 			print("Error: ");
> > 			print("0x"); printnum(16, 8, 0, '0', resp); print("\n");
> > 		}
> > 		
> > 	}
> > 	print("\n-------end-----------\n");
> > }
> > 
> > 
> > unsigned char SD_Response(void) {
> > 	unsigned char 	i;
> > 	unsigned char 	resp;	
> > 	
> > 	for(i=0; i<10; i++) {
> > 		resp = spiGetByte();
> > 		if(resp != 0xFF) {
> > 			return resp;
> > 		}
> > 	}		
> > 	return 0xFF;
> > }
> > 
> > void SD_SendCommand(unsigned char command, unsigned char arg_a,
> > unsigned char arg_b, unsigned char arg_c, unsigned char arg_d) {	
> > 	spiSendByte(command);
> > 	spiSendByte(arg_a);
> > 	spiSendByte(arg_b);
> > 	spiSendByte(arg_c);
> > 	spiSendByte(arg_d);
> > 	spiSendByte(0x95);				// correct CRC for first command in SPI after
> > that CRC is ignored, so no problem with always sending 0x95
> > }
> > 
> > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> >
> 
> First, what's the value of "CMD0" ? It must be 0x40.
> 
> Cheers, 
>  Max.
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.