I am working on an application where I have to write the data captured from a pulser to SD card.
The data format includes header (26 bytes) followed by data itself.
I am using the FatFs library to write it.
The data that I am getting is uint8_t type.
The format of the header is as below:
Version: 4 digits 4 Bytes
Payload Size: 0-65535 2 Bytes
HW Version: 4 digits 4 Bytes
Time Code: 4 digits 4 Bytes
Vector ID: 0-65535 2 Bytes
Up Vector Length: 0-65535 2 Bytes
Up Sample Freq: 0-16777215 3 Bytes
Dn Vector Length: 0-65535 2 Bytes
Dn Sample Freq: 0-16777215 3 Bytes
Up Vector Data 4096 bytes Up Vector Length Bytes
Dn Vector Data 6656 Down Vector Length Bytes
The overall file size needs to be around 10 KB based on above table.
However, the size spikes up to around 14 - 15 KB.
Providing example as below:
Version: 1,9,1,0 4 Bytes
Payload Size: 10754 2 Bytes
HW Version: 2,2,0,0 4 Bytes
Time Code: 0x5C40E21C 4 Bytes
Vector ID: 1 2 Bytes
Up Vector Length: 4097 2 Bytes
Up Sample Freq: 8333333 3 Bytes
Dn Vector Length: 6657 2 Bytes
Dn Sample Freq: 8333333 3 Bytes
Up Vector Data Data Up Vector Length Bytes
Dn Vector Data Data Down Vector Length Bytes
If I use the standard f_printf or f_write option both of them writes either the value as individual bytes for a given value as if it is written as ascii code or does not write as decimal but ascii value.
For example 10754 is either written as 1 0 7 5 4 as if they were individual numbers instead of 2A02 (hex equivalent of 10754). In the buffer of the file it is writing the number 10754 on each index rather than having 2A followed by 02 as they are 8 bit value.
Thank you for the reply.
I am attaching the piece of code that I am trying to use to write the data to the SD card file.temp.c
Also I am attaching the file that I get by using this code.V0000002.TXT
If you see the header part itself what I am expecting in the file is as below:
But what I get is as below:
This are FatFs Generic FAT Filesystem Module functions and it is third party library.
If I get it right you wont to write the data binary, not human readable ASCII text. You can do that this way:
write_ptr = fopen("test.bin","wb"); // w for write, b for binary
fwrite(buffer,sizeof(buffer),1,write_ptr); // write 10 bytes from our buffer
Printf will always transform binary data into human readable ASCII text.
thank you solderdot,
I will try with the suggestion that you provided.
Please note that my code snippet is correct for standarc-C libraries. Maybe your 3rd party lib works differently. However, search your lib for services allowing you to write *binary* data.
From your tables you attached to other posts it is clearly visible that this is what you want, but what you get is ASCII-hex format, i.e. instead of one byte having the value 0x2A you get a string of 2 bytes "2A".
Yes you are correct Solderdot in saying "instead of one byte having value 0x2A I get string of 2 bytes "2A".
The 3rd party FatFs library is the one that is used by msp432 to write on the SD card.
Let me search for the services allowing to write "binary" data.
This should work for most architectures. You also did not specify the MPU chip. Some older ones require a uint16_t as a long.
uint16_t val = 0x2A02;
printf( "val = %04x\n", val );
Try first with printf(). Then make sure your fd is good, and change to fprintf(). I am suspicious about your f_printf() - is that the actual call, or is it a typo on your part? If f_printf(), you may be using a non-standard library.
Thank you for the reply.
I am using MSP432P401R chip from Texas instrument.
f_printf is FatFs library function and it is third party library for Generic FAT FileSystem Module.
I will try with what you have mentioned.
With my way what I get is as below:
But what I am expecting to get is as below:
Attaching the file that I got using the way I wrote.
Hope this clarifies my problemV0000002.TXT