FAT32 library for MMC/SD cards
Re: FAT32 library for MMC/SD cards
I had one SD card that didn't work with SPI, and it was a very old 16MB card. Any made in the past few years should work, even the generic ones. Mikroelectronika sells them. Or get a good Sandisk or Kingston to be sure.
If you know what you're doing, you're not learning anything.
Re: FAT32 library for MMC/SD cards
Is it possible to have multiple SD cards on the same bus with this library?
Re: FAT32 library for MMC/SD cards
You have to declare an enable pin in the initialization. You might be able to reinitialize every time you change cards. You just have to try it. I would bet that it would work.
You certainly should be able to have two separate cards at SPI1 and SPI2.
You certainly should be able to have two separate cards at SPI1 and SPI2.
If you know what you're doing, you're not learning anything.
Re: FAT32 library for MMC/SD cards
Hello guys,
There is short FAT32_Dir(void) function for extract file names over some user-defined medium.
I don't need any mediums! I need read files names from my SD card to MCU's RAM. How I can do that?
And please explain, how I can select a file on FAT32 file system as the medium.
Best regards.
There is short FAT32_Dir(void) function for extract file names over some user-defined medium.
I don't need any mediums! I need read files names from my SD card to MCU's RAM. How I can do that?
And please explain, how I can select a file on FAT32 file system as the medium.
Best regards.
___________________________________________
http://www.techno-spectr.ru/en/main-en/
Yaroslavl, Russia
http://www.techno-spectr.ru/en/main-en/
Yaroslavl, Russia
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: FAT32 library for MMC/SD cards
Hello,
Please take a look at following topic.
It is for FAT16 but DIR function operates the same way:
http://www.mikroe.com/forum/viewtopic.p ... ir#p183856
Best regards.
Please take a look at following topic.
It is for FAT16 but DIR function operates the same way:
http://www.mikroe.com/forum/viewtopic.p ... ir#p183856
Best regards.
Re: FAT32 library for MMC/SD cards
So it's been several months now and many of us are in need of Fat32 for USB thumbdrives.
Is there any work underway on this?
Thanks in advance..
Bart
Is there any work underway on this?
Thanks in advance..
Bart
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: FAT32 library for MMC/SD cards
Hello,
We do have in plans to develop USB stack and provide support for MSD.
But I can not make any promises regarding release dates.
Best regards.
We do have in plans to develop USB stack and provide support for MSD.
But I can not make any promises regarding release dates.
Best regards.
Re: FAT32 library for MMC/SD cards
Hi ! I need some help using FAT32 library in libstock.com, I am trying to use the library to constantly acquire data from a stormscope sensor (by serial port 1) save latitude and longitude etc acquired by a second serial port and save the data in a file in a SD Card, my code works fine, but after 10 ~ 15 min of operation the hardware stuck and when I try to see the data I notice that the FAT is corrupted and all the data deleted.
I am using a dspic33fj128mc202
After some research I found that the use of a swap file could solve the problem, but i don´t comprehend the use of the swap file by the help in the library, actually I can´t comprehend the method of re-writing the swap data in another file.
Could someone please help with examples ?
Thanks in advance, sorry for my poor english.
Part of my code (the swap file is configured but not used)
I am using a dspic33fj128mc202
After some research I found that the use of a swap file could solve the problem, but i don´t comprehend the use of the swap file by the help in the library, actually I can´t comprehend the method of re-writing the swap data in another file.
Could someone please help with examples ?
Thanks in advance, sorry for my poor english.
Part of my code (the swap file is configured but not used)
Code: Select all
storm=stormlogger(); //data aquisition
FAT32_Delete("SWAP.TXT"); //delete previous swap file
if (FAT32_MakeSwap("SWAP.TXT", 5000, &swapStartSc) == 0) { // make swap file
//for (d=0; d<5000; d++) { // to all swap file sectors
// FAT32_Dev_Write_Sector(swapStartSc + d, buf); // write buffer content
// FAT32_Dev_Write_Sector(swapStartSc, buf); // write buffer content
//}
}
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Logando");
status=FAT32_Exists(posi.nomearquivo);
if (status==0) { //if the file doesn't exist write a new file
fhandle = FAT32_Open(posi.nomearquivo, FILE_WRITE);
FAT32_Write(fhandle, posi.lat1, 16);
FAT32_Write(fhandle, posi.lon1, 17);
FAT32_Write(fhandle, posi.date1, 14);
FAT32_Write(fhandle, posi.hora1, 14);
FAT32_Close(fhandle);
//i=0;
//while (fhandle != 0 || i<5) {
// FAT32_Close(fhandle);
// Delay_ms(10);
// i++;
//}
}
i=0;
while (storm.ret[i]!=0) {
i++;
}
fhandle = FAT32_Open(posi.nomearquivo, FILE_APPEND);
FAT32_Write(fhandle, storm.ret, i+2);
FAT32_Close(fhandle);
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1,posi.lat1); //display latitude
Lcd_Out(2,1,posi.lon1); //display longitude
Re: FAT32 library for MMC/SD cards
am using dspic33fj128mc202 at 79.2275 Mhz and this is my mmc initialization
Code: Select all
mmcinit();
do {
Spi1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_64,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
Delay_ms(20);
i=FAT32_init();
inttostr(i,ed);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,4,"MMC Found ?");
if (i == 0) {
Lcd_Out(2,2,ed);
Lcd_Out(2,9,"YES !");
Delay_ms(1000);
}
else if (i == 1) {
Lcd_Out(2,2,ed);
Lcd_Out(2,9,"No FAT");
Delay_ms(1000);
}
}while (i != 0);
Spi1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_16,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_HIGH, _SPI_ACTIVE_2_IDLE);
Re: FAT32 library for MMC/SD cards
I'm not sure if I'm following all the details correctly, but how frequently are are you writing to the SD card? How many total writes are there? From what I understand, a given sector of these cards can be written to a maximum of 10,000 - 100,000 times depending on the quality of the card (the better name brands like Kingston are closer to 100,000). If your application exceeds the maximum writes, the sector will fail permanently.
The reason why swap files are recommended is that they allow you to buffer the data and minimize the writes to a sector. If this is your problem, keeping a RAM buffer until a complete sector is full will fix this.
If it's essential to keep everything in nonvolatile memory, you might want to consider adding a Ramtron FRAM chip to the design, and buffer the files in it. They're good for 10^14 writes. I've used them on several projects, and the I2C and SPI ones are exact drop-in replacements for eeproms. This way, you can write each sector only once.
The reason why swap files are recommended is that they allow you to buffer the data and minimize the writes to a sector. If this is your problem, keeping a RAM buffer until a complete sector is full will fix this.
If it's essential to keep everything in nonvolatile memory, you might want to consider adding a Ramtron FRAM chip to the design, and buffer the files in it. They're good for 10^14 writes. I've used them on several projects, and the I2C and SPI ones are exact drop-in replacements for eeproms. This way, you can write each sector only once.
If you know what you're doing, you're not learning anything.
Re: FAT32 library for MMC/SD cards
Thx for helping me, but thinking about that I changed a bit my code and now I use only one buffer[1024] and save on the end of the routine, this is done in each 2 or 3 seconds it saves about 1,5Kb max. of data. But again after 20 ~ 25 min of operation the hardware stuck and all data erased (fat32 is damaged). Any hints ? I changed the SD to another one and slowed down the SPI write speed, but no changes in the FAT problem at all . (sorry for my poor english)
My new code.
posi=gprmc(); // capta dados do gps (lat,lon,data,hora)
for (i=0; i<801; i++) { storm.ret = 0; } // Cleans buffer ... Limpar buffer da leitura anterior
for (i=0; i<1024; i++) { buf = 0; } // Cleans buffer ... Limpar buffer da leitura anterior
storm=stormlogger();
i=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Logando");
d=0;
status=FAT32_Exists(posi.nomearquivo);
if (status==0) { //if file does not exist save lat/lon data
strcat(buf,posi.lat1);
strcat(buf,posi.lon1);
strcat(buf,posi.date1);
strcat(buf,posi.hora1);
}
strcat(buf,storm.ret);
i=0;
while (buf!=0) { i++; }
fhandle = FAT32_Open(posi.nomearquivo, FILE_APPEND);
FAT32_Write(fhandle, buf, i+2);
FAT32_Close(fhandle);
[/code]
My new code.
posi=gprmc(); // capta dados do gps (lat,lon,data,hora)
for (i=0; i<801; i++) { storm.ret = 0; } // Cleans buffer ... Limpar buffer da leitura anterior
for (i=0; i<1024; i++) { buf = 0; } // Cleans buffer ... Limpar buffer da leitura anterior
storm=stormlogger();
i=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Logando");
d=0;
status=FAT32_Exists(posi.nomearquivo);
if (status==0) { //if file does not exist save lat/lon data
strcat(buf,posi.lat1);
strcat(buf,posi.lon1);
strcat(buf,posi.date1);
strcat(buf,posi.hora1);
}
strcat(buf,storm.ret);
i=0;
while (buf!=0) { i++; }
fhandle = FAT32_Open(posi.nomearquivo, FILE_APPEND);
FAT32_Write(fhandle, buf, i+2);
FAT32_Close(fhandle);
[/code]
Re: FAT32 library for MMC/SD cards
I think that the original author of the FAT32 is Dany, and he wrote it in Pascal. You might be able to get his attention on the Pascal forum, or if you look there for the very long thread (something like "pic website"), you can find a link to his website. He might have some insight into what might be the problem.
The other thing that you might do is download the Pascal source code, and see what's actually happening inside the library. It's a very large library, though.
The other thing that you might do is download the Pascal source code, and see what's actually happening inside the library. It's a very large library, though.
If you know what you're doing, you're not learning anything.
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: FAT32 library for MMC/SD cards
Hello,
From the code snippet I really can not see what could be the cause of the problem.
First thing that comes to me is that writing to some buffer can exceed it's size and thus you can overwrite random variables in RAM.
This can cause unpredicted behavior.
As LGR said, you can use swap file to save time. Writing to swap reduces writes, since you do not update FAT table.
When you do FAT32_MakeSwap, you will get start sector of your swap file. And now you can write/read to these sectors with MMC routines without damaging FAT system.
Best regards.
From the code snippet I really can not see what could be the cause of the problem.
First thing that comes to me is that writing to some buffer can exceed it's size and thus you can overwrite random variables in RAM.
This can cause unpredicted behavior.
As LGR said, you can use swap file to save time. Writing to swap reduces writes, since you do not update FAT table.
When you do FAT32_MakeSwap, you will get start sector of your swap file. And now you can write/read to these sectors with MMC routines without damaging FAT system.
Best regards.
Re: FAT32 library for MMC/SD cards
Thanks for the reply and for helping me,
My buffer size is 1024 (FAT32 formatted in 1024 bytes per sector) and the max usage of the buffer is 862 positions, everytime I use the buffer the program fill it with zeros, I'll try to find something in the others sub routines that could be causing this and to be sure I will revert my code for FAT 16 and try running to see if the problem happens again.
I noticed that before the hardware stuck it resets itself for 3 or 4 times and then finally stuck.
My buffer size is 1024 (FAT32 formatted in 1024 bytes per sector) and the max usage of the buffer is 862 positions, everytime I use the buffer the program fill it with zeros, I'll try to find something in the others sub routines that could be causing this and to be sure I will revert my code for FAT 16 and try running to see if the problem happens again.
I noticed that before the hardware stuck it resets itself for 3 or 4 times and then finally stuck.
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: FAT32 library for MMC/SD cards
Hello,
This is strange behavior and it will need further inspection.
If you can locate a exact place of reset or freeze it would be helpful.
But without your entire project and explanation how to reproduce it, I can not be sure what could be cause of this.
Best regards.
This is strange behavior and it will need further inspection.
If you can locate a exact place of reset or freeze it would be helpful.
But without your entire project and explanation how to reproduce it, I can not be sure what could be cause of this.
Best regards.