Quick SD Question

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey all,

I'm just curious, is it typical to get sporadic (albeit rare) SD card write errors when executing over SPI at 16 MHz.

Here is the set up:

AVRXMEGA256A3B controller,
SDHC Class 4 card (8 GB)
Operating over SPIC (if it's relevant)
No File-System, writing raw to card.

Essentially I am doing some testing right now to determine actual data-transfer rates we can achieve and
am simply writing continuous sectors to the SD card. I am not using multi-block writes, just the CMD24 write-block and updating the info on sector address/error counts every 800 or so writes (just some division of the storage amount.)

Basically what seems to be happening is very rarely the card will either time-out or return some error code. When this happens I simply give the card a minor delay and send the command again. Typically it appears that I will have to send the command twice after the initial failure to get it to succeed (not sure if this is systematically relevant). Letting this run for quite some time I find that we are getting approximately a 0.04% error rate (very minor, but still there).

I was wondering if this is typical? Is it possibly due to signal integrity on the SPI module when operating at 16 MHz or perhaps something with the cards?

I am waiting for the card to not be busy before each write command.

Any info will be much appreciated,

- Josh

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At that sort of failure rate, consider the possibility of atomic access problems. The scenario is that the code is doing something that requires atomic access of a 16-bit, or more, variable, but an interrupt hits in the middle. This seems to be most critical for time dependent access control but I can imagine a few other possibilities.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Card should work fine at that speed, maybe you should check you have correct SPI mode and of course monitoring signals with logic analyser to see the timings would show something, as well as monitoring with oscilloscope to see ringing or noise etc.

Try different brand/make/model/size cards too.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the replies,

Jim, I'm not sure if interrupts would be causing this as the code used for testing is purely sequential. The write commands are executed iteratively and the SPI is polled, not interrupt driven. But honestly I don't know enough about the XMEGA platform to know if there are internal interrupts occurring for the MCU (not the user implemented ones) that would be causing an issue like this.

Unfortunately I do not have a logic analyzer at the lab that I am working at... However I might be able to rig something using multiple probes on the O-scope together. What do you mean by "ringing" on the signal? I can tell that the 16 MHz signal is not the cleanest, the square waveform is more... squiggly if you will, but it doesn't seem to be bad enough to impact the communication, as the line is still above the high logic threshold for the specified duration, and held low long enough. If you would like me to post an image of the waveform I can do that.

Thanks again for the all the help, much appreciated.

- Josh

P.S. I am a college student working on an undergraduate project with the Space Grant Consortium. So if I seem a little lacking in some background knowledge please try to work with me, I'm glad to learn more whenever I can.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

signal integrity on the SPI module when operating at 16 MHz

What error rate do you get at 4MHz? 1MHz?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theusch,

So I did a quick little test and this is what I got:

4 MHz Clock - 518723 Sector Writes - 0 Errors
1 MHz Clock - 237993 Sector Writes - 0 Errors

Definitely seems indicative of a signal integrity issue. I went ahead and stopped the 1 MHz test before it reached 500k writes because it was just taking too damn long, heh. I figured if there were no errors on 4 MHz the 1 MHz should be fine, and 200k writes should be enough to see any errors that crop up.

Still, it seems to me that the MCU should be able to run a 16 MHz SPI no problem right?

- Josh