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.

MSP430f5359 sprintf formating output

Other Parts Discussed in Thread: MSP430F5359

I'me using the following :-

Code Composer Verison 6.1 and compiler version 4.4.5.
Miccocontroller MSP430F5359 on the MSP-TS430PZ100C.

The software utilses the ATOM RTOS.

There are 4 tasks used.

All of these tasks are asleep. When a carriage return is received 
on the UART2 ( pin 71) input, the associated interrupt routine 
wakes up all 4 tasks etc.


The output task reponds by sending the approriate requested data
to UART2 output ( pin 70).

The above works.

However, the output task uses 'sprintf' to format the data into a 
string as follows.

str_p += sprintf( str_p, " %02X", ram_byte );

str_p is then 'sent' to the UART ouput.

Instead of outputting 0x1a or 0xf2, it outputs 2X.


When str_p += sprintf( str_p, ",%x", ram_byte ); is used the values 1a or f2 are output.

Similary requesting floating point values, '6f' is output instead of the value itself.

In project - MSPCompiler - Advanced Options - Library Funcion Assumptions, 
I canged Level of printf/scanf support from minimal to full.

However, this change prevented the UART interrupt from detecting the carraige return and
consequently not waking up the tasks.

It appears that the data received buy the UART ( UCA2RXBUF) is corrupted.

Can you provide a solution to this ?

Thanks,

  • Rowland,
    Can you send me the code?

    What are you trying to output? You're adding the number of chars written to the hex value, so that may be part of your problem.

    What happens if you remove the str_p+= ?

    I'm looking into the UART losing the interrupt now.

    Best regards,
    Cameron
  • Rowland Roderick said:
    str_p += sprintf( str_p, " %02X", ram_byte );

    Rowland,

    what exactly do you want to do - maybe I just don't get it right :\ The sprintf function takes the number from a variable writes a string to an array of chars and returns the number of written chars (without the "\0"), so

    char    array[10];
    uint8_t variable = 122;
    uint8_t number_of_written_chars;
    
    number_of_written_chars = sprintf( array, "%02X", variable );

    In your case I do not know what str_p is, because you use it inside sprintf, so I would assume it is an array but you also return the written bytes to it. But when it was an array, you would normally pic one element to write the value to, like str_p[0] = sprintf( ...), but of course this would also overwrite your string you just put in there via sprintf.

    So as I said, maybe I just do not get your idea behind this, but this looks strange to me at first sight.

    Dennis

  • Dear Cameron,

    Many thanks for responding.

    I discovered that an i/o pin on the microcontroller wasn't pulled up. Consequently, the UART wasn't initialised correctly.

    The software works correctly provided I ticked the 'full' option in the Level of print/scanf support required in the Project / MSP430 / Advanced options/ Library function Assumptions.

    Rowland
  • Glad it works now!

    Rowland Roderick said:
    I ticked the 'full' option in the Level of print/scanf support

    Yeah, that is another thing that often causes confusion when sprintf does not work properly. Should always be the first question. Maybe wouldn't be a bad idea if CCS could throw out a warning when using datatypes in combination with sprintf that are not supported by the current setting.

    Dennis

**Attention** This is a public forum