PHOTO 1. It may be ugly, but it works. You can have
one of these too. Just specify Mouser part number
517-2908-05WB-MG and get out that fine-tipped
soldering iron.
Now that we have an open file that we can write to,
let’s put something in it:
char sendBuffer[14] = “SERVO Magazine”;
// Write 14 1-byte objects from sendBuffer
// into the file
FSfwrite ((void *)sendBuffer, 1, 14, pointer);
We’re done writing to the file. So, let’s close it:
// Close the file
FSfclose (pointer);
That file we just created and loaded with data would
be useless if we couldn’t read it:
char receiveBuffer[50];
// Open file in read mode
pointer = FSfopenpgm (“FILE1.TXT”, “r”);
Let’s only read five characters from our file:
// Read five bytes only
FSfread (receiveBuffer, 5, 1, pointer);
WORD time; //last update time
WORD date; //last update date
char name[FILE_NAME_SIZE]; //file name
WORD entry; //position of file’s
//directory entry
//file structure checksum
//file attributes
//base cluster of the
//file’s directory
DWORD dirccls; //current cluster of the
//file’s directory
WORD chk;
WORD attributes;
DWORD dirclus;
Our receiveBuffer now contains “SERVO.” We know
that we have not reached the end of the file as “Magazine”
still remains to be read. There will be times when it is
important to know if the end of file position has been
reached. We can easily determine if the end of file has
been reached using this memory disk drive file system API
call:
if (FSfeof (pointer))
{
} FSFILE;
//we are at end of file
}
This file system can also manipulate directories just as
easily as it handles files. You can get the full monty on its
file system API calls by downloading
the Application Libraries package and
accessing the Windows Help files,
which are part of the download
package. The Application Libraries
download also includes example code
to assist you in writing your own
PHOTO 2. I suggest getting one of
these if you want to get a feel of the
OLED display and the MicroSD card
without having to solder and write
code.
62 SERVO 10.2010