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.

MSP430F169 and SPRINTF problem with CodeComposer Studio V4

Other Parts Discussed in Thread: MSP430F169, CODECOMPOSER, MSP430F4784, TMS320F28335

To anyonethat might be able to help

Im programing an MSP430F169 Micro using CodeComposer Studio 4.  Pretty much everything works fine until i try to use SPRINTF.  Im using the line below and including the proper include files but with no luck.  Its very strange in that it does partially work.  The formatting text is printed properly but the variables are not. 

 

Code that i used.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <stdio.lib>

int a = 120;

int b = 240;

int c = 360;

int d = 480;

char buffer[30];

sprintf(buffer,"Var 1 = %3u Var 2 =%3u Var 3 =%3u Var 4 =%3u",a,b,c,d)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

What i expect to get is "Var 1=120 Var 2 =240 Var 3 =360 Var 4=480"

what i actually get is "Var 1=    Var 2    = Var 3    = Var 4=   "

As you can see i get the formating text....but i dont get the values of the variables.  ANY THOUGHTS?

  • Hi Eric,

     

    I have the same problem with programming an MSP430F4784 Micro using new CodeComposer Studio 4. Bevor I using the CCE 3.1 and it works fine.

    Please TI, give some help!!!

     

    CODE:

      DegC = 102.56;               //float
      sprintf(DegC_strg, "Temp: %03.2f",DegC);
      LCDOuts(DegC_strg);         //string output
    wait(50000);

    DISPLAY(2x16): Temp: 3.2f   ???

     

    SO I REMEMBER, ANY THOUGTS, thanks???

     

     

  • Does the behavior change if you extend the heap size?

  • No changing the heap size did not effect how the sprintf functioned....

    I have narrowed the problem down to being with the Code Composer Studio 4.

    The exact same program in Code Composer Essentials 3.1 works flawlessly.

    I would normally expect an issue like this from Microsoft...lol

  • I don't know about the 4784, but on the 5438, you can program wiht MSP430 and MSP430X command set. Normally, this is transparent to the programmer, only that the X commands can access more than 64k but add to stack usage for larger 20 bit return address etc.

    Maybe CCS3.1 did not know about 430X and always compiled programs with the standard commands. And its libraries, containing the sprintf function and many more) were written and compiled for non-X. But CCS4 will per default use the 430X commands and link the X version of the library. Of course the X version of the library has been recompiled with X return commands (using RETA instead of RET instructions for 20 bit return address on stack), but functions which make assumptions about the stack content (and sprintf does) need to be rewritten manually to handle the difference. Maybe this has slipped through when building CSS4.

    I'm just guessing, but a new compiler version and sprintf problems sounds very familiar to me from the MSPGCC compiler.

    One more thing, Eric: your buffer is 30 bytes, yet the size of the generated string (including the 4 variables) would be 45 bytes. even without them in the printout, you're writing out of bounds.

  • To solve this sprintf problem with CODE COMPOSER STUDIO V4 follow these steps:

    Project -> Properties -> C/C++ Build -> Tools Settings -> Library Function Assumptions

    In the LEVEL OF PRINTF SUPPORT REQUIRED change the option MINIMAL to FULL.

    That's it.

     

     

  • Thanks for your CodeComposer 4 I.Q. JHony.  Your information was correct and it did solve my Sprintf problem.  Hope this help everyone else as well.

  • Great! This worked for me to fix my problem with using sprintf and floats.

    Thanks

  • I also have problems with the sprintf fucntion.

    I am using TMS320F28335, CCS4 V4.1.2.00027, TI XDS100v1 USB emulator

    char sTemp[14];

    float fV = 5.2;

    sprintf(sTemp,"%.3f", fV);

    When the code run into sprintf, it crash,i.e. went into selfLoop.

    I did what you said about  set the LEVEL OF PRINTF SUPPORT REQUIRED change the option MINIMAL to FULL.

    But still not work, Could you please help?

     

     

     

     

  • I also have problems with the sprintf fucntion.

    I am using TMS320F28335, CCS4 V4.1.2.00027, TI XDS100v1 USB emulator

    char sTemp[14];

    float fV = 5.2;

    sprintf(sTemp,"%.3f", fV);

    When the code run into sprintf, it crash,i.e. went into selfLoop.

    I did what you said about  set the LEVEL OF PRINTF SUPPORT REQUIRED change the option MINIMAL to FULL.

    But still not work, Could you please help?

     

     

     

     

  • I'm having a problem with Code Composer.  Here is the code:

           char buf[10];
           float x;

           x=9.9;
           sprintf(buf,"%f", x) ; //puts garbage in the buf[] buffer in Release mode, works in Debug mode

           //buf[0] = '9'; //works correctly
           //buf[1] = '.';
           //buf[2] = '9';
           writecom(buf[0], 1);//test by writing to LCD display
           writecom(buf[1], 1);
           writecom(buf[2], 1);

    The sprintf function does not appear to work in Release mode but works
    perfectly in Debug mode.  I have the optimization set to zero and have adjusted the support settings mentioned earlier in this thread.

     

     

  • Try to increase the heap size, that might help.

  • Don Powrie said:
    The sprintf function does not appear to work in Release mode but works
    perfectly in Debug mode. 

    debug mode and release mode have an individual set of settings (else there were no difference between the two and no need to have them). you need to configure both independently.

  • Hurrah! That worked and saved me oodles of frustration. Thanks so much!

  • thanks it solved my problem with sprintf

  • Jhony, is there a similar option under CCS 5.1.1.00031?

    --Randy

**Attention** This is a public forum