Electrical – SD card single write block

microcontrollersdcard

I'm presently writing the code for SAMD20 micro-controller and SDCard. I'v successfully written code for single block read and multi block successfully. I'm testing my code with San-disk 16 GB SDCard with HC-1 specs.

I'm stuck with writing the code for single block write.

I've followed following process:

Sent CMD24 command (with sector number 2001:just after first block of FAT32 FS )
Based on response started writing buffer with incremental data (0x00,0x01,0x02,0x03……..) (After Sending data token 0xfe)
Now after this, I'm waiting for data response (i.e. 0x05 for successful data write), which i didn't get. MISO line goes BUSY (0x00) after that and after some time, transit to high (0xff).

If I send CMD13 (arg=0x00) after this, I should get card status, but It is returning back with 0xC1 0x3F.

After reset, if I tried to read sector no. 2001. I get following results

WinHex screenshot

I think this is the correct procedure for SD Card write.

Any help will be appreciated.Thanks in advance.

Best Answer

As far as I'm aware, the correct procedure for a single-block write operation is:

Send CMD24
Wait for the 0x00 acknowledgement
Send 0xFE
Send entire block (512 bytes for modern cards)
Send 2-bytes of anything (or 2-byte CRC, if enabled)
Wait for xxx0yyy1 data response token
Check that yyy = 010

I have a suspicion that you're not waiting for the CMD24 acknowledgement before sending the data. That's what I did at first, too.

By the way, that output of sector 2001 looks suspiciously like a FAT FS Information Sector (which always starts with RRaA), which usually is located at block 1 of the partition. Does your partition start at sector 2000?