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.

CCS/CC2650: CC2650 sprinft

Part Number: CC2650


Tool/software: Code Composer Studio

Hi,

I would like to convert an integer to an ascii string with sprintf. The code compiles and I can start it but when it arrives to this line (this is an example: sprintf (str, "% d", 30);) the code stops. What can I do?

Note: I am on CCS

thank you in advance

Jérémy

  • Hello,
    Can you explain more what happens? Are you saying that you run the application and it just halts on the sprintf call for no reason?

    Also note that there are many things to take into consideration when trying to use C I/O on embedded devices. Please see the below article for more details:
    dev.ti.com/.../

    Thanks
    ki
  • Not sure if this is related, but there appears to be a space character between the "%" and the "d" character.

    Also please make sure str is a buffer large enough to hold the resulting string and null terminating character. For a 32-bit integer, a 16 character buffer should suffice: char str[16]; Alternatively str needs to be a pointer to such a buffer. If your str pointer is not set correctly, sprintf() may be putting its result into some location that causes the program to halt or experience a fault of some kind.

    Generally with code that doesn't need to access hardware-specific features of the microcontroller, I like to make a minimal test program that includes the code in question and compile and run that on my PC. It is often easier and faster to debug code on a PC and afterwards transfer working code to your microcontroller. If it works on your PC, it's not guaranteed to work on the microcontroller, but at least you have more confidence in your code.
  • Hello Jeremy,
    I haven’t heard back from you, I’m assuming you were able to resolve your issue. If not, please provide post a reply with an update below (or create a new thread).

    thanks,
    ki