This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SD card interface with LPC1768

I am trying to interface an SD card with LPC1768 using SPI protocol.I am using File system middleware provided in ARM MDK which uses CMSIS SPI DRIVER API as the lowest layer to communicate with the hardware.The following code is to initialize and mount the memory card drive.It is expected to receive a fsOK status for successful mounting but instead, the fmount function doesn't return any status or error code and nothing happens, as far as switch case instruction is concerned.

What could be the problem ?

void init_filesystem (void) {

stat1=finit("M0:");
if(stat==fsOK)
{
LPC_GPIO1->FIOPIN=0XFFFFFFFF;
stat2==fmount("M0:");

switch(stat2)
         {
case fsOK:
LPC_GPIO2->FIOPIN=0X00000001;
break;
case fsError:
LPC_GPIO2->FIOPIN=0X00000002;
break;
case fsNoMedia :
LPC_GPIO2->FIOPIN=0X00000004;
break;
case fsNoFileSystem :
LPC_GPIO2->FIOPIN=0X00000008;
break;
case fsNoFreeSpace :
LPC_GPIO2->FIOPIN=0X00000010;
break;
case fsFileNotFound :
LPC_GPIO2->FIOPIN=0X00000020;
break;
case fsDirNotEmpty:
LPC_GPIO2->FIOPIN=0X00000040;
break;
case fsTooManyOpenFiles:
LPC_GPIO2->FIOPIN=0X00000080;
break;
case fsUnsupported:
LPC_GPIO2->FIOPIN=0X00000100;
break;
case fsAccessDenied:
LPC_GPIO2->FIOPIN=0X00000200;
break;
case InvalidParameter;
LPC_GPIO2->FIOPIN=0X00000400;
break;
case fsInvalidDrive :
LPC_GPIO2->FIOPIN=0X00000800;
break;
case fsInvalidPath :
LPC_GPIO2->FIOPIN=0X00001000;
break;
case fsUninitializedDrive  :
LPC_GPIO2->FIOPIN=0X00002000;
break;                                                                                  \ 
case fsDriverError:
LPC_GPIO2->FIOPIN=0X00004000;
break;
case fsMediaError :
LPC_GPIO2->FIOPIN=0X00008000;
    break;

         }
 }

}

Parents
  • I have added the default statement but the function must return a value from the status enum.Actually, the problem is whenever I insert the memory card and try to run the following initializing code,even the code statement after calling the fmount function doesn't work at all.And as soon as I remove the memory card and reset the controller with same code,switch case instruction of media error gets executed.

    void init_filesystem (void) {
    
    stat1=finit("M0:");
    if(stat==fsOK)
    {
    
    stat2==fmount("M0:");
    LPC_GPIO1->FIOPIN=0XFFFFFFFF;
    switch(stat2)
             {
    case fsOK:
    LPC_GPIO2->FIOPIN=0X00000001;
    break;
    case fsError:
    LPC_GPIO2->FIOPIN=0X00000002;
    break;
    case fsNoMedia :
    LPC_GPIO2->FIOPIN=0X00000004;
    break;
    case fsNoFileSystem :
    LPC_GPIO2->FIOPIN=0X00000008;
    break;
    case fsNoFreeSpace :
    LPC_GPIO2->FIOPIN=0X00000010;
    break;
    case fsFileNotFound :
    LPC_GPIO2->FIOPIN=0X00000020;
    break;
    case fsDirNotEmpty:
    LPC_GPIO2->FIOPIN=0X00000040;
    break;
    case fsTooManyOpenFiles:
    LPC_GPIO2->FIOPIN=0X00000080;
    break;
    case fsUnsupported:
    LPC_GPIO2->FIOPIN=0X00000100;
    break;
    case fsAccessDenied:
    LPC_GPIO2->FIOPIN=0X00000200;
    break;
    case InvalidParameter;
    LPC_GPIO2->FIOPIN=0X00000400;
    break;
    case fsInvalidDrive :
    LPC_GPIO2->FIOPIN=0X00000800;
    break;
    case fsInvalidPath :
    LPC_GPIO2->FIOPIN=0X00001000;
    break;
    case fsUninitializedDrive  :
    LPC_GPIO2->FIOPIN=0X00002000;
    break;                                                                                  \ 
    case fsDriverError:
    LPC_GPIO2->FIOPIN=0X00004000;
    break;
    case fsMediaError :
    LPC_GPIO2->FIOPIN=0X00008000;
    break;
    default:
    LPC_GPIO->FIOPIN=OXFFFF0000;
    }
     }
    
    
    

Reply
  • I have added the default statement but the function must return a value from the status enum.Actually, the problem is whenever I insert the memory card and try to run the following initializing code,even the code statement after calling the fmount function doesn't work at all.And as soon as I remove the memory card and reset the controller with same code,switch case instruction of media error gets executed.

    void init_filesystem (void) {
    
    stat1=finit("M0:");
    if(stat==fsOK)
    {
    
    stat2==fmount("M0:");
    LPC_GPIO1->FIOPIN=0XFFFFFFFF;
    switch(stat2)
             {
    case fsOK:
    LPC_GPIO2->FIOPIN=0X00000001;
    break;
    case fsError:
    LPC_GPIO2->FIOPIN=0X00000002;
    break;
    case fsNoMedia :
    LPC_GPIO2->FIOPIN=0X00000004;
    break;
    case fsNoFileSystem :
    LPC_GPIO2->FIOPIN=0X00000008;
    break;
    case fsNoFreeSpace :
    LPC_GPIO2->FIOPIN=0X00000010;
    break;
    case fsFileNotFound :
    LPC_GPIO2->FIOPIN=0X00000020;
    break;
    case fsDirNotEmpty:
    LPC_GPIO2->FIOPIN=0X00000040;
    break;
    case fsTooManyOpenFiles:
    LPC_GPIO2->FIOPIN=0X00000080;
    break;
    case fsUnsupported:
    LPC_GPIO2->FIOPIN=0X00000100;
    break;
    case fsAccessDenied:
    LPC_GPIO2->FIOPIN=0X00000200;
    break;
    case InvalidParameter;
    LPC_GPIO2->FIOPIN=0X00000400;
    break;
    case fsInvalidDrive :
    LPC_GPIO2->FIOPIN=0X00000800;
    break;
    case fsInvalidPath :
    LPC_GPIO2->FIOPIN=0X00001000;
    break;
    case fsUninitializedDrive  :
    LPC_GPIO2->FIOPIN=0X00002000;
    break;                                                                                  \ 
    case fsDriverError:
    LPC_GPIO2->FIOPIN=0X00004000;
    break;
    case fsMediaError :
    LPC_GPIO2->FIOPIN=0X00008000;
    break;
    default:
    LPC_GPIO->FIOPIN=OXFFFF0000;
    }
     }
    
    
    

Children