Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: SDHC initialization problem with ACDM41
PostPosted: Sat Mar 17, 2012 12:00 am 
Offline

Joined: Fri Jan 13, 2012 11:06 am
Posts: 7
Hi everyone,

I don't know where i am making mistake, so i hopped someone of you will see what i do wrong.

I am trying to initialize an SDHC card in SPI mode using a at91sam7x512.

i have done everything up to ACMD41.

cmd0 (0x40 000000 95) -> response is R1 (0x01)
cmd8 (0x48 0001AA 87) -> response is R7 ( with good pattern 0xAA and good VCA )
cmd58 (0x7A 000000 95) -> gives me the expected R3 response

cmd55(0x77 000000 95) -> response is R1 (0x01)

acmd41(0x69 400000 95) -> response is R1(0x05)

And this is a problem, i always repeat acmd41 and response is 0x05, never 0x00.

In SD SPECIFICATION ver2.0 head 7.2.2 they suggest to turn CRC on before using acmd41.

So i try this and:

cmd0 (0x40 000000 95) -> response is R1 (0x01)
cmd8 (0x48 0001AA 87) -> response is R7 ( with good pattern 0xAA and good VCA )
cmd58 (0x7A 000000 95) -> gives me the expected R3 response

now i turn CRC on

cmd59(0x7B 000001 83) -> response is R1 (0x01)
cmd55(0x77 000000 65) -> response is R1(0x01)
acmd41(0x69 400000 77) -> response is always 0x05

Why i always get 0x05 response?

When i worked with SD card everything worked fine. After cmd0, i call cmd1 and get response 0x00.


Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Sat Mar 17, 2012 11:30 am 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi!
In ACMD41 you need to pass the that the host supports SDHC cards and you need to pass which voltage is handled. I initialize the card in SD mode, you in SPI mode, so there might be some differences. I attach you a snipped of the code where i initialize the card. Maybe this would be of some help:

//CMD55 -- leading command for ACMD commands. The argument is always 0
MCI_SendCommand( MCI_CMD_APP_CMD | AT91C_MCI_MAXLAT | AT91C_MCI_RSPTYP_48, 0 );
MCI_GetResponse48( response );

//Issue ACMD41 to get OCR
//bit 30 is HCS bit and FF8 is voltage mask (see page 55 of SDHC simplified spec)
MCI_SendCommand( MCI_ACMD_OP_COND | AT91C_MCI_RSPTYP_48, MCI_OCR_VOLTAGE_WINDOW | MCI_HCS_BIT);
MCI_GetResponse48( response ); //Get R3 response
TRACE_INFO( "MCI: ACMD_OP_COND response: 0x%x ", response[ 0 ] );

The necessary definitions are:
#define MCI_OCR_VOLTAGE_WINDOW 0x0FF8000

#define MCI_HCS_BIT ( 1 << 30 )

If this does not work, come back and we'll try sth else.

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Sat Mar 17, 2012 6:04 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi.
I've just checked in the specification and in the SPI mode you do not pass the voltage window bits. 30 bit needs to be on to signalize High Capacity.

Mind, you need to provide several dozens of empty cycles between CMD58, CMD55 and ACMD41 to give the card clock to prepare for the next stage.

If you are in a deadlock, I'll find my project working under AT91SAM7x to see how I implemented it exactly and what responses I got.

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Sun Mar 18, 2012 11:26 pm 
Offline

Joined: Fri Jan 13, 2012 11:06 am
Posts: 7
Hi, thanks for your reply.

For ACMD41 command in SD mode as argument i have to pass voltage, but not in the SPI mode. In SPI mode i only have to set HCS bit and that is 30 bit, what i have done
ACMD41:
command - 0x69
argument - 0x400000
crc - depend did i turn on or off CRC check

i also try to put empty cycles between CMD58, CMD55 and ACMD41 but that don't help me.

This is my code, which work fine until ACMD41command (Initialization od SD card in SPI mode):


i = 0;
do
{
SD_status = SDSPI_WriteCommand(cmd0,0); // Send cmd0 with argument 0x000000 and CRC 0x95
if(i++>250) {return SD_status = SD_NOT_FOUND; } // fail and return
} while( SD_status != 0x01 ); // idle state

// cmd0 line pass with correct response (0x01)

SET_COUNTDOWN(20); while(counter_down) {SDSPI_dummy_byte();} // set timer to 20 ms to send dump byte in idle state

i = 0;
do
{
SD_status = SDSPI_CMD8(cmd8,0x1AA); // send cmd8 with argument 0x0001AA and CRC 0x87
if(i++>500) { return SD_status = SD_NOT_FOUND;}
} while( ((SD_status != 1)||(response7[4]!=0xAA))&&(SD_status != 0x4) );// to go out from loop it must be correct pattern and (illegal command or correct response)
if(SD_status==0x4) printf("It is Standard Capacity Card Version 1.x\n\r"); // if it is illegal command it means it is standard capacity SD card ver 1.x
else if(SD_status==0x1)
{
if(response7[3]==0) // If VCA in response is set to 0, the card cannot operate on the supplied voltage
{
printf("Unusable card\n\r");
return;
}
}

