PDA

View Full Version : Multiple Block Write SD protocol issue



jimbostlawrence
- 14th February 2016, 19:58
Hi all,

I've been working with SD cards for a couple of years now, but only using Single Block Write. I'm trying to get Multiple Block Write to work but it fails after writing the first set.

Posting code will be difficult as it's a complicated program and would be easier if I started again, just to put something up to post.

What I've been trying so far is to use CMD25 and sending four blocks of data (4x 512 bytes) and then, once they've gone through, sending a single byte $fd using:



SDC_data_in = SSPBUF
SSPIF = 0
SSPBUF = $FD
While !SSPIF
Wend


and then raising the CS line to, in theory, finish that set of block writes.

Then, when I wish to write another set of 4 blocks (at the next available address), I do the same as above, but, after the first 512 bytes go through, I get a data not accepted error ("Unknown fail"):



for cnt = 0 to 511
SDC_data_out = SDC_buffer[SDC_buffer_current_mul+cnt]
gosub write_byte
next cnt

SDC_data_out = $ff
gosub write_byte ' send 16 1s as a dummy CRC
gosub write_byte

SDC_data_in = SSPBUF ' clear the buffer
SSPIF = 0 ' clear the interrupt flag
SSPBUF = $ff ' shift out a dummy byte
While !SSPIF ' wait for receive byte
Wend

SDC_data_in = SSPBUF ' get the byte
If ((SDC_data_in & $0f) != DATA_ACCEPTED) Then
SEROUT2 Serial_out,6,[$d,$a,"Unknown fail"]
high red_led
gosub stop_read
endif


Does anyone have any code that successfully sets up a multiple block write to an SD card, terminates using the multiple stop token, and then successfully repeats this on the same card? I've been trying to do this for 3 days now with no success.

I also tried CMD12 but I got an Illegal Command error in the R1 response.

I have checked using a hex editor (changing the data it's writing each time to make sure it 'is' doing its job) that the 4 blocks are being written in the first multiple block write instance...

Best,

Jimbo

Demon
- 16th April 2016, 14:58
Sorry for late reply, been away mostly, and have no knowledge about SD cards. But after doing some research for another thread, have you tried MeLabs SD Card SAMPLE program sdfs3.pbp?
http://melabs.com/samples/PBP-mixed/sdfs3.htm



' Write to file
FAT_src[0] = "A" <<-------- Just load up your array as you see fit from element 0
FAT_src[1] = "B"
FAT_src[2] = "C"
FAT_count = 3 <<-------- set to 512
Gosub FSfwrite
Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
If (FAT_error != 0) Then Stop

This sample program does it all for you. Just note it's using PBPL and PIC 18 (but you probably already know this).

If you absolutely have to use your own code (for whatever reason), SDFS.PBP might provide insight at what is the correct procedure.

Or am I missing something obvious?

Robert