I'm learning to use a MMC card, actually i am capable to read a sector, but i can't write, when i send the write command it doesn't answer with the appropiate response, then i can't to send the data, how can i do??, i send other commands and MMC responds ok. Im using MMC card in SPI mode, the card capacity is 32 Mb long.
Thanks, but i think i'm doing all correctly. When i send write command, MMC sends Address Error, but i don't understand why it happen, address is ok. Can you help me. If i can read a sector, why cannot i write a sector?.
For reading a single block at a time
1 Send the command
Send the read command, then the raw address (LBA *512).
2 Wait for a R1 response
Continue to send 255 till you get something back with bit 7 clear
If <> 0 then error.
3 Wait for token
Continue to send 255 till you get a start token
4 Read 512 bytes
5 Read 2 check sum bytes
It may be a good idea to add some timeout error handling so you don't get stuck in a loop is something goes wrong.
Phil
Added after 7 minutes:
Whoops WRITING NOT READING.
For writing a single block.
1 Send the command
Send the write command, then the raw address (LBA *512).
2 Wait for a R1 response
Continue to send 255 till you get something back with bit 7 clear
If <> 0 then error.
3 Send start token
4 Send 512 bytes
5 Send 2 check sum bytes
6 Wait for NOT busy
send 255 till 0 is not received
Ok, but i don't understand why do you have to multiply by 512 (LBA * 512), what happens if i send a LBA number directly?, the address would be correct.
Thanks, finally i have written various sectors with LBA*512 formula, i don't understand why it is like that, in a CF card you write the LBA number directly.
Ok, but i don't understand why do you have to multiply by 512 (LBA * 512), what happens if i send a LBA number directly?, the address would be correct.
Because you are addressing data.
You could ask for, or write to sector X.5 to X+1.5. The addressed data does not have to be at a LBA boundary.
If you ask for a an LBA, but the card expects a memory address, you will be out by a factor of 512.
Phil