f_write for integers or wchar_t on stm32

Status
Not open for further replies.

Thread Starter

Engineering_Junkie

Joined Sep 9, 2015
41
Hey everyone,

I have the following function, part of elm-chan's FATFS library:


FRESULT f_write (
FIL* fp, /* Pointer to the file object */
const void* buff, /* Pointer to the data to be written */
UINT btw, /* Number of bytes to write */
UINT* bw /* Pointer to number of bytes written */
)

Problem is that to get readable data I need to make sure the data I'm passing to const void* buff is a character, otherwise I'll get junk out passing it an int, etc.

So I work with 16 bit unsigned integers and I'll have about 192 of these before I write them to the file. Issue is converting them to char is very processor intensive and going from 16 bit down to 8 bit is a mission. I tried using wchar_t although it seems to work perfectly within the code, but as soon as I write to the file, I get junk again.

Example:

uint16_t aDST_Buffer= 1100;
wchar_t hj;
hj =(wchar_t)aDST_Buffer; //This gives me hj = 1100
res1 = f_write(&SDFile, hj, sizeof(hj), (void *)&wbytes); // This produces a large amount of junk.

Is there anyway around this? Any 16 bit character datatypes or ways to write integers via f_write for readable data?
 
Status
Not open for further replies.
Top