Multiple Block Write SD protocol issue


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009
    Location
    South Wales (UK)
    Posts
    62

    Default Multiple Block Write SD protocol issue

    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:

    Code:
    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"):

    Code:
    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

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,040


    Did you find this post helpful? Yes | No

    Default Re: Multiple Block Write SD protocol issue

    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


    Code:
    ' 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
    Last edited by Demon; - 16th April 2016 at 16:11.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Easy way to do multiple write statements ?
    By Scampy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th March 2016, 09:05
  2. Lcdout multiple variables issue
    By MarkEngineer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd February 2015, 15:51
  3. DT Multiple Software PWM and 18F2321 issue
    By microuser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th December 2012, 09:23
  4. SD Multiple Write?
    By jimbostlawrence in forum General
    Replies: 1
    Last Post: - 21st October 2011, 18:45
  5. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 09:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts