Jump to content

[SOLVED]FILE_CheckSDcard() returns 0 2nd time launched with DisCon SD


Recommended Posts

Posted (edited)

hi

i want to check if the SD-Card is connected or not... so far so good, no problem, but there is a behaviour that cost me the night...

Connected SD:

1st execution of FILE_CheckSDCard() > Return "0"... that is good - it work right

2nd execution of FILE_CheckSDCard() > Return "0"... that is good - it work right

 

Disconnected SD:

1st execution of FILE_CheckSDCard() > Return "2"... that is good - it work right

2nd execution of FILE_CheckSDCard() > Return "0"... why that? the SD is still NOT connected...

this code is executed every 2 seconds:
 

MUTEX_SDCARD_TAKE;         status = FILE_CheckSDCard();     MUTEX_SDCARD_GIVE;
      if (status == 2) { //NO SD
      if (status == 0) { //SD

.... EDIT

"FILE_CheckSDCard" itself internally uses  "MIOS32_SDCARD_CheckAvailable();" maybe that is a trace

 

when using "MIOS32_SDCARD_CheckAvailable" instead of "FILE_CheckSDCard()"

but "FILE_DirExists" looses its functions and returns me everytime "-3" them, so useless for me again...so i am circling around...

//SD-Card Connected?
    u8 prev_sdcard_available = sdcard_available;
    MUTEX_SDCARD_TAKE;       sdcard_available = MIOS32_SDCARD_CheckAvailable(prev_sdcard_available);         MUTEX_SDCARD_GIVE;   
    if( sdcard_available && !prev_sdcard_available ) { statusSD = 1;}   // SD Card has been connected
    else if( !sdcard_available && prev_sdcard_available ) { statusSD = 0;


      if (statusSD == 0) {//NO DISK}         
      if (statusSD == 1) {// YES CARD!  >>> next: check Card-content
                                     statusDir = FILE_DirExists("mq");    //ask file.c: exist a folder "mq/" on the CARD?    

 

Edited by Phatline
Posted

ok this 3 lines are needet, then its working:

//Check SD-Card
MUTEX_SDCARD_TAKE;      
	availableSD = FILE_SDCardAvailable();
	statusSD    = FILE_CheckSDCard();
	statusDir   = FILE_DirExists("mq");
MUTEX_SDCARD_GIVE;

availableSD is the one to take...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...