SD-Card Interface problems

Topics regarding the Uzebox hardware/AVCore/BaseBoard (i.e: PCB, resistors, connectors, part list, schematics, hardware issues, etc.) should go here.
User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

SD-Card Interface problems

Post by uze6666 » Thu Sep 18, 2008 3:11 pm

So I finally decided to work on the SD interface. I've actually implemented the one from that site. However, using their code it *seems* to initialize ok. But when issuing a read a sector command it freeze forever waiting for the "transfer ready" status . i.e:

Code: Select all

while(SPI(0xFF) != (char)0xFE);
Since I don't own either a logic analyzer or digital scope it really, really hard to see what's going on. I've tried lowering CPU speed to 14Mhz during init/read to be sure the ISP is not going bezerk because of overclocking. Same results. Could it be electrical problems? Some docs mentions all pins should have pull-ups. Really?

Perhaps its that guy's code? Since, I found another open source lib, and try that tonight. If anybody experienced something similar, how has suggestions, please let me know!

Cheers,

Uze

havok1919
Posts: 474
Joined: Thu Aug 28, 2008 9:44 pm
Location: Vancouver, WA
Contact:

Re: SD-Card Interface problems

Post by havok1919 » Thu Sep 18, 2008 7:28 pm

uze6666 wrote:So I finally decided to work on the SD interface. I've actually implemented the one from that site.
Huh... That code looks a little weird to me. I don't remember that leading and trailing 0xFF in the MMC 'command'. I only remember six bytes. Looks suspicious.
Could it be electrical problems? Some docs mentions all pins should have pull-ups. Really?
If you've run it with a slow clock it's probably not electrical. I think pullups get mentioned a lot because not all MCU's have them on their I/O's. Should be OK on the AVR, but I'd probably turn on the pullup for MISO if you haven't already.
Perhaps its that guy's code? Since, I found another open source lib, and try that tonight.
I've collected a few as well if you need more examples. Since the only thing I have left to test is SD/MMC, I'll try that as well using the commercial library I have. (I know it worked on an Mega128 when I tried it, so at least that's a known good datapoint to start from.)

-Clay

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: SD-Card Interface problems

Post by uze6666 » Thu Sep 18, 2008 7:41 pm

I don't remember that leading and trailing 0xFF in the MMC 'command'. I only remember six bytes.
I thought that too, but I looked at the spec, and it mentioned user code should allow for at least 8 clocks before/after commands. Anyway, I tried removing them, they SD card init failed completely! Also, I've enabled the pullup on MISO, otherwise it fails initialization after a reprogramming. I will try the other lib tonight and if it fails, I'll surely ask you for those other FOSS library.

Uze

havok1919
Posts: 474
Joined: Thu Aug 28, 2008 9:44 pm
Location: Vancouver, WA
Contact:

Re: SD-Card Interface problems

Post by havok1919 » Thu Sep 18, 2008 9:52 pm

uze6666 wrote:I thought that too, but I looked at the spec, and it mentioned user code should allow for at least 8 clocks before/after commands. Anyway, I tried removing them, they SD card init failed completely! Also, I've enabled the pullup on MISO, otherwise it fails initialization after a reprogramming. I will try the other lib tonight and if it fails, I'll surely ask you for those other FOSS library.
Interesting... I really didn't remember those leading/trailing bytes from when I last looked at SD, but it's entirely possible it was being done in a macro or something and I was only looking at the actual command packet bytes.

I'm going to wire up a little RS-232 level translator and try to get my library running on the '644...

-Clay

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: SD-Card Interface problems

Post by uze6666 » Fri Sep 19, 2008 12:38 am

Ok, got it to work finally with a change of software and...disconnecting the ISP programmer! I used a stk500 and even if I made a tri-stated buffer for the lines, something messes up signals. De-plugging it and working for the wall psu work just fine. Just that sucks, because I have to unplug/replug the programmer all the time. Any idea what to try to get around this?


Uze

havok1919
Posts: 474
Joined: Thu Aug 28, 2008 9:44 pm
Location: Vancouver, WA
Contact:

Re: SD-Card Interface problems

Post by havok1919 » Fri Sep 19, 2008 1:24 am

uze6666 wrote:Ok, got it to work finally with a change of software and...disconnecting the ISP programmer! I used a stk500 and even if I made a tri-stated buffer for the lines, something messes up signals. De-plugging it and working for the wall psu work just fine. Just that sucks, because I have to unplug/replug the programmer all the time. Any idea what to try to get around this?
So you were using the STK500 to provide power over the ISP header and it doesn't work, but powering from the wall wart does? Or did you still have to disconnect the ISP for it to work when powering from the wall?

What's your circuit look like? (Do you have a 3.3V regulator and run the '644 @ 5V? What'd you use for level translators if so?)

I just stuck a 3.3V regulator on my baseboard, so I'll try it all at 3.3V with the ISP MKII and see what happens.

-Clay

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: SD-Card Interface -- problems solved

Post by uze6666 » Fri Sep 19, 2008 2:34 am

Yeah, I use the STK500 to power and program my board. Now, I must disconnect the ISP header for the SD to work (and power it externally). I built a second story with a 3.3V regulator and SD stuff on it. Looks somewhat boxy now, can't be more appropriate for the UzeBOX! :lol:
uzebox2levels.jpg
uzebox2levels.jpg (30.28 KiB) Viewed 3084 times
I just ordered a AVRISPmkII, so I'll see tomorrow if it fixes the issue. Other than that, I just dumped my first raw sector on the screen, very cool...sky's the limit now! :D
sddump.jpg
sddump.jpg (27.45 KiB) Viewed 3057 times
Btw, I finally used this AVR SD library. It's well done, works fine and it's GPL'ed. I will have to tweak it a bit for what I intend to do, but it's great stuff nonetheless.

Cheers,

Uze

CompMan
Posts: 91
Joined: Mon Aug 25, 2008 3:48 am
Location: Kent, WA

Re: SD-Card Interface -- problems solved

Post by CompMan » Fri Sep 19, 2008 2:49 am

Looks great, I should be getting my parts in 2 or 3 weeks. After I put it together I can start on an Ethernet interface.

Compman

havok1919
Posts: 474
Joined: Thu Aug 28, 2008 9:44 pm
Location: Vancouver, WA
Contact:

Re: SD-Card Interface -- problems solved

Post by havok1919 » Fri Sep 19, 2008 3:47 am

So just as another datapoint. I got my (commercial) SD library running. I'm running the UZEBOX @ 3.3V to ease interfacing to the SD card since I didn't have the right level conversion on the SD lines on the first AVCore boards (the 1.0 Stamp).

Anyway, I'm running with the unit wall powered (and regulated to 3.3V on board) with an AVRISP MKII connected. I can leave the ISP connected and successfully program (@4MHz, which is nice) *most* of the time. It would appear that you can interrupt the SD card mid-operation and it'll wedge the SPI bus. (that makes sense-- if the SPI clock were to go away when the card was driving the bus... no worky.)

It does appear that if you leave the SD card inserted while doing an ISP program that the *card* might get in a bad mood... (You would think that since it's deselected it wouldn't care...) The demo program tries to talk to the card and then write a text file to the card with FAT16. If I leave the card plugged in and program the '644 it will sometimes fail programming-- if I do it again it always seems to work. (That's not a huge annoyance since it takes less than a second to program the part @ 4MHz.) Once programmed (with the card in the slot), no amount of resetting the AVR will get the card to init. If I pop the card out and back in-- it works every time. Similarly, if I pop the card out while programming the AVR, then pop it back in-- that works every time too.

Sooo... It seems like the card getting crabby to me. Maybe I'll try adding an external pullup on the SD card chip select-- could be that the AVR is glitching/floating that line during reset or programming and the SD card state machine starts trying to receive a byte or something...

Anyway, since I can write a file to the card using FAT16, I'm pretty sure that the interface on the AVCore is good. (That's a metric assload of stuff going on with this library doing FAT16 with no directory/sector caching, so it's beating on things pretty hard. This was running @ 14MHz too, signals look nice and clean!)

-Clay

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: SD-Card Interface -- problems solved

Post by uze6666 » Fri Sep 19, 2008 3:59 am

If I pop the card out and back in-- it works every time. Similarly, if I pop the card out while programming the AVR, then pop it back in-- that works every time too.
That's *exactly* what I am experiencing! So I guess I just blew 35$ on an AVRISP :(. I tried putting pull-up on all the SPI lines, no luck, same results. It seem's like the card would need to have have it's power cut down during programming (when reset line=zero). Perhaps that could easily be done with a transistor or something very cheap? I'll have a try. What do you think?

On the bright side, it's good to see we have no problem with overclocking. Moreover, I just popped in a 644P and the SPI works just fine at SPI2X.

Uze

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests