problem writting 2d arrays into SD card

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem writting 2d arrays into SD card

Jump to solution
1,086 Views
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

Labels (1)
0 Kudos
1 Solution
982 Views
BlackNight
NXP Employee
NXP Employee

Change

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

to

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

View solution in original post

0 Kudos
8 Replies
982 Views
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 Kudos
982 Views
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 Kudos
982 Views
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 Kudos
981 Views
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 Kudos
982 Views
BlackNight
NXP Employee
NXP Employee

So is fs really of type FIL?

0 Kudos
982 Views
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 Kudos
983 Views
BlackNight
NXP Employee
NXP Employee

Change

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

to

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

0 Kudos
982 Views
arunkumar1989
Contributor I

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

Thanks a lot.

AK

0 Kudos