Hey guys,
I am having some problem writing 2D arrays into SD card.
Please consider the following example:
[code]
int16 Ringbuf[5][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8}};
FAT1_f_printf(&fs,"%d,",Ringbuf[0,0); //random garbage is being written to file here.
[/code]
Any idea why this is happening?
I am using MK60MOVLQF15 CPU
Thanks,
Arun
解決済! 解決策の投稿を見る。
Hi Arun,
I think I have not really used that printf() function.
printf() uses a lot of stack, make sure you have plenty stack space allocated.
Then, %d is for integer, probably 32bit on your microcontroller.
Use %hd instead (see printf - C++ Reference ).
Maybe this explains what is happening.
I hope this helps,
Erich
no luck so far ,single dimensional arrays are working correctly,my problem is with 2D arrays,the manual also has no examples with 2D examples are given,is there any way around this?
if the array is one or two (or more) dimensional, really should not matter.
Anway, what you have pasted will not compile anyway, I think you wanted to have this:
FAT1_f_printf(&fs,"%d,",Ringbuf[0][0]); //random garbage is being written to file here.
The other thing to check: is your code warning-free?
Make sure you have included "Fat1.h" before using any function of it, especially functions with open argument lists.
Erich
The warning at that line is this:
Description Resource Path Location Type
left-hand operand of comma expression has no effect [-Wunused-value] passing argument 1 of 'f_printf' from incompatible pointer type [enabled by default] sdcard.c /sdcard_150_v2/Sources line 55 C/C++ Problem
So is fs really of type FIL?
Change
FAT1_f_printf(&fs,"%d,",Ring[0,1]);
to
FAT1_f_printf(&fs,"%hd,",Ring[0][1]);
Yes ,a silly typo from me ,thanks that did the trick.
Thanks a lot.
AK