FAT32 Library not more than 128 files created at a time.

General discussion on Libstock website & codes posted on this website.
Post Reply
Author
Message
dineshreil
Posts: 4
Joined: 15 Nov 2013 11:38
Location: Jaipur

FAT32 Library not more than 128 files created at a time.

#1 Post by dineshreil » 20 Sep 2014 06:21

I am using AVR version of FAT32 Library. I try to create files on it via a for loop.
The problem is: I cannot create more than 128 files in a directory. The loop stops and everything hangs.
I have used 128x64 Graphics LCD to see the current file number value and return message of FAT32 Library functions.
When i see content of card on computer (via card reader). No files seen in directory.
When i reconnect card and restart machine. The counting starts again from 1 ( i wrote in code to skip counting to already created files). And counting goes till 256 and it stops again. When i check on computer, i can see 128 files but not 129-256 file found. Handle is opened and closed, so its not error of exhausting handles value.

The code is here. Hardware is working ok, i have been using the hardware with Fat16 library for 2 years.
The loop code is:

void main()
{
system_init_routine(); // for glcd and keypad , uARt etc.
///////////////////////////////////////
// SPI module initialization
///////////////////////////////////////
initSPI();

///////////////////////////////////////
// initialize storage device.
// optionally, we could format the device
// instead of just initializing it.
///////////////////////////////////////
err = FAT32_Init();
// err = FAT32_format("dev0");
if (err < 0) //
{
UART2_Write(CR);
UART2_Write_Text(constToVar(UART2buf, cmdFAIL[0]));
UART2_Write(CR);

while(err < 0) // ...retry each second
{
err = FAT32_Init();
Delay_ms(1000);
}
}
///////////////////////////////////////
// if all went well, reinitialize
// SPI with greater speed
///////////////////////////////////////
initFastSPI();

Glcd_fill(0);
Glcd_write_text("File Check",30,0,1);
Glcd_write_text("**********************",0,1,1);
Glcd_write_text("input how many files",0,2,1);
Glcd_write_text("5 digits(Ex.00045)",0,3,1);
strcpy(value, get_value_any(30,4,5,0,1));
value[5]='\0';
total=atol(value);
Glcd_write_text(" ",0,2,1);
Glcd_write_text(" ",0,3,1);
Glcd_write_text(" ",0,4,1);


err = 0;
memset(DirName, 0, 9);
memcpy (DirName, "DIR", 3);
err = FAT32_MakeDir(DirName);
err = FAT32_ChangeDir(DirName);

for( // for loop from i =0 to i < total )
{
Glcd_write_text(" ",0,7,1);
h=i;

if(i<1000)
{
strcpy(file_name,"AAAAA");
}
else if(i>999 && i<2000)
{
h=i-1000;
strcpy(file_name,"BBBBB");
}
else if(i>1999 && i <3000)
{
h=i-2000;
strcpy(file_name,"CCCCC");
}
else if(i>2999 && i <4000)
{
h=i-2000;
strcpy(file_name,"DDDDD");
}

longtostr(h,show);

k=5;
j=0;
for(p=0;p<12;p++)
{
if(isdigit(show[p]))
{
file_name[k+j]=show[p];
j++;
}
}
k=k+j;
file_name[k]='\0';
strcat(file_name,".txt");

Glcd_Write_text(" ",0,3,1);
Glcd_Write_text("Name:",0,3,1);
Glcd_Write_text(file_name,30,3,1);
longtostr(h,show);
Glcd_Write_text(show,15,4,1);
Glcd_Write_text("Current:",0,4,1);
longtostr(i,show);
Glcd_Write_text(show,0,5,1);
Glcd_Write_text("/",80,5,1);
Glcd_Write_text(value,86,5,1);


fileHandle[0] = FAT32_Open(file_name, FILE_APPEND);
if (fileHandle[0] < 0)
{
UART2_Write(i);
UART2_Write(j);
while(1);
}
err = FAT32_Close(fileHandle[0]);

} // for lops ends

} // main function closes
Don't wait for the Last Judgment. It happens every day.

Muphy
Posts: 318
Joined: 24 Feb 2008 14:05
Location: Stonehaven Scotland

Re: FAT32 Library not more than 128 files created at a time.

#2 Post by Muphy » 22 Sep 2014 13:29

You have not posted all of your code, it is going to be important to see how all the variables have been declared. Post it all or as much as you can!

Can you also _please_ use the Code styles when pasting in code to give anyone who wants to help a fighting chance to see the formatting and try and understand the structure of your code. The styles available to you are above the text box into which you typed your question (and pasted your snippet of code)


Thanks,

Mark

dineshreil
Posts: 4
Joined: 15 Nov 2013 11:38
Location: Jaipur

Re: FAT32 Library not more than 128 files created at a time.

#3 Post by dineshreil » 23 Sep 2014 06:18

Thank you for updating me about Code Style...I will take care of it in future.

And about the code details:
I have been using Fat16 Library of Mikroc for AVR. And hit a dead end on number of files in a directory.
(limited to 1022 or 2048, depending on SDcard Company).
I am using 4GB SDcard of Sony or Kingston. (Details: SDHC, No. SD-k04G). I had lot of discussion with MikroE team and Marina Petrovic helped me with few matters, we discussed but still no solution. We hit dead end.
They suggested me to work on FAT32 Lib instead. The hardware is working fine for 2 years. No issues with that.
The software also just bit modified for FAT32 Lib requirement.

I have used their sample code to create files FILEXY in DIRXY for all english 26 letter combinations.
But i have just increased the number of files in loop and made it 10000 ( Ten thousand).
I checked the program and hit again with lot of issues, which i have mentioned earlier.
If you are concerned with code/variable etc, i request you to look for FAT32 Library Sample code/Example code for AVR. I changed Micronctroller from ATmega128 to ATmega1560. All clock sources, fuse settings are properly defined, checked and verified.

The new problem with FAT32 library is mentioned in first message of this post.


Code: Select all


void main()
{
system_init_routine(); // for glcd and keypad , uARt etc.
///////////////////////////////////////
// SPI module initialization
///////////////////////////////////////
initSPI();

///////////////////////////////////////
// initialize storage device.
// optionally, we could format the device
// instead of just initializing it.
///////////////////////////////////////
err = FAT32_Init();
// err = FAT32_format("dev0");
if (err < 0) //
{
UART2_Write(CR);
UART2_Write_Text(constToVar(UART2buf, cmdFAIL[0]));
UART2_Write(CR);

while(err < 0) // ...retry each second
{
err = FAT32_Init();
Delay_ms(1000);
}
}
///////////////////////////////////////
// if all went well, reinitialize
// SPI with greater speed
///////////////////////////////////////
initFastSPI();

Glcd_fill(0);
Glcd_write_text("File Check",30,0,1);
Glcd_write_text("**********************",0,1,1);
Glcd_write_text("input how many files",0,2,1);
Glcd_write_text("5 digits(Ex.00045)",0,3,1);
strcpy(value, get_value_any(30,4,5,0,1));
value[5]='\0';
total=atol(value);
Glcd_write_text(" ",0,2,1);
Glcd_write_text(" ",0,3,1);
Glcd_write_text(" ",0,4,1);


err = 0;
memset(DirName, 0, 9);
memcpy (DirName, "DIR", 3);
err = FAT32_MakeDir(DirName);
err = FAT32_ChangeDir(DirName);

for( // for loop from i =0 to i < total )
{
Glcd_write_text(" ",0,7,1);
h=i;

if(i<1000)
{
strcpy(file_name,"AAAAA");
}
else if(i>999 && i<2000)
{
h=i-1000;
strcpy(file_name,"BBBBB");
}
else if(i>1999 && i <3000)
{
h=i-2000;
strcpy(file_name,"CCCCC");
}
else if(i>2999 && i <4000)
{
h=i-2000;
strcpy(file_name,"DDDDD");
}

longtostr(h,show);

k=5;
j=0;
for(p=0;p<12;p++)
{
if(isdigit(show[p]))
{
file_name[k+j]=show[p];
j++;
}
}
k=k+j;
file_name[k]='\0';
strcat(file_name,".txt");

Glcd_Write_text(" ",0,3,1);
Glcd_Write_text("Name:",0,3,1);
Glcd_Write_text(file_name,30,3,1);
longtostr(h,show);
Glcd_Write_text(show,15,4,1);
Glcd_Write_text("Current:",0,4,1);
longtostr(i,show);
Glcd_Write_text(show,0,5,1);
Glcd_Write_text("/",80,5,1);
Glcd_Write_text(value,86,5,1);


fileHandle[0] = FAT32_Open(file_name, FILE_APPEND);
if (fileHandle[0] < 0)
{
UART2_Write(i);
UART2_Write(j);
while(1);
}
err = FAT32_Close(fileHandle[0]);

} // for lops ends

} // main function closes


Don't wait for the Last Judgment. It happens every day.

Post Reply

Return to “Libstock Discussion”