Products > Embedded Computing

Detect microSD card connected to Arduino?

(1/3) > >>

Peabody:
I'm looking at a possible new SD card bootloader for Arduinos, and this would typically require level shifting since Arduinos are usually 5V and SD cards are 3.3V.  Here is the module widely available on Ebay:

https://www.ebay.com/itm/382768089497

And I believe the relevant schematic is attached below.

The problem is detecting the presence of the card on power-up, if possible something other than sending commands into the ether and seeing if any response comes back.  That's not a good solution because the user's circuit may have other things connected to the SPI pins.

I've done such a bootloader for a couple of the TI MSP430 parts, which don't require level shifting.  Every card has a nominal 50K pullup resistor on its card select pin, so I put a 1M external pulldown resistor on that line at the MSP end, so I could read the value at boot.  If the card is present it reads HI, otherwise LO.  If a card is present, then I switch the pin over to output mode for its chip-select function, and the pullup and pulldown resistors are of high enough value that they don't interfere.

But I haven't figured out a way to make that work with level shifting, and haven't come up with any alternative.  Unfortunately, the "card inserted" pin on the holder isn't brought out to the module header.

If anyone can think of something, please let me know.

stj:
look closely,
the socket contains a switch near the "J1" print.

Peabody:

--- Quote from: stj on April 22, 2019, 06:48:31 pm ---look closely,
the socket contains a switch near the "J1" print.

--- End quote ---

Yes, that's the switch that connects to ground if a card is inserted, and it's connected to the first pin on the holder.  But that pin isn't connected to anything.  In the worst case I will use that, but it would require devoting yet another GPIO pin to this, which I would rather not do.

I've come up with something that may work.  See attached circuit.  I jumper around the 125 gate on the Card Select line, and add the 1M resistor on the Arduino, so it looks like the MSP430 version.  At the beginning the port is in Read mode, and it will read high if a card is present because the card has a pullup resistor on that pin.  Otherwise it will read low because of the 1M pulldown.  Then if a card is present, I get around the need for level shifting by putting the port in Input mode when I need it to go high, at which point the pullup resistor in the card brings it high, and putting the port in Output, Low mode when I need it to be low.  But I never actually source 5V  to that pin on the card, so level shifting isn't needed.

This is just the card select line, so there's nothing fast going on there.  I will test this when my modules arrive.

thm_w:
I know its not what you want, but here is the module with CD signal if anyone else is wondering: https://www.aliexpress.com/item/MicroSD-card-module/32530917432.html

Your idea is great though, I've had to deal with a lot of bad card detect type switches (which stops product from working), they really are not needed as is shown here.

OM222O:
easiest solution I can think of:

I'm not sure which micro you are using, but there should be some library that allows you write to files etc.
Try opening a file with a random name for write and check for exceptions. if there were exception it means there is no sd card and if it passed, it means there is one. put this in a timer interrupt that happens let's say every second and you will have a pretty responsive device without using any hardware.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod