DigitalIn pullup detect

29 May 2011

I've got this code:

...
DigitalIn carddetect(p9);
...
main(){
...
 carddetect.mode(PullUp);
    if (carddetect==0) {
        error("SD card not found\n");
    }
...

I'm trying to use the CD pin on the sparkfun uSD breakout board. However, no matter the state of the SD card, I'm always getting the error. I've confirmed that the voltage at the pin changes from 0 to 2.3 when the card is inserted, and I believe this should correspond in a digital change from 0 to 1.

Any suggestions?

29 May 2011

Hi Andrew, i think the switches in the card reader are closing to GND ( GND1 maybe ) Try first to measure the switch points at the breakoutboard. The 2 switches ( card detect and Write protect ) have an common contact and are not connected to the GND from the data signals. /media/uploads/driedee/dscn2304.jpg

Not inserted==1 , inserted==0

Have you connected COM to GND ? BTW At my SD-card socket that common contact is NOT connected to the housing.

Hugo

29 May 2011

When the card is out, the CD is definitely connected to ground. When I insert the card, the connection is broken (as I would expect). And COM is connected to GND.

Referenced to ground, the pin voltage changes from 0 ->3.5V when the card is inserted, so I believe the breakout board and switch are working, there's just something wrong with my code.

29 May 2011

I put a 1ms delay after: carddetect.mode(PullUp); Seems to work now... must of just taken time to pull the pin up... If anyone has any other solutions that work without a delay that'd be great

29 May 2011

Could switch bounce, try using PinDetect:-

Import libraryPinDetect

InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold.

29 May 2011

Good to know that not every SD-card connector has the same switch result ! The first i found http://www.globalconnectortechnology.com/memory-card-connectors/pdf/MEM1050.pdf Is open when there is no card in it, and electric also not equal mine, wp switch to gnd, cd to p3. It looks like its important to watch the right schematic.