| Author |
Message |
JC
Joined: 20 Feb 2006
Location: Hudson,OH
|
|
Posted: 25 May 2006, 15:05 PM Post subject: MMC Card Variability |
|
|
I am interested in storing data on an MMC card. I have 64MB, 128Mb, & 256MC cards to play with.
I have bit-banged the SPI interface to learn how to do it, to avoid any internal ZX interrupt issues which could interfere with the software serial comm ports, and to avoid any data block length / Chip Select issues.
I can Init and Block Read / Write to the 64MB & 256MB cards.
I can not get the 128MB card to Init into SPI mode. I send synch pulses, then Cmnd0, the expect the R1 response. I never get the R1 response from this card. The others generate it 8 clock pulses after the Cmnd0.
The card works fine in a multi-card USB reader on a PC. I can format, and R/W to the card(s).
It happens to be a different brand of card than the two that I have working with the ZX-24, (Label is KingMax R).
On the PC the card is obviously in MMC Mode, FAT partition, etc. The PC does not test the SPI capability of the card...
I wondered if others have had any similar experiences, where particular cards seem problematic?
Since the other 2 cards work I believe the core of my code is functional. Tweaking some timing and padding made no difference.
Card is running a 3.3 V, with Oscoped level shifters.
Any thoughts?
JC
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 25 May 2006, 16:14 PM Post subject: |
|
|
| Quote: | | I have bit-banged the SPI interface to learn how to do it, to avoid any internal ZX interrupt issues which could interfere with the software serial comm ports, and to avoid any data block length / Chip Select issues. |
I believe that SPICmd() could be used without any of the effects that you're trying to avoid. Firstly, the SPI data is transferred with interrupts enabled. Consequently, long transfers may be realized without interfering with Com3-6, the RTC, etc. Secondly, beginning with v1.2.0 of the VM the transfer byte count values for SPICmd() can be 16-bit values. This eliminates the block length/chip select issue discussed here in the past.
It is possible that the one misbehaving card is more sensitive to timing than the other two. You might try interacting with it using SPICmd() and see if it works properly.
|
|
| Back to top |
|
 |
spamiam
Joined: 13 Nov 2005
|
|
Posted: 25 May 2006, 17:23 PM Post subject: |
|
|
| Quote: | | Secondly, beginning with v1.2.0 of the VM the transfer byte count values for SPICmd() can be 16-bit values. This eliminates the block length/chip select issue discussed here in the past. |
Oh, that is great. I had not noticed this change, or at least not realized its significance.
So, this means that it is no longer necessary to use a bit-banged SPI interface to write all 512 byte MMC cards? I now forget if there were other concurrency problems in addition.... That would make things immensely easier.
I had planned on getting back to my SD/MMC card interface soon. I wanted to expand on my interface functions for the FILES section. It appears that I will be able to dump the bit-banged interface in preference for a nice hardware-based interface. This will make things much easier.
I must say, it appears that the O.P. probably has gone beyond my original work which was just a barebones feasibility/testing project. Maybe he can post his code and schematic of the hardware interface. He mentioned a level shifter. This is more sophisticated than the voltage dividers I used for the signals from the ZX to the MMC. I did work out a schematic for such a technique, but I did not go so far as to assemble it yet. The divider seemed to be working fine at the very low bandwidth I was getting with the bit-banged interface. Maybe using the built-in SPI hardware will achieve enough bandwidth to have the simple dividers have issues.
I have even more reason to get back to this project!
Now we just need some software that will interface with the MMC FAT without having to use a separate SD/MMC interface card! I bet this is not feasible. But it certainly IS feasible to interface directly to the raw MMC card.
-Tony
|
|
| Back to top |
|
 |
zbasicandy
Joined: 26 Jan 2006
|
|
Posted: 25 May 2006, 18:25 PM Post subject: SD?MMC |
|
|
| Quote: | | I had planned on getting back to my SD/MMC card interface soon |
If you can use ZBasic's "new 16 bit" SPI commands and a cheap breakout SD/MMC (like sparkfun electronics $14.95 interface)
and do reads/writes using ZBasic's ZX-xx microcontroller(s)
this would be great. Also throw in the FAT routines.
The question will be "is this interface scheme fast? and "does it hog
all the ZBasic ZX-xx microcontroller resources?"
Will this SPI interface be cost effective ... cheap?
|
|
| Back to top |
|
 |
