data token not come in sdhc card

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

data token not come in sdhc card

579 Views
sonuprajapat
Contributor II

hi  i doing project on sdhc card with lpc2468 in spi mode. my card is working fine but when i read a block and then erase a block and then again read block now data token 0xfe is not come . what could be problem i do not understand please help me .

my erase and read function as ...

UWORD8 SDHC_Block_read(UWORD32 Block_no)
{

UWORD8 block_lenght_cmd[6]= {0x50,0x00,0x00,0x02,0x00,0xFF}; //set block lenght 512
UWORD8 Block_No_command[6]= {0x51,0x00,0x00,0x00,0x00,0xFF};
int a,dummy;
// unsigned char data;

Block_No_command[4] = Block_no & 0xFF;
Block_no = Block_no >> 8;
Block_No_command[3] = Block_no & 0xFF;
Block_no = Block_no >>8;
Block_No_command[2] = Block_no & 0xFF;
Block_no = Block_no >>8;
Block_No_command[1] = Block_no & 0xFF;
// lk.st_com=TRUE;
//******************* select block lenght ***************
dummy = SPI_ReceiveByte(); //Send some dummy clocks

FIO0CLR = SPI0_SEL;
spi_send(block_lenght_cmd,6);
if( mmc_response(0x00) == 1 ) //if response is 0x00 then procced else hang the program
{


FIO0SET = SPI0_SEL;
// while(1);
return 1;
}
else

FIO0SET = SPI0_SEL;
dummy = SPI_ReceiveByte();
//********************** send command to block read ************

FIO0CLR = SPI0_SEL;
spi_send(Block_No_command,6);
if( mmc_response(0x00) == 1 )
{

FIO0SET = SPI0_SEL;
// while(1);
return 1;
}
if( mmc_response(0xFE) == 1 ) //if data token is 0xFE then procced else hang the program
{

FIO0SET = SPI0_SEL;
// while(1);
return 1;
}

for(a=0;a<512;a++)
{
SDHC_Read_buffer[a] = SPI_ReceiveByte(); //receive the write bytes to mmc

}
dummy = SPI_ReceiveByte(); //receive end token bytes
dummy = SPI_ReceiveByte();

dummy = SPI_ReceiveByte();

FIO0SET = SPI0_SEL;
// lk.st_com=FALSE;
return 0;
}

void SDHC_Block_Erase(UWORD32 Start_Block_no,UWORD32 End_Block_no)
{
UWORD8 Erase_start_cmd[6]={0x60,0x00,0x00,0x00,0x00,0xFF}; //CMD32
UWORD8 Erase_end_cmd[6]={0x61,0x00,0x00,0x00,0x00,0xFF}; //CMD33
UWORD8 Erase_cmd[6]={0x66,0x00,0x00,0x00,0x00,0xFF}; //CMD38
int check,dummy;

Erase_start_cmd[4] = Start_Block_no & 0xFF;
Start_Block_no = Start_Block_no >> 8;
Erase_start_cmd[3] = Start_Block_no & 0xFF;
Start_Block_no = Start_Block_no >>8;
Erase_start_cmd[2] = Start_Block_no & 0xFF;
Start_Block_no = Start_Block_no >>8;
Erase_start_cmd[1] = Start_Block_no & 0xFF;

Erase_end_cmd[4] = End_Block_no & 0xFF;
End_Block_no = End_Block_no >> 8;
Erase_end_cmd[3] = End_Block_no & 0xFF;
End_Block_no = End_Block_no >>8;
Erase_end_cmd[2] = End_Block_no & 0xFF;
End_Block_no = End_Block_no >>8;
Erase_end_cmd[1] = End_Block_no & 0xFF;

//******************* select block lenght ***************
dummy = SPI_ReceiveByte(); //Send some dummy clocks

FIO0CLR = SPI0_SEL;
spi_send(Erase_start_cmd,6);

if( mmc_response(0x00) == 1 ) //if response is 0x00 then procced else hang the program
{

FIO0SET = SPI0_SEL;
while(1);
}
else

FIO0SET = SPI0_SEL;
dummy = SPI_ReceiveByte();
/*************************************************************************/

FIO0CLR = SPI0_SEL;
spi_send(Erase_end_cmd,6);

if( mmc_response(0x00) == 1 ) //if response is 0x00 then procced else hang the program
{

FIO0SET = SPI0_SEL;
while(1);
}
else
FIO0SET = SPI0_SEL;
dummy = SPI_ReceiveByte();
/*************************************************************************/

FIO0CLR = SPI0_SEL;
spi_send(Erase_cmd,6);
if( mmc_response(0x00) == 1 ) //if response is 0x00 then procced else hang the program
{

FIO0SET = SPI0_SEL;
while(1);
}
if(wait_wr_finish() == 1)
{

FIO0SET = SPI0_SEL;
while(1);
}
else

FIO0SET = SPI0_SEL;
// dummy = SPI_ReceiveByte();
// dummy = SPI_ReceiveByte();
}@@#@

0 Kudos
2 Replies

431 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi,

Have you ensured that the clocks are correctly synchronized? Additionally, on the following links you could find some useful information regarding SD connection on LPC2468:

http://www.keil.com/forum/19657/how-connect-sd-card-to-lpc2468/

http://forums.ni.com/t5/LabVIEW-Embedded/how-connect-sd-card-to-lpc2468/td-p/1733096


Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

431 Views
sonuprajapat
Contributor II

Thanks for replay,

I think clock is correct because this work fine on one other card .

/sonu

0 Kudos