EmbeddedRelated.com
Forums

MMC card using SPI on BX-24

Started by arhodes19044 November 5, 2005
Well, I am answering myself here. I had a ton of help from various
sources, but most of it did not work.

I finally figured it out. I was actually afraid of this type of
problem.... The bit-banged SPI routines were not perfect, at least
not for SD/MMC cards.

The datasheets show graphically the bus timing. It states that the
host-to-card data is clocked-out on the rising edge of the clock,
and the Card-to-host data is clocked-in on the falling clock edge.

Well, that is true..... but I would have phrased it in the reverse
order.

The card-to-host data is READY to go before you raise and drop the
clock. If you try to read while the clock is high, then the data is
undefined. If you read after you drop the clock, then it is the
NEXT bit.

You have to
1) Set the MOSI pin to whatever data bit you want to send to
the card.
2) read the MISO bit
3) raise the clock pin
4) drop the clock pin
5) repeat 7 more times to make a byte.

The MMC clock should be low at idle.

At this speed a voltage divider works fine for the 5v to 3v
interface for the MOSI, CLOCK, and the Card Select pins. I used
2200 and 3300 ohm resistors. I had been using 4700 and 10,000 ohm
resistors, but went with lower values while troubleshooting.
Probably the 4700/10,000 would work fine too.

The MISO wire goes straight from the card to the BX. 3.3v is high
enough for the BX to read it as "high".

This is really all that needs to be done.

Bit-Banging is really slow! 1500, yes, fifteen hundred bits per
second. If it were possible to use the Hardware SPI, then it would
be considerably faster. Hardware I2C is darned fast too. I think
the BX H/W I2C will support speeds of 400,000 bits per second. THis
is not as good as RAW SPI speed, but on a BX, you will not get that
sort of speed because of the EEPROM overhead.

So, I think I would go with I2C FRAM for non-volatile storage unless
you need mass quantities, with relatively low speeds. MMC is fine
for large, slow data access. Problem: Data writes are 512 bytes.
This can be solved with a little care.

-Tony