Pages: [1]   Go Down
Author Topic: Accessing SD card at higher speeds.  (Read 1565 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 5
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So far the highest SCK speed I can use and still ensure reliable data transfer (specifically reading) is 4MHz. At 8Mhz I get about 99% of the data read correctly off the SD card, but every now and then (always in the same place in the file I'm reading) I get a kilobyte or so of 0xFF instead of the actual data. At 16MHz the SD card won't even initialize. So my question is, is there anything I can do to increase the reliability of my connection so that I can get 100% integrity at 8Mhz? I'm running at 3.3v and the SD card is connected to the SPI pins through 2K resistors for current limiting (except for MISO). I'm also using a very basic custom SD library so that I can read as fast as possible. My guess is that the SD card is busy at the times when it gives me 0xFF so checking if it's busy before reading might solve the problem but there doesn't seem to be a busy bit in any of the SPI registers. I already check if bit 7 of the status register is high before proceeding to read anymore data. It might just be that the data is lost somewhere between the SD card and the MCU though. However, the fact that I get bad data in the same place every time really befuddles me.
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 53
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

>the SD card is connected to the SPI pins through 2K resistors for current limiting
The serial resistors in the SPI limit the maximum speed (create RC low-pass filter in the signal path).
So from HW point of view this might be the issue..
p.
« Last Edit: August 08, 2012, 03:28:30 am by pito » Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ha, something inside of me was saying that 2K was too big as well. I'll desolder them and put in some 220 ohm ones tomorrow. But shouldn't they only affect writing? Like I said, there's no resistor on MISO.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just using a seriese resistor is not sufficient for dropping down to 3.3V. You need a potential divider or better a proper level shifter. Just using one resistor will destroy your card.
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As I mentioned in the original post, I'm running the MCU at 3.3v
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 53
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

>I'll desolder them and put in some 220 ohm ones tomorrow. But shouldn't they only affect writing? Like I said, there's no resistor on MISO.

The 220ohm is better than 2k, you may try with it. See the pictures below on the 2k and 220ohm difference. The best solution is none resistors, however..


* res in spi.jpg (62.08 KB, 879x589 - viewed 27 times.)

* res in spi 220.jpg (56.89 KB, 881x588 - viewed 25 times.)
« Last Edit: August 08, 2012, 04:29:08 am by pito » Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wasn't sure what the input impedance of the SD card was, hence the resistors. I'll just omit them completely then.
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I took out the resistors. Made no difference.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What sort of arduino are you using?
It could be that your SD card can't go faster. Have you tried another one?
What class of SD card do you have?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have used many SD card but most of them are not at higher speed.The SD Memory Card includes key enhancements over existing Flash cards. These include cryptographic security, protection of copyrighted data, high-data transfer rate for fast copy/download and high storage capacity in sandisk SD card.
Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

>What sort of arduino are you using?
I'm not actually using an arduino. I'm using an ATxmega256D3 on a custom board.

>It could be that your SD card can't go faster. Have you tried another one?
I've tried a 16MB card but it didn't work at any speed (I think it's getting FAT12 formatted instead of FAT16). I also tried a 128MB miscroSD card in an adapter, but it didn't work at any speeds either. My current working card is 512MB if it makes a difference.

>What class of SD card do you have?
If by class you mean speed class then all I know is that there are no high speed marking on it (like these: https://www.sdcard.org/developers/overview/speed_class/host-marks.png). If by class you mean SD vs SDHC vs SDXC, its just plain old SD. The only useful info on the card is SD-M512 which led me to this "datasheet", http://datasheet.octopart.com/SDM512-Toshiba-datasheet-10124.pdf

If the card couldn't go faster then I assume it wouldn't even initialize at 8MHz (like it fails to at 16MHz). The fact that I get 99% of the data back correctly leads me to believe that it's just busy or something and that I have to wait for it. Although it certainly could just be the max SPI speed of the card.

Which leads me to the question, has anyone ever attempted to use an SD card in SD mode (which I assume is faster) on an arduino? Or is it far too complicated/fast for a small MCU to keep up?

Also I just read this: "When the card encounters a data retrieval problem, it will respond with an error response (which
replaces the expected data block)
". This is likely whats happening right now. I'll read up some more on it.
Logged

0
Online Online
Edison Member
*
Karma: 44
Posts: 1484
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like you have lots of software bugs.  You need to look at the SPI mode protocol for access to the SD card.

Much of what you are seeing is due to not following the SD protocol.

For example the way an SD indicates busy for a read is to send repeated 0XFF.  It sends a start of data token when it is no longer busy.

You can't use SD mode since that requires hardware SDIO bus support and the ATxmega256D3 does not have a SDIO bus.

Logged

Pages: [1]   Go Up
Jump to: