I am using a SD Card Module that has no pin for checking existence of SD Card, So i should do the check using fatfs libs. The micro-controller is STM32F103RB and i'am using SPI protocol to communicate with SD Card. Up to now i can detect a removal state with this code:

bool check_SdCard()
    FATFS check_fatfs;

        return true;
    else return false;

The problem is that i can't check insertion of SD Card (or i cant re init the SD Card properly) to Read/Write to it after removing it from a previous initialization.

the above code returns true if the SD Card is inserted to the module from first startup of the device but always returns false if SD Card removed/reinserted after startup. so f_mount could not reinitialize SD Card after reinsertion. I've also tried

with no success. Does anyone know how to solve the problem of re initialization of SD Card using fatfs?

  • \$\begingroup\$ Try to unmount the card first before checking for re-insertion. I.e., unmount it once you detect it has been removed (r/w error or something). \$\endgroup\$ – JimmyB Jan 28 at 9:27
  • \$\begingroup\$ According to f_mount documentation in this link, a f_mount(NULL,"",0); or f_mount(0,"",0); will do an unmount. I've also tried this but ended with the same result that the code in question has. @JimmyB \$\endgroup\$ – sina jahromi Jan 28 at 13:04

Your Answer

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

Browse other questions tagged or ask your own question.