I refer to the SD library that comes with Arduino 0022 release.
It fails to release the MISO pin to high-impedance state, preventing the SPI bus from being shared with other devices on that system.
The SD SPI interface is such that a minimum of 8 clock pulses need to be sent on SCK after releasing the CS pin to logic high. Otherwise the card continues to drive the MISO pin indefinitely. The SD library makes no attempt to do this.
To recreate the problem set up a SD card and wire two 100k resistors between MISO and GND and between MISO and 3V3. Add scope probe on MISO and observe that it starts off at 1.6V at reset, but after the SD library has been begun it stays at 0V or 3V3 forever after.
My fix was to call spiSend() at the end of chipSelectHigh(), and replace the call to chipSelectHigh() in the SPI-setup code to a direct digitalWrite(). chipSelectHigh() is called at the end of each SPI bus transaction and thus this guarantees the 8 SCK pulses necessary to release MISO to hi-Z state. Using the setup above you can see the MISO line reverting to 1.6V after every SPI transaction.
A less serious issue is that the SPI bus is driven at 125kHz, whereas the spec wants 400kHz clock during init. Most cards seem very tolerant but the closest match to 400kHz would be SPI at 250kHz (divide by 64)
"It fails to release the MISO pin to high-impedance state, "
Master In Slave Out is an input - so the slave does not let go of the line?
And it needs extra clock pulses after CS goes high to do so? That does not sound like proper operation from the SD card.
The SPI on MMC and SD cards is a hack, the cards native mode uses a continuous clock (at higher speeds) and the SPI clock bursts serve as clock to the whole SD card as far as I can make out from the specs (the ones I have). So the SD card can't do anything when CS is de-asserted until some clock pulses come through to allow it to function enough to change the state of its output driver. Remember an SD card is a microcontroller talking to some flash chips, microcontrollers need a clock...
SPI SCK is not the internal clock for SD cards. SD cards are active without SPI clock. The data out line is only driven in some cases after CS is set high and only with some cards. I missed at least one case in SdFat so I now send a byte on the SPI bus after setting CS high. This always works to release data out with old and new SD cards.
Here is a quote from the SD Physical Layer spec about a write operation.
While the card is busy, resetting the CS signal will not terminate the programming process. The card will
release the DataOut line (tri-state) and continue with programming. If the card is reselected before the
programming is finished, the DataOut line will be forced back to low and all commands will be rejected.
Resetting a card (using CMD0 for SD memory card) will terminate any pending or active programming
operation. This may destroy the data formats on the card. It is in the responsibility of the host to prevent
this for occurring.
I make use of the fact that SD cards program flash without SPI clock in my fastLogger examples. See the the examples in beta-lib above.
I write data to the SD but do not wait for the SD to program the data to flash. I check for errors or busy before the next transfer. Each transfer of 512 bytes takes about 850 usec.
No, that's not what I mean, that's just saying that write and erase are asynchronous commands, I'm talking about general SPI transactions which require extra clocks. Try it with a resistive divider and an oscilloscope connected to see that MISO is not released without the extra clocking.
By the way I'm using microSD cards (ie TransFlash protocol) - perhaps I should have made that clear from the outset.
The reason an SD drives MISO is not because of clock, it's to provide some computability with MMC cards which require eight clocks to release MISO after CS is high. SD cards release MISO on the edge of the first clock after CS is high on operations that drive MISO after CS is high.
What I was saying is that SD cards have an internal clock. This is not how they work.
The SPI on MMC and SD cards is a hack, the cards native mode uses a continuous clock (at higher speeds) and the SPI clock bursts serve as clock to the whole SD card as far as I can make out from the specs (the ones I have). So the SD card can't do anything when CS is de-asserted until some clock pulses come through to allow it to function enough to change the state of its output driver. Remember an SD card is a microcontroller talking to some flash chips, microcontrollers need a clock...
A card can complete operations without external clock. I use this fact in my libraries.
Why do you think SPI was a hack? Do you mean for the MicroSD. The SPI mode is optional in the microSD format.
SPI was designed in from the beginning for SD cards. Here is a quote from the spec:
The SPI bus and one-bit SD bus are mandatory for all SD families.
Also there is no standard for a "TransFlash protocol" Here is a quote from the history:
Although Transflash was the original name for microSD, the name was changed to microSD once the standard was adpoted.
Well I just bought a microSD card that mentions TransFlash on the consumer packaging!
All these memory standards are confusing(!) glad the fix is in - and I do appreciate all the hard work, especially as having written a partial SD driver myself
I agree, finding reliable information about microSDs is very difficult. There is a lot of incorrect stuff on the web. This is due to the microSD's history.
It was created as T-flash by Sandisk and Motorola as a propitiatory flash card for phones. Then T-Mobile sued over the name and it was changed to TransFlash just before SanDisk released it.
Other flash companies pressured SanDisk to standardize the "phone card" so SanDisk, Toshiba and Panasonic developed the "microSD standard" to be administered by the SD Card Association.
I think SanDisk and maybe others still refer to the product as TransFlash.
The good news is that the SD Card Association says this about the current microSD standard:
All microSD memory cards are backward compatible with SD standards-enabled electronic devices. By using an appropriate adapter, the microSD memory card can easily and quickly be inserted into any device that supports a full-size SD or miniSD memory card.