mmc card writing problem

Status
Not open for further replies.

ibrahim03

Full Member level 1
Joined
Sep 29, 2005
Messages
99
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,288
Activity points
2,335
I am trying to store some data in a mmc card using the ATMEGA8515L microcontroller. I studied the code from the following site :

http://www.captain.at/electronic-atmega-mmc.php


My problem is that the card initializes properly(as indicated by the LED) but the writeramtommc() method is not executed because the card gives an incorrect response to the write command.


The trouble is that I am using ATMEGA8515L instead of mega32 and it has only 512 bytes os SRAM so I cannot write a sector of 512 bytes instead I have reduced it to 256 bytes, is that ok?

Also I have some confusion about the address in the write command. Did the guy who wrote the original code give the address of 512 in the write command because he was writing a 512 byte sector ? I think it can be anything, right ?

Also there is a question about the speed of the SPI port in the original code ,when initializing the MMC to the SPI interface, the speed of the SPI was decreased( by setting the bits in SPCR register) but after initialization the speed was never increased. Should it not be increased again.

Another thing, in the 'fillram()' method in the for loop:
for (i=0;i<=512;i++)

it should be
for (i=0;i<512;i++)
because the data block is 512 bytes and not 513 bytes.

I think there really are some bugs in this code !!
 

I believed that SD/MMC need 512 bytes to write,
but reading could be less.
I can't help you much, but may I suggest you look here
http://elm-chan.org/fsw/ff/00index_e.html
I use it in a Pic24h and it's working well (note that Pic24H has lots of RAM tho)

good luck!
 

Hi,

For SD cards you need to write 512 bytes of data for 99% of cards out there. There are some new ones from Sandisk that allow <512 byte writes but I don't think they will catch on, writing 256 bytes is not a problem though as all you do is write 256 bytes of real data then do a loop
Code:
for (n=0;n<256;n++) writedata(myarray[n]); // Real data
for (n=0;n<256;n++) writedata(0x00); // Dummy blanks
to fill in the rest of the 512 with blanks, OK this wastes 1/2 of the memory but most SD cards are 32Mb or bigger!, so you still have alot to play with.

You MUST address the data in 512 chunks or multiples thereof no exceptions, you will generate an error of you try anything different, also please note that SD cards have a little less memory available that the stated value, this is for a "failure block" that allows the controller in the SD card to write data to a "spare" location if it has an error in a sector, it reduces the overall available memory by about 5% maybe a little less.

Fox.
 

    ibrahim03

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…