Success with FAT library !

I’ve been dabbling off and on with the Elm-Chan FatFS library.  I was having a lot of issues customizing it for this project because I am an assembly language programmer and sometimes “C” code can be a bit baffling and frustrating for me to figure out … especially when it’s some one else’s code.

I made an acquaintance with an astute “C” programmer I met through the  RC-2014 google group.  He agreed to look at the code and get it running as a library.  He has some prior commitments, so there will be a delay in progress, which is fine as I am still awaiting the arrival of the PCB’s for this project.

I had previously investigated Roland Riegel’s “sd-reader” code.  His code supports multiple AVR targets and I was able to get it to compile,  upload and functions in my ATmega328p SDmem card test board.  However, I abandoned his code because I was not able to get the “write” file function in his demo to work.  The issue seemed to be writing to the SDmem card.  When attempting to write to a file (that did not exist) using the demo,  the command aborted with an “error opening file [file name]” message.  I checked the accompanying FAQ for the project, set the proper #define  for the “Card Detect” and “Write Protect” MACROs and still no joy.

In my desire to learn as I go, I took another stab at Roland Riegel’s “sd-reader” code.  I performed another web search for others that were using his code and all of them seemed to have great results with it.  So why then was I unable to get it to function as expected?  In one of the search hits, I found a YOUTUBE video of someone that was able to get it to work with an ATmega644p.  I figured why not watch it?  It started out with wiring, etc., so I skipped to the end where he uses Roland’s demo to perform the various SDmem card functions.  What I saw revealed to me my error in thinking.  He used the “touch” command to FIRST create the file to write to THEN he was able to successfully write to the file.   I tried that on my test setup and as was now expected, it worked.  Hmm … I had mistakenly thought that the “write” function would create the file to write to if it was not found.

After a few more hours of tailoring the code to my needs, I was able to get it to compile as a simple library module, complete with section relocation and extraction of the data structures in RAM and the entry points (API’s) of each of the functions.  Now it is time to document the specific register loads that I will need to perform when call the  API’s.

There is limited support for a real-time clock in the “sd-reader” library.  Since the Z80 project will use a DS3231, I’ll need to figure out how to get that linked in for file date and time stamping.  I have found a few “C” libraries but am focusing on one in particular.  As of yet, I have no DS3231 to work with but they should arrive in less than a week, with a little luck.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s