Electronic – How to detect SD Card Insertion Without Leakage Current

microcontrollermicrosdpower

I'm using a TI CC1111 SoC to read/write a microSDHC SD card, with an Amphenol card socket. The card detect (CD) pin of the socket is connected to ground when no card is present. When a card is inserted, the connection is broken. (This seems to contradict the datasheet, but it's what my multimeter tells me).

One way to detect card insertion would be to connect a GPIO pin to the CD pin. By default the CC1111's pins are configured with an internal pull-up resistor. If a card were present, I'd read logic high, and otherwise the pin would be pulled to ground. But I worried this might draw excessive current, and sure enough, the CC1111 datasheet warns (pg. 90):

Unused I/O pins should have a defined level and not be left floating. One way to do 
this is to leave the pin unconnected and configure the pin as a general purpose I/O 
input with pull-up resistor. This is the default state of all pins after reset except 
for P1_0 and P1_1 ... Alternatively the pin can be configured as a general 
purpose I/O output. In both cases the pin should not be connected directly to VDD or
GND in order to avoid excessive power consumption.

Question 1: Where is the power consumed? Is it just in the internal pull-up resistor? The datasheet says the internal pull-ups are 20k, so with 3.3 V that's about 0.17 mA. Is that what they're talking about? Or perhaps the "excessive power consumption" warning only applies when the pin is configured as an output?

Qustion 2: What is the right way to detect card insertion/removal without wasting power?

And no, I haven't measured the current draw yet, but I will.

Best Answer

I'm pretty sure the datasheet warning is there to cover the case where a pin is tied directly to Vcc or Gnd, but then the firmware configures that pin as an output and tries to drive it to the opposite state (either because of a bug or a subsequent firmware change).

If you really want to play it safe, put a relatively low-value (say, 1K) resistor between the card socket contact and the GPIO pin. When the GPIO pin is used as an input, this resistor forms a voltage divider in conjunction with the internal pullup that still allows the pin to be read as "0". However, if the GPIO pin should inadvertently be configured as an output and driven high, it serves to limit the current flow to a few mA.