fat16lib - you are talking like so many software engineers I have known. You can't change the laws of physics by writing a spec that says it should not be so.
Clearly something happened for the card to fail, it could be:-
A random fail unconnected with anything he was doing.
Something he did that caused the fail or made it more likely.
You seem to be saying it is 1) because it couldn't be 2) {as an aside have you ever read Catch 22?, the bit where the plane crashed and he was on the passenger list}
So if you are so sure of yourself, take four SD cards from different manufacturers. Run that same code, and plug and unplug the arduino say twenty to thirty times with about 20 seconds between plugs. Then if you get a fail you will know you are wrong. If you don't get a fail you will either be right or the OP was particularly unlucky.
Mike, you are a grumpy old guy. Kind of funny/amusing too.
I am a PhD physicist. I taught solid state physics to EEs.
I spent most of my career at large world class research labs working with advanced electronics. LBNL, CERN, Fermilab, and others.
Now that I am retired, I amuse myself with programming since I didn't have time for that while I was working. I had a large staff of electrical engineers and programmers.
It is about probability and it is extremely unlikely that pulling the card during a write damaged it since it was designed to be pulled during write with power on it.
I have tried to damage SD cards by pulling them during write. I wrote a program to do the fastest possible raw write to an SD card to see what would happen. I never damaged any.
Well your career almost matches mine, PhD, Physics lecturer at a University for 21 years taught graduate and undergraduate EE and Physics students and then in industry for 15 years.
However what I can't understand is you keep saying:-
It is about probability and it is extremely unlikely that pulling the card during a write damaged it
I know he didn't damage it by pulling it out of the socket,
He removed the power from the arduino he did not pull out the SD card from its socket!
That is what you have to test!
I can only assume that your time in academia robbed you of some vital fault finding ability. Something happened, I have never known any academic so starved of data that he will not formulate a hypothesis, so what is yours?
All you keep saying is it could not be this. No alternative explanation?
I know he didn't damage it by pulling it out of the socket.
How do you know this? Static on a signal pin could do it.
Wow, you put me in my place.
I can only assume that your time in academia robbed you of some vital fault finding ability. Something happened, I have never known any academic so starved of data that he will not formulate a hypothesis, so what is yours?
All you keep saying is it could not be this. No alternative explanation?
Mike has me a bit curious about your failed card. I have never seen a true SD card lockup on ACMD41. I have seen it with MMC cards and is to be expected since they they don't support ACMD41.
Could you provide a little more info?
How did you acquire it? There are many counterfeit cards on ebay that have modified firmware and often lockup. These cards are small but are reprogrammed to appear much larger and lockup after some use.
What is the brand?
What is the size in MB or GB?
What is the model for example SanDisk has Ultra, Extreme, etc. Other manufactures have other model names.
I have an old SanDisk card that came with a Canon camera and it also looks a little different than the current retail cards so your card is no doubt genuine.
As a last long long shot go into the Fat16 library and edit SdCard.h at about line 96 change the 2000 to 20000 in this line
uint16_t const SD_INIT_TIMEOUT = 2000;
That will increase the initialization timeout to 20 seconds. You will need to wait a long time for the error message.
The card is failing with ACMD41. The status is busy so lets give it a long time.
That card accepts an alternative initialization command and I have a SanDisk retail version of the card manufactured in 2006.
It should be easy for me to do a small patch that tries CMD1 for initialization.
How much has the card been used?
SanDisk says this card has a life expectancy of 5-10 years for normal consumer use in a camera. Normal consumer use in a camera is not much use.
At the risk of another ad hominem attack by Mike, I will offer "my theory".
I don't think you would do the common things that kill cards, bending, crushing, immersion in water, static or high voltage noise.
After that comes normal wear after five years if you used it very much or a defective part if it had very little use.
I still say power off during programming is not a likely cause. SanDisk says the card should not be harmed by removal of power during programming.
In addition it is unlikely it was programming flash when you removed power. I looked at your sketch and it probably caused two blocks to be written per second. This card buffers write data in RAM and and rapidly programs the data when the block is complete. It is capable of programming 4000-8000 blocks/second so the chance it is programming when the application is running is on the order of 1/2000.
In addition you must assume the Arduino keeps running at very low voltage and the card's power controller fails to stop programming on power failure. To make Mike happy I will say there is a chance this happened but let Mike speculate on the probability that it was programming and the SanDisk design to protect the card is bad.
Here is the patch that uses CMD1 for initialization. If this doesn't initialize the card there is no hope.
CMD1 was used to initialize MMC cards and also works for standard SD cards like the 1GB SanDisk card.
In Fat16 edit SdCard.cpp at about line 180 and replace this:
// start initialization and wait for completed initialization
while ((r = cardAcmd(ACMD41, 0)) != R1_READY_STATE) {
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
error(SD_ERROR_ACMD41, r);
return false;
}
}
with this:
#ifdef USE_ACMD41
// start initialization and wait for completed initialization
while ((r = cardAcmd(ACMD41, 0)) != R1_READY_STATE) {
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
error(SD_ERROR_ACMD41, r);
return false;
}
}
#else // USE ACMD41
// use CMD0 to initialize the card - works with SD or MMC cards
uint8_t const CMD1 = 0X01;
uint8_t const SD_ERROR_CMD1 = 16;
while ((r = cardCommand(CMD1, 0)) != R1_READY_STATE) {
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
error(SD_ERROR_CMD1, r);
return false;
}
}
#endif // USE_ACMD41
I did a benchmark on the 1GB card with a PC test program and it can program 20,000 blocks per second. So there is a 1/10000 chance that it is programming flash in your app at any instant.
for what you've asked - I haven't used it much - about 18 month after buying it I bought a 8GB card and used it with my camera since then
so for the last 3 year it just been in a box unused - till a few weeks ago
about the program you wrote - thanks for your efforts - but I'll be near my arduino only in 2 or 3 days
I'll let you know as soon as I'll try it
hoping for a resurrection of my card:)
There are no other commands to try for that SD. It functions in SD identification mode but will not go into data mode. It just returns busy for any command to switch it to data mode.
I wouldn't worry much, SD cards rarely fail unless they are severely abused . Companies like SanDisk have labs that analyze cards that fail under warranty and keep making SD cards more idiot proof.
There was probably a marginal part in your card. Only SanDisk could diagnose the fault since the card doesn't return a detailed status, just busy.
Since your SanDisk card was made, SD cards have been improved so their expected life is now well over 10 years.
Normally the worst that happens when a card is not shutdown gracefully is a file is corrupted.
About 30,000 people have downloaded the various SD libraries I have written and the Arduino SD.h library is based on my code. I get a lot of email about problems and this is the first card I have seen that would respond to mode and identification commands but not go ready.
Many high end cards like the SanDisk Extreme now have a lifetime warranty.
It doesn't work with 3 sd cards I have, first I was operating off the 3.3v pin, then I found the threads that said the current is too low, so I moved to the 5v pins, still no joy.
I am using SDFormatter to try a full format, all sd cards fail to format with various error codes.
I was going to try providing an independent 5v supply to the card reader/writer, but after I saw the comment from fat16lib on this thread I realised that my issue may be the card reader/writer using divider/pull-up resistors.
Can you point me at a link for a circuit to make this card reader/writer work?
Would this card reader/writer work better with mini/micro sd (in a size changing thingy) using the arduino 3.3v supply?