JC
Joined: 20 Feb 2006
Location: Hudson,OH
|
|
Posted: 25 May 2006, 23:29 PM Post subject: |
|
|
I saw that the SPICmd byte count had increased. That is truely a good thing. I may play with the internal commands instead of the bit-bang to see if it makes a difference, but I suspect it is a card issue. Further web searching found lots of post for the same make card not working with certain MP3 equipped cell phones... Sounds like the SPI does not work on that version MMC card.
I used the Spark Fun breakout board and MMC card holder for my testing. I used a resistive divider to bring 5V signals down to 3.3V. I used 2 transistors to bump up the 3 v to 5 volt signal. Bit-Bang is slow, but I would not expect either level translator to be bandwidth limited for the 0-20MHz signal range.
One of the reasons I wrote the bit-bang, besides wanting to learn how it works, was that I believe, (ie yet to be tested), that as long as Chip Select stays low the clock frequency can go to 0. What this means is that for data logging, I can write data packets as needed, and not use a 512 byte tmp array, or an extra eeprom for tmp data storage.
One application I have in mind requires 30 byte data packets, one packet every second. I can write 17 packets, then close out the 512 byte MMC sector with 2 junk bytes, and start the next sector. If needed one could use the two "spare" bytes per 512 sector, but with MMC card size it is not an issue for me.
I'll see how it goes.
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 26 May 2006, 0:21 AM Post subject: |
|
|
"I believe [...] that as long as Chip Select stays low the clock frequency can go to 0."
If this idea pans out, I suspect that you can still implement it using the hardware SPI channel. I haven't worked out the details but I believe that you could use a 74HCT125 and a 74AHC157 to peform both the level shifting and the SPI suspend function while an additional ZX output keeps the chip select low. I can draw up a proposed circuit if you're interested.
|
|
| Back to top |
|
 |
JC
Joined: 20 Feb 2006
Location: Hudson,OH
|
|
Posted: 26 May 2006, 4:17 AM Post subject: |
|
|
Sure, I'd love to see the circuit. But I have not yet confirmed the premise that the Clock can go to 0 Hz. I leave for a string of night shifts and won't be home to work on this further until middle of next week...
I have not previously uploaded schematics, or code, but will do so for anyone interested.
Don't laugh too much at the code. The goal is a working system, after that everything else is performance enhancement. The big step was the first one, just making it work. Also, note that my original goal, beside learning the MMC and SPI protocol, was to NOT use the internal routines, or anything which uses Timer1, or could interfere with the software USARTs.
I have left my personal MMC & SPI learning curve Notes included within the code.
JC
|
|
| Back to top |
|
 |
JC
Joined: 20 Feb 2006
Location: Hudson,OH
|
|
Posted: 26 May 2006, 4:25 AM Post subject: ZX-24 MMC Card Interface |
|
|
ZX-24 to MMC Memory Card Schematic is attached as a JPG image.
ZX-24 5 V to MMC 3 V Signal Level Converter is a resistor divider.
3V to 5V converter uses two, 2N3904 transistors to bump the signal up to 5 V. Each stage inverts the signal.
Do NOT forget the pull up resistor on the MMC Data Output pin.
It is 10K, (Value not shown in the uploaded image.)
JC
[Edit: reduced image size. Full-size image.]
| Description: |
| ZX-24 to MMC Memory Card Interface Schematic JPG image <<JC>> |
|
 Download |
| Filename: |
ZX24 MMC Memory SubSystem V1 b.jpg |
| Filesize: |
297.12 KB |
| Downloaded: |
1158 Time(s) |
Last edited by JC on 26 May 2006, 4:48 AM; edited 1 time in total |
|
| Back to top |
|
 |
JC
Joined: 20 Feb 2006
Location: Hudson,OH
|
|
Posted: 26 May 2006, 4:44 AM Post subject: ZX-24 to MMC Memory Card Bit-Banged Program |
|
|
ZX-24 to MMC Memory Card Bit-Banged Program.
Program works, but isn't pretty!
Includes my MMC & SPI learning curve notes for those wishing to develop this further.
JC
| Description: |
ZX-24 to MMC Bit Banged Program. Works, but not refined! <<JC>> |
|
 Download |
| Filename: |
ZX24MMCV2.bas |
| Filesize: |
23.88 KB |
| Downloaded: |
1054 Time(s) |
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 26 May 2006, 16:30 PM Post subject: |
|
|
Here is my proposed schematic for allowing the MMC card to be continuously selected and to provide 3.3/5 volt level conversion at the same time. The 74HCT125 could be replaced with the single transistor level converter shown in app note AN-213 or any other suitable conversion circuit.
The SS/ output from the ZX is the pin that will be specified in the call to OpenSPI(). The SEL/ output from the ZX is an additional I/O pin that will be separately controlled by the program.
The multiplexor serves to control the presentation of the clock signal to the MMC card. When the SS/ line is low, the SCK signal will be routed to the MMC card. When the SS/ line is high, the clock signal to the MMC card will be continuously low. It is not really necessary to run the MOSI signal through the multiplexor but since it needs level conversion anyway, it is convenient to do so.
The sequence that I propose to use with this circuit is as follows:
1) set the SEL/ signal low.
2) perform one or more SPICmd() calls to send/receive data to/from the MMC.
3) set the SEL/ signal high.
I believe that this will work with no spurious transitions on the CLK signal because the ZX VM asserts and deasserts the SS/ output when the SCK signal is idle.
Note that this circuit assumes that the MMC uses SPI mode 0 but it could be modified to work with the other modes.
| Description: |
|
 Download |
| Filename: |
mmc_ifc.jpg |
| Filesize: |
28.72 KB |
| Downloaded: |
1114 Time(s) |
|
|
| Back to top |
|
 |
|