Go Down

Topic: new SdFat library beta - sensing card detect and write protect (Read 1 time) previous topic - next topic


I use the card detect to decide if I should make logs. If there is no card, my app will merily go along its business without making logs. This is handy for my app.

I check the WP manually, and if it is asserted, I don't write logs, but I do read update info for my app from the card.

I expect most times a user puts a write protected card in, it will be a mistake. But the potential for data destruction if I ignore WP is not a risk i want to accept (and get complaints about).


The write protect tab is not electrically connected to the card.  It can be sensed by most SD sockets and can be used to implement write protect in software.  In practice it is not very useful with the Arduino since most apps write to files.

You could connect the socket write protect sensor to a digital pin and refuse to open files for write.  It is probably better to sense write protect in your application and warn the user. 

There is no standard way to detect write protect on SD shields so I did not implement it.

Card detect is not very useful either.  Users expect to use it to implement card removal or card change.

You can't just remove a card since all files open for write must be closed or you will lose data or cause file system corruption.  This means the user must signal the application to prepare for card removal.  The application must the tell the user to change cards.  At this point you could use card detect.

Sometimes the app tell the user when it wants to change the card.  In any case most of the programming must be done in the app so card detect is best handled by the app.


Hmmm that's awkward!

I never tried it, but will do so later. I know the card holder has a write protect sense you could connect to the Arduino, but I was under the assumption that the card itself (or some cards?) would also block these operations.
Now, if a host doesn't implement it, the write-protect doesn't really offer any protection at all!


Actually I meant what I said. If i put a write protected card in, I can write to it. I can open files. I can delete files. All that stuff. I did npot se a method in the class library structure to check the status of the write protect switch. So I asked.

Go Up