SD Card FAT16 read problem on PC

Hi All,

I have been trying to create open a .TXT file on my 32MB Sandisk SD card using Olimex STR-P711 development board.Finally I have managed this using FAT16 but I have another problem.I can open/read/create a .TXT file but when I write into it, I cannot see what I have written into the file when I put it on my PC.It shows an EMPTY .TXT file and nothing written into it.Does anyone have an idea why could this be?

Thank you…

Regards,

P.S: I checked the buffer I am trying to write and it is not empty and after I create the file,I try to read it and it shows what I have written already.So I can write but my pc doesn’t show.

When the file is created it has zero length and when the file is closed this is updated to the correct length. Depending on the code it may or may not be updated while writing data to the file.

If the file length is never changed it will stay at zero.

Did you call the file close routine?

UhClem:
When the file is created it has zero length and when the file is closed this is updated to the correct length. Depending on the code it may or may not be updated while writing data to the file.

If the file length is never changed it will stay at zero.

Did you call the file close routine?

Hi David,

First of all,thank you for your reply :slight_smile:

Yes I call file close routine and it shows the time stamp.I mean I am updating the time stamp in file close routine.When I check it on my PC,I see the time stamp and it is the time stamp in the file close routine,so no probem with the time stamp and I also update the file size,directory.But it still shows “0 KByte” and nothing in the .TXT file :cry:

When I create a .TXT file on my PC and write “1 2 3 4 5” in it,I can read it from the development board using fat read routine.When I create a .TXT file on development board, I call write routine and try to write the same thing “1 2 3 4 5” then I close the file.After that I call file read routine and read what I have written “1 2 3 4 5” but my PC cannot show it.Do you think I am writing to a wrong address and read from the same wrong address? or can you give me some tips for this problem? :frowning:

Thank you all,

Best regards.

shadow-c:
or can you give me some tips for this problem? :frowning:

I just spent a lot of time debugging my take on FAT16 code and I used a number of techniques to track down problems. My biggest limitation was using the logomatic hardware without a JTAG interface so I was limited to inserting a printf statement in various locations.

But I also used the Unix program “od” (octal dump) to examine the raw contents of the flash memory card. This way I could see if things were the way I thought they should be. I also used the “dd” program as a quick and dirty way to fill space with zeros so I could see when they changed. The nice thing with Unix/Linux is that I could use dd to either create a file or write directly to the flash card prior to creating a clean file system on it. That is how I discovered that my old flash card reader was confused by a newer SD card.

Using od (or a Windows equivalent if you have to) you can see if the data is actually written to the file, the FAT table gets updated, and the directory entry is correct. If not, that should give you a hint on where to look for trouble.

UhClem:

shadow-c:
or can you give me some tips for this problem? :frowning:

I just spent a lot of time debugging my take on FAT16 code and I used a number of techniques to track down problems. My biggest limitation was using the logomatic hardware without a JTAG interface so I was limited to inserting a printf statement in various locations.

But I also used the Unix program “od” (octal dump) to examine the raw contents of the flash memory card. This way I could see if things were the way I thought they should be. I also used the “dd” program as a quick and dirty way to fill space with zeros so I could see when they changed. The nice thing with Unix/Linux is that I could use dd to either create a file or write directly to the flash card prior to creating a clean file system on it. That is how I discovered that my old flash card reader was confused by a newer SD card.

Using od (or a Windows equivalent if you have to) you can see if the data is actually written to the file, the FAT table gets updated, and the directory entry is correct. If not, that should give you a hint on where to look for trouble.

Hi David,

I really thank you for you response and help.I used a hex editor and checked if I really write to the SD card.I am now pretty much sure that I am writing to SD card correctly.I can create a .TXT file and write in it.To be sure,I created a .TXT file on my PC and write something in it.Then I checked the sectors and addresses,write down them on a paper.After that, I do the same procedure on my development board (create a .TXT file, write in it and check using hex editor).And guess what? My development board does the same thing as my PC.I mean they both write the same sectors and addresses and the same things.So I think the problem is that I can NOT update the FAT table in some way.That is why,even if I write to the correct address or sectors, my computer shows nothing in it with 0 Kb.when I checked the time stamp,it shows the time that I created the .TXT file NOT the time I modified or write in it.create date is correct but I can not update modified date I guess :frowning:

I checked that I am writing the modified date correctly in file close routine but maybe the address where I write the update information is wrong.

So David,can you please help me or guide me to solve this problem? How can I update the file? For example when you create a file,where is the time stamp,file size information is written?

Thank you for your response and kindness.

Hope you have a nice day,

Thank you…

Hi All,

I have solved my problem :smiley: I wasn’t able to update the directory table because my parameters were changed in a way that I don’t understand.I defined the parameters as static but they are changed in some way without my permission :? After I call the read sector routine, the parameters are changed but I don’t changed them or use them in read sector routine,funny.I haven’t figured out the reason but I applied a simple solution.Before I call read sector routine,I save the parameters in a buffer and then after I call read sector routine, I reload them :slight_smile:

So now, I can write and read my .TXT file both on my PC and development board.

Thank you for your help and hints David,

Good luck

Regards