2
\$\begingroup\$

I am interfacing 32GB Micro SD card with PIC32MX795F512L. I am following the examples provided in Lucio de Jasio book. In one of their example, they are using while( !getCD()); to check if the card is present or not. But this seems not working in my case because when I remove the card, it doesn't give any error and moves forward. Below is its code:

// SD card connector presence detection switch
int getCD( void)
// returns TRUE card present
// FALSE card not present
{
 return !SDCD;
}

In the hardware, SD-CD pin is connected to RA15. So what is the way of detecting the card presence?

EDIT:

enter image description here

Above is the schematic for SD card connections. SD-CD# pin is the pin for card detect. I am checking the voltage change on R34 but there is no change. When the card is removed, it shows 3.5v and when card is inserted, it again shows 3.5v. Am I doing something wrong or hardware has got some problem.

\$\endgroup\$
  • \$\begingroup\$ by reading the state of that pin? \$\endgroup\$ – PlasmaHH Dec 22 '15 at 11:16
  • \$\begingroup\$ you mean if its high, so card is present \$\endgroup\$ – user007 Dec 22 '15 at 11:17
  • \$\begingroup\$ @PlasmaHH if the card is not getting detected, so that means it will not further initialized. Is card detection really important? \$\endgroup\$ – user007 Dec 22 '15 at 11:35
  • \$\begingroup\$ Card detection can be important. It really depends upon several things and how the software to access the card interface is written. If access is started to the interface without a card present the software could hang waiting for a response. Similarly if a card is being accessed for writing and a removal is not properly handled the card could end up being corrupted. \$\endgroup\$ – Michael Karas Dec 22 '15 at 12:47
2
\$\begingroup\$

SD Card detection is typically done by a mechanical switch that is built right into the SD Card socket. It opens and closes when the card is inserted and removed. You will have to investigate how this switch is hooked up in your hardware and test that this works correctly up to the PIC32 pin before you even begin to think about software issues.

Testing the hardware should be as simple as looking at the signal going to the PIC32 pin using a scope probe or multi-meter in volts measure mode. With the PIC32 board powered monitor if there are changes of state in the signal as a card is inserted or removed. If you do not see this working then the switch in the socket is not properly connected. It is typical that one side of these switches is connected to GND. The other side has a pullup resistor to +3.3V and also connects to the PIC32 pin. If working correctly you should see it changing between 3.3V and GND.

Once you have verified the hardware connection it is time to investigate the PIC32 software aspect. The particular pin connection needs to be a general purpose input port pin on the microprocessor. Then that port pin needs to be properly configured to be acting as a digital input pin. If not properly configured then there will be no joy in reading in the SD Card status signal.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the useful information. I have edited my question and uploaded the schematic. Please have a look at it. \$\endgroup\$ – user007 Dec 22 '15 at 12:33
  • \$\begingroup\$ @user007 - Well at least you now know that there may be something wrong with the hardware. The SD Card socket could be broken or the socket does not have a switch.... \$\endgroup\$ – Michael Karas Dec 22 '15 at 12:43
  • \$\begingroup\$ I think there is some problem in card connector. Maybe its switch is broken. Thank you very much.! \$\endgroup\$ – user007 Dec 22 '15 at 12:55
  • \$\begingroup\$ I have tested multiple uSD card connectors and found huge quality variation between them. I bought like 8 or 10 different ones to aid in selection of a socket for a project I was working on. I can also say that some of the sockets with the push-push type insert and eject mode of operation can be seriously damaged if the card is forcibly pulled out when it is in the retained position. Thus if you select a push-push type socket you want to look for one, that when used in conjunction with the product case, does not allow normal access to yank the card out without the push eject action. \$\endgroup\$ – Michael Karas Dec 22 '15 at 13:20
  • 1
    \$\begingroup\$ Whether the SD or uSD card socket supports a card detect switch is a different question from the type of card retention mechanism the socket supports. Most sockets will have the card detect switch contact built into the socket. However that said I am sure that there are a few types without the switch to save a few pennies of cost. Note that these switches are pretty delicate, especially for uSD card sockets and can be easily damages. You should look to see of any of the SMT feet of your socket failed to solder properly. Secondly try to find the socket mfg and look up the part data sheet. \$\endgroup\$ – Michael Karas Dec 23 '15 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.