fat32 library FILE_APPEND question

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
Karamel
Posts: 97
Joined: 23 May 2015 01:00

fat32 library FILE_APPEND question

#1 Post by Karamel » 30 Aug 2015 22:06

Hi,

I would like to make data logger with this library. I tried something about file append but any code didn't work. I have a txt file which name is R.TXT and I call these code every 1 second. I would like to add someting below my txt file but they do not work.

Code: Select all

fileHandle[0] = FAT32_Open("R.TXT", FILE_APPEND);
err = FAT32_Write(fileHandle[0], "x", 1);
how can i do this?

Best Regards,
Karamel :roll:

Karamel
Posts: 97
Joined: 23 May 2015 01:00

Re: fat32 library FILE_APPEND question

#2 Post by Karamel » 01 Sep 2015 09:23

Is there anyone who can tell it me? :roll:

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: fat32 library FILE_APPEND question

#3 Post by aleksa.jovanovic » 02 Sep 2015 15:11

Have you tried without "err=" ?
Just "FAT32_Write(fileHandle[0], "x", 1);" ?

Also did you initialize FAT32?

Best regards,
Aleksa

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: fat32 library FILE_APPEND question

#4 Post by Dany » 02 Sep 2015 20:14

Karamel wrote:I have a txt file which name is R.TXT and I call these code every 1 second. I would like to add someting below my txt file but they do not work.

Code: Select all

fileHandle[0] = FAT32_Open("R.TXT", FILE_APPEND);
err = FAT32_Write(fileHandle[0], "x", 1);
If you call this code every second then you also have to close the file every time, because you (re)open it each second also. Not closing the file can lead to loss of data (as you see happening).
The alternative is opening the fille for appending once, write many times 'X', and close the file once. Failing to close the file can lead to loss of data of course (closing the file updates the FAT for sure).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Karamel
Posts: 97
Joined: 23 May 2015 01:00

Re: fat32 library FILE_APPEND question

#5 Post by Karamel » 02 Sep 2015 23:29

aleksa.jovanovic wrote:Have you tried without "err=" ?
Just "FAT32_Write(fileHandle[0], "x", 1);" ?

Also did you initialize FAT32?

Best regards,
Aleksa
Hi,

Yes I have initialized FAT32. Actually, my problem is that.

default size of my txt file is four. What is the meaning that? for example, "mikr".

when I want to write in side "amazing". it writes but like that "amaz"

when I write my txt file "abcdefg" with my computer and then, microcontroller can write inside "amazing".

library can not append any text to my txt file
it just can change string in txt file :roll:

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: fat32 library FILE_APPEND question

#6 Post by aleksa.jovanovic » 03 Sep 2015 15:20

Could you post the project so I can try it out ?

Best regards,
Aleksa

Karamel
Posts: 97
Joined: 23 May 2015 01:00

Re: fat32 library FILE_APPEND question

#7 Post by Karamel » 03 Sep 2015 15:54

Hi,

thanks for interesting aleksa.

I have added my simple code. it can write like my previous message and it can not append(add) any string to my txt file.

Best Regards,
Karamel :roll:
Attachments
SD_MMC_Demo.rar
(280.1 KiB) Downloaded 356 times

Karamel
Posts: 97
Joined: 23 May 2015 01:00

Re: fat32 library FILE_APPEND question

#8 Post by Karamel » 03 Sep 2015 16:06

I have a txt file which has a 3 letter inside like that. (I had written it with my computer)

Image

and then, I take off my sd card from my computer and I plug it my test board(has stm32f103vet6 microcontroller) it tries to write "amazing" to my tft file.

finally, I take off my card from pcb and I plug it my computer. It looks like that.

Image

microcontroller can not write "amazing" to R.TXT. it just can write 3 letter. Library also can not append any string. :roll:

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: fat32 library FILE_APPEND question

#9 Post by Dany » 03 Sep 2015 17:56

Hi, try to
- use FILE_APPEND in stead of FILE_WRITE
- close the file after writing to it.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Karamel
Posts: 97
Joined: 23 May 2015 01:00

Re: fat32 library FILE_APPEND question

#10 Post by Karamel » 03 Sep 2015 21:23

Thank you so much Dany :)

Now, it works with these codes.

Code: Select all

    err = FAT32_Size("R.TXT", &size);
    FAT32_Seek(fileHandle[0], size);

    FAT32_Write(fileHandle[0], "amazing", 10);
    FAT32_Close(fileHandle[0]);

I would like to do new line before writing "amazing" Such as like that.

amazing
amazing
amazing
.
.
.
.

I tried this FAT32_Write(fileHandle[0], "\namazing", 10); but it didn't work. how can I do it?

Post Reply

Return to “Library Development Discussion”