This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Float format using usnprintf function

Other Parts Discussed in Thread: EK-TM4C1294XL

Hi, I'm working with the EK-TM4C1294XL LaunchPad. I'm sensing a voltage level stored in a global variable called tension and I want to show the value in a webpage (local network). The enet-lwip example, works with a function called  usnprintf. I have read that this function doesn't support floating point format. When I try to use it, the function shows a value like "2706" in the webpage, but the original value is "1.672697", as you can see in the next image:

I wanted to know if there's a way to send my variable directly in float format to the webpage. Or which way do you suggest my to qork with this issue.

Thanks, MARTIN

  • Hi,

    You may use:

    #include <stdio.h>

    and then call usual sprintf/snprintf function(s). Take care this need extra ~2K stack.

    Petrei

  • Thanks for the help Petrei, but my troubles still go on.

    I have include the stdio.h header and implemented the sprintf function as you see in the image:

    I have a warning related to the implementation of the sprintf function, but I googled and I think it is correct. In despite of this I don't have errors so the project compiled succesfully.

    I took the caution of expand 2 extra K of stack memory: (there were 2048 K by default in the original enet_lwip project)

    Finally when I run my website, it goes down throughing errors like this: (red circled)

    The error anulles the script routine that shows the data I am measuring, in this case the tension variable show in the first post.

    I hope you can guide in this issue, thank you very much, Regards

    Martin

  • Hi,

    You have a typing error in that format specifier, should be "%-f" as is in documentation:

    format specifier follows this prototype: 
    %[flags][width][.precision][length]specifier 

    You may google for that if not obvious.

    Petrei

  • Thanks at all Petrei, I made it works! an example of the rigth implementation of the function was: sprintf(pcBuf, "%-3.2f%", tension);

     

    Regards, Martin C!

  • Hi Martin,

    It would be useful to other forum users to mark this thread as answered.

    Petrei

  • May I suggest that you,  (click on)  "Verify Answer" icon on each of Petrei's first two posts here?   (one directing an increase in stack size, 2nd noting typo)

    This gives newly arriving readers confidence that your issue (which may be theirs - too) has been well resolved...   (single "Verify" may not prove sufficient to fully/properly guide)

  • Bravo Martin - well done - thank you.

    Your good work has (properly) rewarded poster Petrei - and served as a nice "marker" for all new readers.    C'est tres bien, mon ami...

  • Thanks folk, I'm just starting! Regards

  • Hi Petrei

    Do you have any idea of how to modify the stack size in IAR?

    Regards
  • Usually, you need to edit the *.ICF file (linker configuration file) that the IDE associates with your project. One option (as we / I do it here) is to copy the default one (that IAR-WB chooses for your MCU) to you project path, rename and edit it.

    The ICF file is found in the linker - tab of the project options. Select "Override default", and edit the path/name to you new file.