Jump to content
43oh

newbie question! how do I use UARTprintf with floats?


Recommended Posts

Silly question here. Is the UART *that* different between the Stellaris LP, and the MSP430 LP ? I own at least one of each, but have been spending all of my time with the MSP430 LP thus far.

 

Point of contention though. sprintf() pulls in around 2k overhead, at least on the MSP430 LP, So i would expect that to be the same for the Stellaris LP. Granted, there is much more code space available on the Stellaris. A lean and mean printf() implementation *could* come in at around 400 bytes in size on the target, with just a few calls. WIth float printing capabilities, maybe 700-800 bytes, with one or two floats calls. Just rough gestimates on my behalf here obviously, since I have no hands on with this platform yet.

 

Either way, if "we" have access to the TXBUF on the Stellaris LP UART, much like that on the MSP430 LP, it should be fairly trivial to use something that already exists for the MSP430 LP. Modified of course.

Link to post
Share on other sites

Not that different.. in the end it is all just registers. sprintf makes it very easy, especially if you are playing around with floats and string manipulations.

printf into a buffer and UARTprintf the buffer out.

 

Yeah for my reflow oven controller code on the MSP430 forums i used sprintf() for "formatting" and number printing.  The formatting part was largely to keep multiple print statements out of my code. Plus the fact that you can then use something like %3i,  to help keep variables where they belong, and display formatted pretty( in my case here this was for an LCD screen ).

 

So cool, thanks for the reply BlueHash, stuff like this is always good to know.

Link to post
Share on other sites

Thank you for your help bluehash

 

Here is what I am using to get print the float value using UARTPrintf:

 

 

float Rx,Xd;
void main()
{
          setup();
          initialize();
          get_data();
          Rx = Xd/3;
          UARTprintf("Rx : %f    ",Rx);
}
//I've edited the printf option to the "full" in properties.
// and also have edited stack size. It is 4096 in present
// I am getting " Rx : ERROR " in output screen of putty (without quotes)

 

 

I've used sprintf so many times in keil and in other compilers...

I prefer it the most for this kind of cases.

But unfortunately I am not able to use it in ccs!

may be I am not able to see my mistake!

Can you please check that also :

 

#include<string.h>
#include<stdio.h>
float Rx,Xd;
char str[200];

void main()
{
          setup();
          initialize();
          get_data();
          Rx = Xd/3;

          sprintf(str,"%f",Rx);
          UARTprintf("Rx : %s    ",str);
}
// In output I am getting nothing.
// In ccs - in debug mode, I've found that it is getting problem while implementing "MAP_UARTCharPut(g_ulBase, pcBuf[uIdx]);"
// In memory map window I am getting some thing like below:
// 48896980:    Memory map prevented reading of target memory at 0x48896980 [code=0x20000]
// After this I've define UART_BUFFERED and have implemented it again but I still getting the same result!
 

 

Thank you so much for your time and guidance.

Link to post
Share on other sites

Ok,.. I just went ahead and created an example. See below.

attachicon.gifstellarisLaunchpad_floatingPoint_sprintf_usage.JPG

 

attachicon.gifsprintfTest.zip

 

Hmmm

 

You got another board than i have ...

My board wouldn't print those floats if all there is in main is : return(0)  ;)

 

Ohh and return(0) in main() on an OS-less mcu wouldn't be my "first choice" unless i loved "HaraKiri" or some other nastyness B)

 

/Bingo

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...