FATFS question, double printf()??

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello AVR Freaks,
I had a question for you all, any guidance is greatly appreciated.

I'm currently working on a project which uses, form among other things, an SD Card and an LCD Display.

The SD Card will serve as a data loger and the LCD as a normal display. I am using Chan's FATFS library to manage pretty much all the SD card related FAT interface.
The problemm is that, unless I'm mistaken, there is no function that allows me to store a variable value in the SD card, I'm trying to use:

f_printf("My value is: @2i", value[0]);

But whenever I read the file I don't see the actual value stored in my array element I just see

My value is:

and neither f_write(); or f_puts(); accept those kinks of parameters.

So what I was thinking of doing is using the stdio.h function printf(); and do the transmit routine to printf the characters into the SD card:

static int sd_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);

static int sd_putchar(char c, FILE *stream){
f_putc(c, &fileobjt);
return 0;
}

The problem is that I'm already using that same printf funtion to transmit to the LCD... so my question is:

Is there a way to have kind of two instances of the printf function one to print on the screen and another one to "print" on the SD Card? -This may sound silly but Im not really familiar with the printf function other thaan its basic use-

Edit: Something I forgot to menction is that all my SD functions are on another .c file than my main routine

or it there a way to fix the f_printf() function included in the FATFS library?

Thanks for the suggestions, they are greatly appreciated!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I were you I'd just sprintf() and then f_write() the resultant buffer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello clawson,
Im guessing the sprintf() is part of the stdio.h correct? but I've never used it before,

could you elaborate a little bit?

thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please read this: http://www.nongnu.org/avr-libc/u...

So, sprintf is almost identical to printf. The difference is that printf outputs a string to stdout, while sprintf outputs a string to a buffer that you send as the first parameter.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see I see it all makes sense now, I also found this one out:
http://www.rohitab.com/discuss/t...

the return value Im guessing its the lenght of the buffer correct?

Is there any special "connection" or setup that should be made in order to use sprintf in AVR just like with printf()? or is it just a matter of including the stdio library?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
the return value Im guessing its the lenght of the buffer correct?

Why do you need to guess? Documentation is written for a reason, and I even linked to it.. (Your guess is not correct, BTW.)

No special "connection" needed. If you have printf working then you also have sprintf.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are right, I apologize for that, looking closer the answer was under the vfprintf

Quote:
vfprintf returns the number of characters written to stream

Thank you very much for your help Johan and clawson now I feel that I understand alot more, even thought it's just a few, babysteps jeje. I'll try to read that documentation you've attached it should be very usefull if I manage to understand it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In that same manual click the "Example projects" link at the top right and look at the more complex stdio example. It shows how to use multiple streams if you want to explore that avenue, though for the purposes of f_printf I think sprintf is the easy solution.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds great I'll take a look into it. Yes sprintf worked perfectly I wasn't aware that there were different knds of printf functions, thank you very much clawson.
I'll still take a look at the other method just for general knowledge