1

I have a Buffalo SDHC SD card with 4GB of storage, and a Raspberry Pi Pico. I have connected the SD card to the Pico's relevant SPI pins and have set the SPI clock speed to 1MHz.

I have reset the SD card with command 0, and have received a successful R1 response of 1 (to clarify, that is all I have done).

Now, I want to read a single block (512 bytes), and after researching, the command code is 17 and the arguments is the block index I want to read (in my case, 0 - 0-511 bytes). I have sent the command, and have received an R1 response of 1 (meaning card is in idle mode), however after some research, I was supposed to also receive a "token" containing 0xFE indicating a successful read followed by the bytes in the sector, or an error code.

However, the only things I am receiving after the initial R1 response are 0xFF bytes which would indicate the SD card is idle. I have tried reading several thousand bytes from the SD card, perhaps thinking the read is taking a while, but nothing, I am only receiving 0xFF bytes with the token nowhere to be found.

Does anyone have any advice on why this could be the case? I have looked over my command syntax and have found it to be correct:

(bits + cmd code) 01010001 (32-bit arguments) 00000000 00000000 00000000 00000000 (CRC value set to 0 due to checking disabled + end bit) 00000001

I have also tried experimenting with a different argument and different clock speeds but to no avail.

Epic Speedy
  • 636
  • 1
  • 11
  • 25
  • It is unclear what reference you are attempting to follow (fatfs?), but the [raspberrypi/pico-extras](https://github.com/raspberrypi/pico-extras) repository has a prototype sd card implementation that may help. I haven't waded into it yet, still fighting DHCP and the lwip library for pico w. I'd take a look at the pico-extras prototype under `src/rp2_common/pico_sd_card` and `test/sd_test` to see if that doesn't point you in the right direction. – David C. Rankin Dec 29 '22 at 02:36
  • @DavidC.Rankin Thank you for the pointer! Although, the prototype there is very odd to say the least - I don't think it even uses the SPI interface, or is using a very low level implementation of it, and is overall a mess that is very hard to understand (though it has been said SD cards are a mess overall to work with). I can try tinkering more to find a fault or reason why the SD card is behaving weirdly but this takes and there's little documentation online, let alone documentation which highlights any problems that can be encountered. As for my aim, I just want to simply read/write blocks. – Epic Speedy Dec 29 '22 at 12:59
  • There is good information on the SD/MMC interface on [How to Use MMC/SDC - elm-chan.org](http://elm-chan.org/docs/mmc/mmc_e.html). It also has a full implementation of fatfs. I understand you simply want to read/write 512 byte blocks. You may find the bare interface sufficient to get that going. I've worked with fatfs before and there is a lot that is barely documented, hard to find, and varies by the SD chipset you have. All and all, it takes dedication. You sound like you are well on your way. – David C. Rankin Dec 30 '22 at 03:28
  • @DavidC.Rankin Thank you for that link! Reading about the initialisation process, it seems after sending command 0 (GO_IDLE_STATE), a command 1 (SEND_OP_COND) is required to initialise the card, otherwise "in idle state, the card accepts only CMD0, CMD1, CMD8, ACMD41, CMD58 and CMD59. Any other commands will be rejected.". I have in fact not sent a command 1, only a command 0, perhaps this could be the cause? I'll have a play around with it to see if that's going to fix it. – Epic Speedy Dec 30 '22 at 17:40
  • 1
    @DavidC.Rankin I finally managed to do it! It turns out I had to read command 8 first, then send an ACMD41 to initialize the card, then the card accepted my reads and I was able to write some data to the first block then read it. The link you sent was the pointer I needed. – Epic Speedy Dec 31 '22 at 13:21
  • Good Job getting it working! I recall reading through the initialization a couple of years back. It's not for the faint hearted. If you have a presentable working solution, you are welcome to provide your own answer. I'll be happy to vote for a well formatted solution. Good luck with your coding. – David C. Rankin Jan 01 '23 at 06:09

0 Answers0