problem writting 2d arrays into SD card

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

problem writting 2d arrays into SD card

ソリューションへジャンプ
1,208件の閲覧回数
arunkumar1989
Contributor I

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

ラベル(1)
0 件の賞賛
返信
1 解決策
1,104件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Change

FAT1_f_printf(&fs,"%d,",Ring[0,1]);

to

FAT1_f_printf(&fs,"%hd,",Ring[0][1]);

元の投稿で解決策を見る

0 件の賞賛
返信
8 返答(返信)
1,104件の閲覧回数
BlackNight
NXP Employee
NXP Employee

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

0 件の賞賛
返信
1,104件の閲覧回数
arunkumar1989
Contributor I

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?

FatFs - f_printf

0 件の賞賛
返信
1,104件の閲覧回数
BlackNight
NXP Employee
NXP Employee

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

0 件の賞賛
返信
1,103件の閲覧回数
arunkumar1989
Contributor I

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

0 件の賞賛
返信
1,104件の閲覧回数
BlackNight
NXP Employee
NXP Employee

So is fs really of type FIL?

0 件の賞賛
返信
1,104件の閲覧回数
arunkumar1989
Contributor I

Yes sir it is.

I am attaching the .c file for your reference.

This is what i am getting in the file:

536805384,

0 件の賞賛
返信
1,105件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Change

FAT1_f_printf(&fs,"%d,",Ring[0,1]);

to

FAT1_f_printf(&fs,"%hd,",Ring[0][1]);

0 件の賞賛
返信
1,104件の閲覧回数
arunkumar1989
Contributor I

Yes ,a silly typo from me ,thanks that did the trick.

Thanks a lot.

AK

0 件の賞賛
返信