Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MMC ROOT Directory Writing

Status
Not open for further replies.

patrikshah

Newbie level 5
Joined
Mar 27, 2007
Messages
10
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,358
hi,
I am interfacing MMC card with LPC2148 SPI based . I have one application note from NXP which

shows how to interface SD /MMC (512 MB) card using SPI for FAT16.

using that code i am able to write & Read data . So i am able to read data from (Sector 0- Boot

sector , Sector 6 - FAT table sector , sector 528 - Data sector )

but when i am accessing or writing data to Root Directory sector , its not able to write or read data to

& from that secotr - 496 .

when i am writing it to sector - 496 data is getting stored on 432 =Difference 64
When i am writing it to sector - 498 data is getting stored on 434 = Difference 64
When i am writing it to sector - 510 data is getting stored on 445 = Difference 64



So can any one tell me Is there any other merhod to write data in to ROOT DIRECTORY .

I am attaching my code here


if ( mmc_write_block(495,rootdirectory_info) == 0 )
{
mmc_read_block (496);
Display_Read_parameter (496) ;
}
else
{
while ( 1 ); /* Very bad

happened */
}



int mmc_write_block(WORD block_number, BYTE* MMCWRDATA)
{
WORD varl, varh;
BYTE Status;

IOCLR0 = SPI_SEL; /* clear SPI SSEL */

/* block size has been set in mmc_init() */
varl=((block_number&0x003F)<<9);
varh=((block_number&0xFFC0)>>7);

/* send mmc CMD24(WRITE_SINGLE_BLOCK) to write the data to
MMC card */
MMCCmd[0] = 0x58;
/* high block address bits, varh HIGH and LOW */
MMCCmd[1] = varh >> 0x08;
MMCCmd[2] = varh & 0xFF;
/* low block address bits, varl HIGH and LOW */
MMCCmd[3] = varl >> 0x08;
MMCCmd[4] = varl & 0xFF;
/* checksum is no longer required but we always send 0xFF */
MMCCmd[5] = 0xFF;
SPI_Send(MMCCmd, MMC_CMD_SIZE );

/* if mmc_response returns 1 then we failed to get a 0x00
response */
if((mmc_response(0x00))==1)
{
MMCStatus = WRITE_BLOCK_TIMEOUT;
IOSET0 = SPI_SEL; /* set SPI SSEL */
return MMCStatus;
}

/* Set bit 0 to 0 which indicates the beginning of the data block */
MMCCmd[0] = 0xFE;
SPI_Send( MMCCmd, 1 );

/* send data, pattern as 0x00,0x01,0x02,0x03,0x04,0x05 ...*/
SPI_Send( MMCWRDATA, MMC_DATA_SIZE );

/* Send dummy checksum */
/* when the last check sum is sent, the response should come back
immediately. So, check the SPI FIFO MISO and make sure the status
return 0xX5, the bit 3 through 0 should be 0x05 */
MMCCmd[0] = 0xFF;
MMCCmd[1] = 0xFF;
SPI_Send( MMCCmd, 2 );

Status = SPI_ReceiveByte();
if ( (Status & 0x0F) != 0x05 )
{
MMCStatus = WRITE_BLOCK_FAIL;
IOSET0 = SPI_SEL; /* set SPI SSEL */
return MMCStatus;
}

/* if the status is already zero, the write hasn't finished
yet and card is busy */
if(mmc_wait_for_write_finish()==1)
{
MMCStatus = WRITE_BLOCK_FAIL;
IOSET0 = SPI_SEL; /* set SPI SSEL */
return MMCStatus;
}

IOSET0 = SPI_SEL; /* set SPI SSEL */
SPI_ReceiveByte();
return 0;
}





So Please help me how to solve this problem

Regards,
Pratik
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top