Hey guys,
I wanna create a fast data logging project with an Arduino. In order to achieve this goal, I wanna fully understand the functionalities of an SD card and how to write data on it. I did some research in the data sheets as well as on sdcard.org (SD association website). I found the attached scheme for using multiple block write, how it is probably used in the defat library low latency logger. Now my question is, why is the SD card busy both after the card received data from the host and after the stop trans token was sent? In which way are data written to the card after a 512 byte block was received and what happens on the card after the stop trans token was sent? In the specification I sadly didn't find any answer to this, as it only describes what to sent to the sd card...
Thanks in advance!
The SD card sends a "busy" flag because it's a NAND flash memory (same technology of a pendrive and a SSD).
In this kind of memory, reading is straightfoward, but writing is not.
For writing purposes, a NAND flash is divided in sections of equal size called "pages" (of 512 bytes in this case). In order to overwrite one of those "pages", the memory has to do it in two steps: erase (set all bits to 1) and program (set the required bits to 0).
Due to the way a NAND flash works, you can set individual bits to 0, but not back to 1; for that, you're forced to set all of them (inside a "page" of course) at once.
This erase-program cycle takes up to a couple of milliseconds (but most of the time takes around 500 microseconds).
So why is the SD card busy after a data transfer? It's because it's a NAND flash memory and now you know that the write process takes a while.
What the master does, is sending dummy bytes to constantly check when the SD card is ready again; during the erase-program cycle it refuses to accept any command and replies with "busy".
It is a good idea to cache (in RAM) at least one page/block/sector, because even if you transfer a single byte to the card, the whole corresponding page is still erased-programmed; which it's pretty inefficient considering how slow that process is.
If you're wondering what happens after the card readies up, apart from accepting commands once again, it goes to a sleep standby mode (lowest power consumption state) after idling for a second. Here's where is safe to remove or power off the card.
Trivia: the "erase" part of the write cycle is what wears-out a NAND flash memory.