Page 1 of 1

FAT32 library help

Posted: 17 Apr 2013 17:35
by nand92
Hi all!
I downloaded and installed the FAT32 library from libstock (http://www.libstock.com/projects/view/108/fat32-library)
for dspic, I'm using it on a mikromedia for dspic33 board.

The problem: i can't find any information on the helpfile about using FAT32_FindFirst and FAT32_FindNext functions!
They're just missing from the help index as if they were not existing.

Were can I find an example (or their code implementation) ?
Obviously from the __Lib_FAT32.h header file i can only see their prototipe, that are quite useless to solve my problem.

Thanks to everyone !

Re: FAT32 library help

Posted: 25 Apr 2013 10:19
by srdjan
Hi,
nand92 wrote:Hi all!
I downloaded and installed the FAT32 library from libstock (http://www.libstock.com/projects/view/108/fat32-library)
for dspic, I'm using it on a mikromedia for dspic33 board.

The problem: i can't find any information on the helpfile about using FAT32_FindFirst and FAT32_FindNext functions!
They're just missing from the help index as if they were not existing.

Were can I find an example (or their code implementation) ?
Obviously from the __Lib_FAT32.h header file i can only see their prototipe, that are quite useless to solve my problem.

Thanks to everyone !
Here are the updated help files.
Download appropriate help file, unrar and place into
{COMPILER_INSTALLATION_FOLDER}\Packages\FAT32 Library\help\

Thank you for reporting this issue.

Re: FAT32 library help

Posted: 25 Apr 2013 17:37
by nand92
Hi, thank you for solving my problem!
Help file updating worked perfectly.

Greetings

Re: FAT32 library help

Posted: 12 Jun 2013 09:51
by anders_col
Hello!

I'm trying to install the FAT32 library by using the Package Manager. But the PM download fails each time, it gets interrupted..? Can you provide another link so I can download and install it correctly? I need this to be able to use 4 GB SD cards on a dsPIC33 card... Right now I only have FAT16 library included in my project. Thanks!

Best regards, Anders

Re: FAT32 library help

Posted: 12 Jun 2013 10:46
by srdjan
Hi,
anders_col wrote:Hello!

I'm trying to install the FAT32 library by using the Package Manager. But the PM download fails each time, it gets interrupted..? Can you provide another link so I can download and install it correctly? I need this to be able to use 4 GB SD cards on a dsPIC33 card... Right now I only have FAT16 library included in my project. Thanks!

Best regards, Anders
Just tried the official download link and it went well.
http://www.mikroe.com/downloads/get/127 ... r_v300.zip
Try it again and let me know if it fails for you, I'll see to provide you with new (temporary) download location.

Re: FAT32 library help

Posted: 12 Jun 2013 13:53
by anders_col
Thanks for quick reply!

I've tried using two different PC's and the download link works, but at the end of the download it stops, just a few bytes short of completion. My PC complained that the file was unsecure, so I tried again turning off all firewalls/antivirus. Same result.

However: I downloaded it using my phone instead and then transferred it to my PC. It worked well and now PM and FAT32 lib is installed. What a happy ending.. 8) Thanks again!

Best regards, Anders

Re: FAT32 library help

Posted: 14 Apr 2014 18:34
by BMWTouring
I am using this library and I can write a Directory and make a TXT file. But I cannot write data in the file. What is going on?

Re: FAT32 library help

Posted: 17 Apr 2014 18:10
by dejan.odabasic
Hello,

Please make sure that file is properly closed wring data in it.
Use FAT32_Close(Handle); function.

Also if you encounter troubles with FAT32 library I suggest reading the return value from function and check the error code with FAT32_GetError() function.
Error codes are available in __Lib_FAT32.h file which is available in FAT32 Example folder.

Best regards.

Re: FAT32 library help

Posted: 18 Apr 2014 17:43
by BMWTouring
Look like Topic Hacking?

I allready Closed the file handler, but it does not write any info into the file.

I am posting the code:

Code: Select all

#define BUFFER_SIZE 27
#include "__Lib_FAT32.h"

//Memory Card Chip Select Connection
sfr sbit Mmc_Chip_Select at LATB2_bit; //was RB2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISB2_bit;
//

// Software I2C connections
sbit Soft_I2C_Scl           at RB3_bit;
sbit Soft_I2C_Sda           at RB4_bit;
sbit Soft_I2C_Scl_Direction at TRISB3_bit;
sbit Soft_I2C_Sda_Direction at TRISB4_bit;
// End Software I2C connections

// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_RW at RD1_bit;
sbit LCD_EN at RD2_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

unsigned char filename[] = "TEMP.TXT";
//unsigned char error;
unsigned char i;
unsigned char *WriteBuffer[100];
unsigned int adc_value;
unsigned char Temperature_Log[BUFFER_SIZE];

char seconds, minutes, hours, day, month, year; // Global date/time variables
char prev_minutes=0;
int err;
short fhandle;
__HANDLE fileHandle[4];
__SECTOR sc;
unsigned char BCD2UpperCh(unsigned char bcd)
{
  unsigned char temp;
  temp = bcd >> 4;
  temp = temp | 0x30;
  return(temp);
}
unsigned char BCD2LowerCh(unsigned char bcd)
{
  unsigned char temp;
  temp = bcd & 0x0F; //Making the Upper 4-bits
  temp = temp | 0x30;
  return(temp);
}
unsigned char rtc1307_Read(unsigned char address)
{
  unsigned char temp;
  Soft_I2C_Start();
  Soft_I2C_Write(0xD0);
  Soft_I2C_Write(address);
  Soft_I2C_Start();
  Soft_I2C_Write(0xD1);
  temp = Soft_I2C_Read(0);
  Soft_I2C_Stop();
  return temp;
}

void Display_Time() {

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_FIRST_ROW);
  Lcd_Out(1, 1,"DATE:");      // Prepare and output static text on LCD
  Lcd_Chr(1, 7,BCD2UpperCh(day));
  Lcd_Chr(1, 8,BCD2LowerCh(day));
  Lcd_Chr(1, 9,'/');
  Lcd_Chr(1, 10,BCD2UpperCh(month));
  Lcd_Chr(1,11,BCD2LowerCh(month));
  Lcd_Chr(1,12,'/');
  Lcd_Chr(1,13, BCD2UpperCh(year));
  Lcd_Chr(1,14,BCD2LowerCh(year));

  Lcd_Out(2, 1,"TIME:");
  Lcd_Chr(2, 7,BCD2UpperCh(hours));
  Lcd_Chr(2, 8,BCD2LowerCh(hours));
  Lcd_Chr(2, 9,':');
  Lcd_Chr(2, 10,BCD2UpperCh(minutes));
  Lcd_Chr(2,11,BCD2LowerCh(minutes));
  Lcd_Chr(2,12,':');
  Lcd_Chr(2,13,BCD2UpperCh(seconds));
  Lcd_Chr(2,14,BCD2LowerCh(seconds));
}

