Jump to content
Sign in to follow this  
Terenceang

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.

Share this post


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.

Share this post


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.

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×