Forum Index
SD/MMC interface API

 
Author Message
spamiam



Joined: 13 Nov 2005

Posted: 13 November 2005, 14:54 PM    Post subject: SD/MMC interface API

Here is something I just wrote. It shows how to interface to SD/MMC cards. Not all commands are supported. Since the exact method of reading/writing the data may be quite application-specific, these modules are not "complete". The data is only printed by debug.print functions. You will need to add your own specific handling of the data.

-Tony



MMC_API.bas
 Description:
This shows how to interface to SD/MMC cards. Not all commands are supported. Since the exact method of reading/writing the data may be quite application-specific, these modules are not "complete". The data is only printed by debug.print funct

Download
 Filename:  MMC_API.bas
 Filesize:  14.24 KB
 Downloaded:  2468 Time(s)

Back to top
sonny



Joined: 24 Nov 2005

Posted: 24 November 2005, 6:46 AM    Post subject:

Tony,

Did you wire the MMC to the ZX-24 directly, is the output of ZX-24 5.0v compatible with MMC 3.3v ?

Sonny
Back to top
spamiam



Joined: 13 Nov 2005

Posted: 27 November 2005, 14:53 PM    Post subject:

Sonny,

No, I did not interface the SD/MMC directly to 5V. I used a 3.3 volt regulator off the 5 volt supply. since the current draw is tiny, the smallest regulator you can find is probablyh going to be fine.

As for the other pins, I used a simple voltaqe divider.

Source--2.2K---3.3K----Ground

I am told that this technique will not work well at high data rates, but as far as I can tell, it works well enough for the ZX.

You could use a "level shifter" IC to be fancy, and it might work better, but this has been OK for me so far. I just wrote and read data, but did nothing useful so far.

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 27 November 2005, 17:49 PM    Post subject:

spamiam wrote:
You could use a "level shifter" IC to be fancy, and it might work better, ...


Some 3.3V devices have "5 volt tolerant" inputs meaning that you can directly connect signals with a 5-volt swing. If the inputs are not 5 volt tolerant, the voltage divider technique will usually work well.

The more likely problem is that the 3.3V signals coming out of the device may not be sufficient to drive a 5 volt device's inputs. A simple way of fixing this is to use an open drain buffer running on 3.3 volts with a pullup to 5 volts on the output side. The ideal device for this purpose is the 74HC07 or 74HC17 but they are hard to find. The alternative is to use a series of two inverters (74HC05 or 74HC06). If you have the gates available, the first in the series could be a 74HC04; only the final output needs to be open drain so that it can be pulled up to 5 volts.

Atmel has an Application Note that discusses the issues of mixed-voltage systems.
Back to top
spamiam



Joined: 13 Nov 2005

Posted: 28 November 2005, 0:11 AM    Post subject:

dkinzer wrote:
Some 3.3V devices have "5 volt tolerant" inputs meaning that you can directly connect signals with a 5-volt swing. If the inputs are not 5 volt tolerant, the voltage divider technique will usually work well.

The more likely problem is that the 3.3V signals coming out of the device may not be sufficient to drive a 5 volt device's inputs.
Atmel has an Application Note that discusses the issues of mixed-voltage systems.


Right. You have to check the datasheets carefully regarding the "5v tolerance of the inputs, and of the input current so that you do not exceed the current tolerance when driving the input with 150% of the expected voltage. Otherwise identical devices (e.g. SD cards) might NOT have the same input tolerances.

BTW, I am using an LDO 3.3 volt regulator to supply the SD card, and I am getting good "high" bits being read by the ZX-24. But a level shifter IC with an LDO 3.3v regulator would remove ALL the worries about voltages and bandwidth. THe level shifters come in various versions with so many low-to-high and high-to-low shifters. There was one I found (was it a Maxim?) that had just the right number and direction of shifters.

Do check the Atmel ref. They suggested a "voltage regulator" option that I had not thought of. Since you probably have a reasonably well regulated 5 volt source. You can supply the SD/MMC card with about 3 volts by using 3 diodes in a row between the 5 volt source and the VCC of the SD/MMC. The average diode will drop about 0.7 volts, and with 3 in a row, you will drop 2.1 volts leaving 2.9 volts as the supply voltage to the card. Again, you need to check the datasheets to see what the Vf is, and really look at it for a a 5-20 MA which is probably about what the card draws. The Vf is not 0.7 over the entire current range usually. Schottky diodes have a smaller Vf, so you can adjust the "regulated" voltage by the selection of the type and number of diodes. You probably want to run the card near its maximum voltage if you are not using a level shifter to get the "high" bit as high as possible to minimize the chance of misreadings by the ZX. Usually 3.5 or 3.6 volts is the high limit. 3.6 volts would be obtained by two "standard" diodes. Remember that there is no such thing as "standard" and you need to check datasheets carefully when you are at the MAXIMUM limit of the card.

-Tony

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 28 November 2005, 1:59 AM    Post subject:

spamiam wrote:
You can supply the SD/MMC card with about 3 volts by using 3 diodes in a row between the 5 volt source and the VCC of the SD/MMC. The average diode will drop about 0.7 volts, and with 3 in a row, you will drop 2.1 volts leaving 2.9 volts as the supply voltage to the card.


The minimum specified voltage for a logic 1 input to a mega32 device is 0.6 times Vcc. Running a ZX-24 on 5 volts means that you have to get to 3.0 volts to guarantee that a logic 1 is recognized. This is nigh well impossible if you're running the SD/MMC on 2.9 volts.

That's not to say that it won't work. A particular ZX-24 may well recognize 2.5 volts as a logic 1 but you wouldn't want to design a system for production that didn't meet the device specifications.
Back to top
spamiam



Joined: 13 Nov 2005

Posted: 28 November 2005, 13:40 PM    Post subject:

dkinzer wrote:
The minimum specified voltage for a logic 1 input to a mega32 device is 0.6 times Vcc. Running a ZX-24 on 5 volts means that you have to get to 3.0 volts to guarantee that a logic 1 is recognized. This is nigh well impossible if you're running the SD/MMC on 2.9 volts.


I did not know the low end of the "high" bit voltage. I have a 3.3v regulator running my SD/MMC test-bed and I am getting accurate data as far as I can tell.

I think my SD card will allow 3.5 volts. But since what I have is working, I am not going to mess with it.

The bottom line is that there are a couple of possibilities for getting a decent interfae, but the most sophisticated is probably the most reliable (level shifter, and a real 3.3v regulator)

-Tony
Back to top
spamiam



Joined: 13 Nov 2005

Posted: 10 January 2006, 14:16 PM    Post subject:

A recent thread elsewhere here made me do some thinking about the difficulty and overhead of dealing with the 512 byte sectors.

If you need to maximize your filling of the SD/MMC card, then you need to buffer your 512 byte sector, and write or read in a full 512 byte chunk.

However, many of us need a bunch of data storage, but not necessarily that much. Also, much of the storage may be in some multi-byte related data which could be considered a "structure".

So, you could use one sector for each element in your data structure, up to 512 bytes in size.

My antique 8meg SD card would have room for about 16,000 data elements (at the worst 16,000 bytes). A more modern 64meg card (which are still fairly cheap) could store about 130,000 bytes in the worst case.

So, all you need to buffer is the LARGEST element, not necessarily the full 512 bytes. In principle, even if you have data elements larger than 512 bytes, you would not need to buffer more than 512 bytes.

-Tony
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008, 2009, 2010 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group