Working on my 6502 computer I have gathered a significant amount of wisdom around working with SD Cards and FAT32.
An SD Card in SPI mode
When an SD Card is powered up it is in SD Mode.
Most documentation says to wait for 1 millisecond after power up before doing anything.
To get to SPI mode we set the CS line high and cycle the clock 80 times. Rememner that CS is active low and so we are unselecting the card and then clocking 80 times. Depending on your SPI code you can acheve this by sending a 0 byte 10 times.
Sending a command
A command is a total of 6 bytes or 48 bits (0 to 47)
When sending via SPI we send bit 47 first and then run along to bit 0.
Receiving Response Code
Depending on the command sent you will eoither get a R1 or an R7 response code. Remeber in the physical wiring we have a pull up resistor in the MISO line, this means that if the SD Card is not sending data then we can expect to receive an $FF on the SPI bus.
So the code to receive the R1 or R7 code needs to loop untill it gets something other then $FF.
An R1 response code is one byte, and a R7 response code is 5 bytes.
In part 3 we will read a sector.