ASCII characters. Screenshot 5 shows what happens when
a hexadecimal 1 (0x01) is substituted for the D character
in our A,B,C,D data packet. The OpenLog firmware prints
a period (0x2E) for nonprintable ASCII characters. This
means we can’t store and recall
hexadecimal numbers from the microSD
card correctly. So, how do we code a
read function that allows us to store
ASCII characters and hexadecimal
values? Like this:
//********************************
//* READ File
//********************************
void readFile(BYTE fileNum)
{
char cmdBuf[32];
WORD timeoutms;
WORD i;
WORD fileSize;
BYTE bitein;
■ Screenshot 5. I substituted a hexadecimal 1 (0x01) for the D character in
our A,B,C,D data packet. As you can see, a period printed as 0x01 is a control
character and not a printable character.
fileSize getFileSize
(fileNum);
(rxBufAtmel) after it is sent to the FTDI USB portal.
Check out Screenshot 4. Our MICROSD1.CSV is
initially empty. Then, we write seven bytes to the file
(A,B,C,D). The next operation is a read and we see those
results printed in Screenshot 4. Finally, another list file
command is executed and we see the MICROSD1.CSV
file size is nine bytes. If you take a look at the highlighted
hex dump in Screenshot 4, you will see that a carriage
return character and a line feed character have been
appended to the file data by the OpenLog firmware.
This is all great if we only need to store printable
memset(rxBufProg,0x00,
sizeof(rxBufProg));
//send read command
sprintf(cmdBuf,”read
microsd%1d.csv 0 %u
3\r”,fileNum,fileSize);
sendStrUart2(cmdBuf);
//wait for card to respond to
//read - about 18mS
i 0;
timeoutms 5000;
do{
if(CharInQueue2())
{
bitein recvchar2();
sendBiteUart1(bitein);
rxBufProg[i++] bitein;
}
tdelayms(1);
}while(timeoutms— && (rxBufProg[i-1]
‘>’));
}
The file read results in Screenshot 6 verify our
updated readFile function. The read
command syntax has drastically changed
here. We have instructed the OpenLog
firmware to read from file position 0 in
raw mode.
To be able to enter the raw
argument ( 3), we must provide a file size.
And yes, there’s code for that:
//********************************
//* GET FILE SIZE
//********************************
WORD getFileSize(BYTE fileNum)
{
char cmdBuf[32];
WORD timeoutms;
WORD i,j;
WORD fileSize;
char sizeBuf[8];
■ Screenshot 6. Now that is a REAL read function. We can now store and
recall ASCII and hexadecimal characters. Note that the hexadecimal 1 is
represented correctly in the highlighted hex dump area of this shot.
memset(sizeBuf,0x00,
sizeof(sizeBuf));
//send size command
74 October 2015