AnsweredAssumed Answered

data token not come in sdhc card

Question asked by sonu prajapat on Mar 8, 2017
Latest reply on Mar 18, 2017 by sonu prajapat

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();
}@@#@

Outcomes