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?