3

I have an SD card (or SDHC card) connected to a microcontroller via SPI mode. I am using Chan’s FAT library. I write data to it which comes from an 8192 byte buffer (buffer cannot be larger due to insufficient RAM). This writing is performed periodically. Normally writing is ready before the buffer is filled again. But once in a while (also depending on the buffer fill speed) things go wrong and writing is NOT ready before the new buffer has to be written, causing loss of data.

BTW, sector size is also set to 8192 bytes, but others do not seem to have an influence.

The writing can be monitored with a scope, and shows that sometimes writing takes a long time. For example, four times longer than usual.

What is going on here, and maybe how do I prevent this from happening? Has this something to do with a read, modify, write sequence? Do I need an external RAM buffer? Or are there better ways to improve performance?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wlamers
  • 1,276
  • 2
  • 12
  • 14

1 Answers1

2

Not a software cause, but flash fundamentally has varying write times. The reason is that the voltage needed to perform a write is carefully balanced. Too high causes permanent damage, too low may fail to change the value. The latter is automatically handled, with just a "slight" stutter as a result. Yet, that stutter seems to be too long for you as your buffer is tiny.

Solutions? We've used expensive single-level (SLC) SD cards in the past. Even now we insist on qualifying all firmware versions. We certainly don't buy SD cards on the spot market.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MSalters
  • 173,980
  • 10
  • 155
  • 350
  • So the voltage handling is causing the delay right? Would using SLC SD cards be having not these kind of problems even in SPI mode? – wlamers Aug 31 '12 at 14:57
  • SPI is just the bus, not the physical write, and it's the latter which probably causes the stutter. SLC works better because you only need to write a `1`, not a `01` or `10` or `11`. – MSalters Aug 31 '12 at 23:29