void main()
{
  unsigned char ones,tens,hundreds,fractional;
  unsigned int temp;

  TRISD = 0x00;
  Lcd_Init();
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Cmd(_LCD_CLEAR);
  Delay_ms(100);
  Lcd_Out(1,1," TEMP. RECORDER");
  Lcd_Out(2,1,"  EMBEDDED LAB");
  Delay_ms(1000);


  ADCON0 = 0b00000001;    //A/D Converter Power Up
  ADCON1 = 0x0E;
  ADCON2 = 0b10111110;    //Right Justfied and Slowest Clock for better accuracy
  ADC_Init();

  while(err == 1)
  {
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(1,1," CARD NOT FOUND");
    err = MMC_Init();
  }
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1,1," CARD DETECTED!");
  Lcd_Out(2,1,"CARD INITIALIZED");
  Delay_ms(1000);
  SPI1_Init();
  err = FAT32_Init();

  if (FAT32_Exists("SWAP.TXT"))
  {
    Lcd_Out(1,1,"Deleting existing swap file...");
    FAT32_Delete("SWAP.TXT");
    Lcd_Out(2,1,"Done");
  }

  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);

  fileHandle[0]=FAT32_Open("data.txt",FILE_APPEND);//write mode. If will create data.txt if it doesn't exist.
  err = FAT32_Close(fileHandle[0]);
  FAT32_MakeDir("ronde1"); //Dit werkt

  fileHandle[0]=FAT32_Open("data.txt",FILE_APPEND);//write mode. If will create data.txt if it doesn't exist.
  fileHandle[1] = FAT32_MakeSwap("SWAP.TXT", 500, &sc);  // if swap file creation was successful,
  if (fileHandle[0] < 0) while(1);
  err = FAT32_Close(fileHandle[1]);
  err = FAT32_Close(fileHandle[0]);

  while(1)
  {
    adc_value = ADC_Read(0);      //Read Temperature from ADC
    adc_value = adc_value*488;
    adc_value = adc_value/10;
    
    Temperature_Log[0] = 'T';
    Temperature_Log[1] = 'E';
    Temperature_Log[2] = 'M';
    Temperature_Log[3] = 'P';
    Temperature_Log[4] = '=';

    temp = adc_value/100;
    ones = temp%10;
    temp = temp/10;
    tens = temp%10;
    temp = temp/10;
    hundreds = temp%10;

    ones = ones|0x30;
    tens = tens|0x30;
    hundreds = hundreds|0x30;
    Delay_ms(1000);
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(1,1,"TEMPERATURE:");
    Lcd_Chr(2,1,hundreds);
    Lcd_Chr(2,2,tens);
    Lcd_Chr(2,3,ones);
    
    Temperature_Log[5] = hundreds;
    Temperature_Log[6] = tens;
    Temperature_Log[7] = ones;
    Temperature_Log[8] = '.';
    
    adc_value = adc_value/10;
    fractional = adc_value%10;
    fractional |= 0x30;
    Lcd_Chr(2,4,'.');
    Lcd_Chr(2,5,fractional);
    Lcd_Chr(2,6,'C');
    
    Temperature_Log[9] = tens;
    Temperature_Log[10] = ones;
    Temperature_Log[11] = ' ';
    Temperature_Log[12] = 'C';
    Temperature_Log[13] = '\r';
    Temperature_Log[14] = '\n';
    
    FAT32_Dev_Write_Sector(sc++, Temperature_Log);
    fileHandle[0]=FAT32_Open("data.txt",FILE_APPEND);//write mode. If will create data.txt if it doesn't exist.
    FAT32_Write(fileHandle[0],"TL",strlen("TL"));
    FAT32_Close(fileHandle[0]);
    Lcd_Out(2,9,err);
    
    Delay_ms(1000);
  }
}
// Code modified by Admin, comment lines removed for better code clarity

