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

Problem in using fopen function

I have added the code.Calling init_filesystem() initializes and mounts the RAM drive successfully and turns the corresponding pins of PORT2 HIGH.This happens so if am not calling the tst_fopen() function.But whenever am calling tst_fopen function,fopen() runs out by an exception and the corresponding pins of PORT2 are switched as LOW.
What could be the issue ?

#include "lpc17xx.h"
#include "rl_fs.h"
#include <stdio.h>
char *opt ="NULL";
fsStatus stat;
char *fname="r.txt";
FILE *f;
 void init_filesystem (void) {
LPC_PINCON->PINSEL4=0X00000000;
LPC_GPIO2->FIODIR=0XFFFFFFFF;
LPC_PINCON->PINSEL2=0X00000000;
LPC_GPIO1->FIODIR=0XFFFFFFFF;
stat = finit ("R0:");
if (stat == fsOK){
stat = fmount ("R0:");
if(stat==fsOK)
{
LPC_GPIO1->FIOPIN=0XFFFFFFFF;
}
else if(stat==fsNoFileSystem)
{
if (fformat ("R0:", "") == fsOK){
stat = fmount ("R0:");
if(stat==fsOK)
{
LPC_GPIO2->FIOPIN=0X0000000F;
}}
}}
}

void tst_fopen (void)  {
f = fopen ("R0:\\r.txt","r");
 if (f == NULL)  {
  LPC_GPIO2->FIOPIN=0XFFFFFFF3;
}
else {
LPC_GPIO2->FIOPIN=0XFFFFFFF6;
}
}

int main (void)
{
SystemInit();
init_filesystem();
tst_fopen();
}