• AVR Freaks

SD card: cmd 17 (read single block) response always 0x01

Author
hneel
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2010/03/03 06:30:43
  • Location: The Netherlands
  • Status: offline
2018/05/29 05:43:14 (permalink)
0

SD card: cmd 17 (read single block) response always 0x01

I'm trying to connect a micro-SD card to a PIC32 controller. The PCB is own design, not some kind of standard development board. At the moment I'm bitbanging the SPI protocol to communicate with the card. (In the near future I will use the proper pins to use real SPI, but for now I have to use this solution). Long story short: I am able to initialise the card and get correct responses for all commands, but when I try to issue the cmd 17 command, it responds with 0x01 (idle) instead of 0x00 (ready) and any subsequent reads all return 0xFF. The expected token 0xFE never comes. I've tried a lot of different sectors as argument for cmd 17, but that doesn't make a difference.
 
These are the commands and responses for initialisation:
>> (0) 40 00 00 00 00 95 
<< (0) 01

>> (8) 48 00 00 01 AA 87
<< (8) 01 00 00 01 AA

>> (55) 77 00 00 00 00 65
<< (55) 01

>> (41) 69 40 00 00 00 77
<< (41) 01

>> (58) 7A 00 00 00 00 FD
<< (58) 01 40 FF 80 00

>> (16) 50 00 00 02 00 15
<< (16) 01

>> (17) 51 00 00 00 00 55
<< (17) 01

They all look good to me, except the last one. (BTW, I'm always using the correct CRC even though I'm aware that it's not neccesary). This makes me think that my setup is basically correct.
 
The card is powered with 3.3V. The voltage doesn't drop when accessing the card. All lines excepct clk have a 100k pullup resistor.
 
The (bit-banged) clock frequency is about 145 kHz. Could this have any influence on the read command? I believe it has to be below 400 kHz at initialisation. But are there any further requirements for reading/writing? I haven't found any. 
 
What could be the reason for cmd 17 not giving the correct response?
 
post edited by hneel - 2018/05/29 05:46:09
#1
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3345
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: SD card: cmd 17 (read single block) response always 0x01 2018/05/29 07:21:12 (permalink)
0
Initialize at slow speed then take up to 10MHz.
 
READ_BLOCK,   17
 
Works for me, I have separate sdcard, sector and cluster libraries.
 
Here is the sequence I use (non-dma version)
 
  1 If an HD card, the address must by left shifted by 9 (x 512)
  2 send READ_BLOCK
  3 Get R1
  4 if response is 0xff ERROR_R1_00 <-- expect 00 (ACCEPT)
  5 get R1
  6 if response is 0xff ERROR_R1_FE <-- expect FE (TOKEN_START)
  7 ::loop 512::
  8 setm SPIxBUF
  9 while not SPIxSTAT bit SPIRBF    <-- wait
10 [buffer++] = SPIxBUF
11 next loop
12 ERROR_OK
 
 
post edited by Gort2015 - 2018/05/29 07:34:45

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#2
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3345
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: SD card: cmd 17 (read single block) response always 0x01 2018/05/29 07:33:36 (permalink)
0
You never said if it was an HD card or SD card.
 
Using magic numbers is not helpful on forums. i.e. (16)
you should write SET_BLOCKLEN

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#3
hneel
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2010/03/03 06:30:43
  • Location: The Netherlands
  • Status: offline
Re: SD card: cmd 17 (read single block) response always 0x01 2018/05/30 02:32:41 (permalink)
0
Thanks for your replies. 
The problem had been solved. It was not in the actual read command but in the initialisation. The response on ACMD 41 (SD_APP_OP_COND) should be 'ready' instead of 'idle'. I had to retry this command in the initialisation routine until the desired result was recieved. Then all subsequent responses will also return 'ready' instead of 'idle'. And CMD17 (READ_SINGLE_BLOCK) will in that case return the token 0xFE and the sector contents. 
 
I guess I was confused bu the SD card nomencaltura. To me 'ready' and 'idle' mean more or less the same.
 
Also thanks for your hint about the address!
 
post edited by hneel - 2018/05/30 02:36:25
#4
Jump to:
© 2019 APG vNext Commercial Version 4.5