Re: FAT32 library help

Posted: 23 Apr 2014 15:31
by dejan.odabasic
Hello,

Make sure that last this which code executes is FAT32_Close(fileHandle[0]);
Use button or other way to exit while loop after closing the file.
Only then SD card can be safely removed.

Also you should check the return values of FAT32 function calls.
Problem does not have to manifest in first loop pass.

I suggest using a FAT32 example project as a guide for writing your project.

Best regards.

Re: FAT32 library help

Posted: 24 Oct 2014 17:00
by ISL_Dave
The data is written into the file but the FAT is not updated until the correct filehandle is closed. Unfortunately if communication to the card is interrupted (i.e. card removed or power lost), the FAT will be out of date.

Therefore if you open a file, write data and remove the card, the data will be on the card (programs like Winhex can be used to verify the presence of the data) but because the FAT is not updated, Windows or whatever you use will not know the data exists.

This is why dejan is suggesting you ensure the file is closed. Creating a file updates the FAT at the same time which could be why you see the file being created.

Re: FAT32 library help

Posted: 29 Apr 2021 18:24
by f0karami
hello
I need the address of the start sector of a file in sd memory but can not find a function for it
In the Fat16 library, the "Mmc_Get_File_Write_Sector()" function did this but in fat32 library i am not found any function this work
please help me
thank you