3

I am interfacing a 32 GB Micro SD card with a 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 doesn't seem to work 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 right way of detecting the card's presence?

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.5 V and when the card is inserted, it again shows 3.5 V. Am I doing something wrong or does the hardware have some problem?

ocrdu
  • 8,705
  • 21
  • 30
  • 42
user007
  • 409
  • 1
  • 8
  • 18
  • by reading the state of that pin? – PlasmaHH Dec 22 '15 at 11:16
  • you mean if its high, so card is present – user007 Dec 22 '15 at 11:17
  • @PlasmaHH if the card is not getting detected, so that means it will not further initialized. Is card detection really important? – user007 Dec 22 '15 at 11:35
  • 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. – Michael Karas Dec 22 '15 at 12:47
  • SanDisk Datasheet states that card detection can be done by reading the SD-internal 50K pull-up resistor on the SD-CS# pin. In your circuit this is killed by your own pull-up. I would try removing R28, then add a 500K/1M pull-down resistor to ensure a 0 read on that pin when no card is the slot. Not really an issue, but note that although SD Specs clearly states the presence of this pull-up resistor, this is not the case for the old MMC standard. – mgruber4 Apr 11 '20 at 08:07

1 Answers1

4

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.

Michael Karas
  • 56,889
  • 3
  • 70
  • 138
  • Thanks for the useful information. I have edited my question and uploaded the schematic. Please have a look at it. – user007 Dec 22 '15 at 12:33
  • @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.... – Michael Karas Dec 22 '15 at 12:43
  • I think there is some problem in card connector. Maybe its switch is broken. Thank you very much.! – user007 Dec 22 '15 at 12:55
  • 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. – Michael Karas Dec 22 '15 at 13:20
  • I think my SD card connector is not push push type connector because to remove the card from the connector I didn't need to push the connector inside instead i just removed it simply by pulling it out. There is no switch in the connector which will eject the card while we push the card inside. I am confused because every SD card connector has a switch which help in removing the card but this one doesn't have any switch. So is this connector faulty or its an another type of connector and its fine. – user007 Dec 23 '15 at 04:42
  • I think its a manual insertion/removal type connector but then it is not giving me any kind of voltage change while I insert or remove the card. I am checking the voltage according to the steps you have described by checking the voltage across resistor but there is no change in voltage. What could be the problem? – user007 Dec 23 '15 at 04:49
  • Very few, if any, SD and uSD card connectors have support for an eject button. Sockets come in three basic types. 1) Simple insert/removal type where there is no mechanical catch to keep card in place. 2) Type where the insertion of the card crosses a detent that places a friction hold on the card and grasping card to pull it out overcomes the detent. 3) Push-push type socket where the card pushes in against spring tension and will latch into position to hold the card in place and a second push in will release the latch and spring can push the card part way out. (continued) – Michael Karas Dec 23 '15 at 05:51
  • (continued from above). Within these variations the sockets come in inverted and normal types. Inverted types mount on the bottom of a circuit board and let the label side of the card still face up. – Michael Karas Dec 23 '15 at 05:53
  • Thanks for explaining the types of connectors. Mine one is 2nd type connector. So will that detent gives us the signal for card detection or this type of connector doesn't have any type detection functionality. – user007 Dec 23 '15 at 05:58
  • 1
    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. – Michael Karas Dec 23 '15 at 06:03