sprintf(cmdBuf,”size
microsd%1d.csv\r”,fileNum);
sendStrUart2(cmdBuf);
//wait for card to respond to
//read - about 18mS
i 0;
timeoutms 5000;
do{
if(CharInQueue2())
{
rxBufProg[i++]
recvchar2();
}
tdelayms(1);
}while(timeoutms— && (rxBufProg
[i-1]
‘>’));
i 0;
j 0;
do{
if(isspace(rxBufProg[j]))
{
++j;
}
}while(isspace(rxBufProg[j]));
■ Screenshot 7. I have set a breakpoint just before the atoi function
is called. In the Variables window, you can see how the raw file size
information is returned by the OpenLog firmware.
//***********************************************
// MAIN
//***********************************************
int main (void)
{
BYTE bitein;
init();
newFile(1);
listFile();
writeFile(1);
readFile(1);
listFile();
do{
bluLED Tog;
tdelayms(250);
}while(1);
do{
sizeBuf[i++] rxBufProg[j++];
}while(rxBufProg[j-1] 0x0D &&
rxBufProg[j-1] 0x0A);
sizeBuf[i-1] 0x00;
fileSize atoi(sizeBuf);
return(fileSize);
I had a blast writing this code. I hope you will find it
useful. You can get the complete source library via
download from the article link. NV
File size is returned as a set of ASCII characters
surrounded by carriage return/line feed combinations.
Carriage returns and line feeds are considered white space
characters. The getFileSize function wades through the
white space characters using the isspace function until an
ASCII character is encountered. The ASCII characters that
make up the file size data are moved to sizeBuf and a null
character is appended.
The file size is obtained by performing an ASCII to
Integer conversion using the atoi function. In Screenshot
7, I set a breakpoint prior to the atoi function call to
capture the raw buffered file size data returned by the
OpenLog firmware.
Exit Function
Yep. There’s code for that. The resultant main function
we used to read and write to the microSD card looks like
this:
October 2015 75