//cmd8 line pass with correct response, good pattern 0xAA and good voltage

SET_COUNTDOWN(250); // Give card a time to read voltage level let's say 250 ms
do
{
SD_status = SDSPI_READ_OCR(cmd58,0); // cmd58 command with argument 0x000000 - read OCR register
if (CARD_IN()) { return SD_status = SD_NOT_FOUND; } // if someone take card out stop process of initialization
} while ((SD_OCR[0]!=0x80)&&(counter_down));

if(SD_OCR[0]&0x40) printf("It is SDHC card\n\r");
else printf("It is SD card\n\r");

printf("SD_OCR[0]=%x\n\r",SD_OCR[0]); // write bits of OCR register to terminal
printf("SD_OCR[1]=%x\n\r",SD_OCR[1]);
printf("SD_OCR[2]=%x\n\r",SD_OCR[2]);
printf("SD_OCR[3]=%x\n\r",SD_OCR[3]);

//cmd58 line pass. Correctly read OCR register

i = 0;
do
{
SD_status = SDSPI_CMD59_ON(cmd59,0x1); // command cmd59 with argument 0x1 turn on CRC check. This is recommended to do before command ACMD41. Head 7.2.2 Bus Transfer Protection, page 96 Simplified Specification Version 2.0
if(i++>250) {return SD_status = SD_NOT_FOUND} // if someone take card out stop process of initialization
} while( (SD_status ) != 1 );

//cmd59 line pass. Response R1(0x01)

i = 0;
do
{
SD_status = SDSPI_CMD55(cmd55,0); // Send cmd55 command before ACMD41 command with argument 0x000000 and CRC 0x65
if(i++>250) {return SD_status = SD_NOT_FOUND} // if someone take card out stop process of initialization
} while( (SD_status ) != 1 );

//cmd55 line pass. Response R1(0x01)

i = 0;
do
{
SD_status = SDSPI_ACMD41(0x29,0x40000000); // send ACMD41 (0x69) with argument 0x400000 and CRC 0x77
if(i++>1500) {return SD_status = SD_NOT_FOUND} // if someone take card out stop process of initialization
} while( (SD_status & 0x1 ) != 0 );

//ACMD41 line fail. Response R1 is always 0x05 , and i dont know what to do, i am really stuck i dont know what i have to do to get 0x00 response?


// Note this: I also try after cmd58 command not to turn CRC on (cmd59 command) but result is the same. Always after ACMD41 command i get 0x05 response.

przemekbary if you still have your project i would appreciate if i could see how did you do it.
I am sure that i have made some stupid mistake but i don't see it.

Regards
Bane


Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Mon Mar 19, 2012 12:45 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi
Due to my gypsum cast I am housebound for the time being and don't have the access to my PC at work. Have you looked at Chan's SD implementation in the SPI mode? Herewith, I attach a file. You can also have a look at:
http://elm-chan.org/fsw/ff/00index_e.html

If you make it through, let me know what was wrong.


Attachments:
mmc.zip [5.67 KiB]
Downloaded 29 times

_________________
Best regards
Przemyslaw Baranski
Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Mon Mar 19, 2012 8:45 pm 
Offline

Joined: Fri Jan 13, 2012 11:06 am
Posts: 7
Hi Baranski and thanks for your replay,

I finally found solution. This is what i have to change in my code to pass ACMD41 command:

i = 0;
do
{
SD_status = SDSPI_CMD55(cmd55,0); //immediately after CMD55 i should start ACMD41 command
SD_status = SDSPI_ACMD41(0x29,0x40000000);
if(i++>250) {return SD_status = SD_NOT_FOUND;}
} while( SD_status != 0 );

It is little crazy that because of this little difference in code i had so much problem, but that's how it is.

Also here is a good site for all who are interest in SDHC implementation and FAT implementation.

http://www.dharmanitech.com/2009/01/sd- ... fat32.html

However this is example for ATmega but could be educational.

I wish you quick recovery :)

Regards
Bane


Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Mon Mar 19, 2012 9:03 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi
Good to hear you've found the solution. Good luck

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: SDHC initialization problem with ACDM41
PostPosted: Mon Mar 19, 2012 9:18 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi
I've just found my project. You should take care with writing onto the card. There were delays required. Otherwise the card got stuck and would not want to budge.

bool SD_WriteSector( char *sourceBuffer, int sector )
{
int i = 100;
for( ; i > 0; i-- )
{
char response = SD_WriteCommand( SD_WRITE_BLOCK, sector << 9 );
if( response != 0x00 )
{
SD_WriteDummyBytes( 20 );
}
else
break;

}

if( i == 0 )
return false;

// Wait100us( 1 ); //necessary with some cards and not with others

SD_WriteDummyBytes( 10 );
SD_WriteByte( SD_STARTBLOCK_WRITE );
for( int i = 0; i < 0x200; i++ )
{
SD_WriteByte( *sourceBuffer++ );
}
//write CRC - not relevant
SD_WriteByte( 0xFF );
SD_WriteByte( 0xFF );
//check response

while( SD_WriteByte( 0xFF ) != 0xFF );
SD_WriteDummyBytes( 20 );
return true;
}

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to: