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/TMS320F28379D: ltoa working in flash

Part Number: TMS320F28379D
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

Hello All,

I am trying to output a string from an Int through a serial connection. I have found many helpful links showing me how to do this, especially discussing ltoa. It works well when I add it into the example sci_echoback from controlSuite. The problem is, when I go to add it into a different program using flash it does not work. I am still using #include stdlib.h, but it does not result in a conversion from the long int to char like it does in the first example program. Ideally I would like to use the stdlib function, but don't know what is wrong with my setup in order to do that.

So, my first question is, am I missing some include which will allow stdlib to work? Or is there a different way to go from a long to a char?

Help appreciated.

Reed

  • Update - I tried it with the flash memory example from controlSuite, and it didn't work there either.

    I am also attempting to write my own code that will do this, but it is just returning the same buffer as well. This code is based on www.techiedelight.com/.../ .

    Any other thoughts would be helpful.

    Thank you.
  • Reed,

    I assume you started with a Flash example from ControlSuite and simply added a call to ltoa in the code? I would imagine this should work with just the stdlib.h included. I will give this a try and see if I can reproduce the issue.
  • Yes, I did. I did also add in most of the code from example sci_echoback also from ControlSuite to make the scia work. When I look at both msg and what I am receiving in PuTTy I am don't see the number I am trying to send.
  • Hello All,

    It turns out the problem was not with ltoa, that portion of code is working.

    Through trying to debug the code I made a fortuitous discovery. When I use two different char * pointer, and use one for messages and the other for numbers it works.

    For example I make two global variables
    char *msgNum;
    char *msg;

    Then I I go through and set up the SCIA similar to in the sci_echoback example.

    Then I go into the eternal loop.

    for (;;)
    {
    DELAY_US(1000);
    msg = "\r\nNumber: \0";
    scia_msg(msg);
    ltoa(LoopCount,msgNum);
    scia_msg(msgNum);
    LoopCount++;
    }

    When I use msgNum for the ltoa it works, but when I only use msg for both it does not.

    If someone could tell me why that would be appreciated!

    Reed
  • Because you did not set aside any memory for msg or msgNum.
    char * msg just creates a pointer, but it does not point anywhere.

    You need to define it like this:
    char msg[16]; (Or whatever size you want)

    You can also use malloc().
  • Keith,

    Thanks for getting back to me. Your answer makes a lot of sense to me, but these solutions do not seem to be working out.

    When I try
    char msg[32];
    I get the an error when I try to write to it: error #138: expression must be a modifiable lvalue

    When I try instantiating
    char *msg = malloc(32);
    I get: error #60: function call is not allowed in a constant expression

    When I try
    msg = malloc(32*sizeof(char));
    In the beginning of main, it throws no errors, but it does not send numbers.

    So my question is: how do I instantiate this correctly so that I am getting the correct memory allocation?

    Reed
  • Please show all your code. There is something weird here.

    You cannot say

    msg = "\r\nNumber: \0";

    You need to include <string.h> and use strcpy(msg, "\r\nNumber: ");

    This is basic C.
  • Keith,

    Thank you for checking this out. You are correct, when I instead of trying to use an = symbol, and instead use string functions from string.h it works well.

    Thank you for helping me out with this.

    Reed