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.

TMS320F28335: String Concatenate in code composer using 28335

Part Number: TMS320F28335


Tool/software:

Hi ,

      I am using TMS320F28335

I am trying to use string concat , strcpy  , strcmp function for example  testData[10] = {'\x02', 'A', 'B', 'C','2', 'D','0','M','\x03'};

to concat this testData to a string using concat and strcpy as shown below in code.

unsigned char extracted_data[5];
unsigned char Concatenat_Data[]={"\0"};
unsigned int receivedData[10] = {'\x02', 'F', 'R', 'M','2', 'D','0','M','\x03'};
unsigned int process_buffer()
{
    unsigned int i,j, initial_index=0,last_index,c=0;

    unsigned int is_cmd_ready = 0;
    char String_Rxd[10] = {"\0"};
    unsigned int buffer_size = sizeof(receivedData) / sizeof(receivedData[0]);

            for (j = 1; j < buffer_size && receivedData[j] != '\x03'; j++)
            {
               if(receivedData[initial_index] == '\x02' && receivedData[8] == '\x03')
               {

                received_command[j - 1] = receivedData[j];
                Concatenat_Data[c] = received_command[j - 1];
                printf("Concatenat_Data: %c\n", Concatenat_Data[c]);

                printf("Received data: %c\n", received_command[j - 1]);  
                c++;
               }
               else if(receivedData[0] != '\x02' || receivedData[8] != '\x03')
               {

               }
            }

      /*Concat function*/
            concatenateStrings(String_Rxd, Concatenat_Data);
            printf("String_Rxd: %s\n", String_Rxd);
              /*Copy string function*/
            strcpy(extracted_data, Concatenat_Data);
            printf("extracted_data: %s\n", extracted_data);

            c=0;
			is_cmd_ready = 1;

        return is_cmd_ready;
}
void concatenateStrings(char* str1, const char* str2)
{

    while (*str1) {
        ++str1;
    }
    while (*str2) {
        *str1++ = *str2++;
    }

    // Add the null-terminating character
    *str1 = '\0';
}

i) First time when I run the code  getting the concatenate string correctly, by using printf we are making sure data is properly concatenated.

Result :
String_Rxd: FRM

extracted_data:FRM

ii)But when we try to  add additional function/code modification , we are not getting the Concatenated string string as previous result. 

Result :

String_Rxd:
extracted_data: 

1) Need clarification on this as we are trying to add additional function/code , we are not getting the string .

Any Changes in the configuration we should do for String or Any Memory size should we add ? in code composer 

2) When we add more function in this sometimes we are getting result as this , some extra symbols are getting displayed
extracted_data: [empty ] or extracted_data: NP€Ëc÷ð`XÈî99x˜w:wW²

3) Does Code composer support strlen function 

Thanks and  Regards,

Taruna G

  • Hi Taruna,

    Can you try stepping through the modified code and seeing which line is causing the issue? Also, what are you modifying?

    Yes, the C2000 compiler supports functions from the C standard library which includes the strlen() function. You would just need to include the string.h header file.

    Best Regards,

    Delaney

  • Hi Thanks for your reply.

     

    1) When we do step in , it is getting stuck in printf statement.

    2) I am doing strcpy/strcat in one function and another function for strcmp [modifying]

     * Actually we are copying the code from notepad and pasting code in code composer , will this cause any problem?

    * When we are typing the code each and every line in code composer and execute , as of now we are getting proper expected result but still sometimes we are not getting the concatenated string is empty.

    Can you please guide me on this and share if any reference regarding "Strings" for code composer[TMS320F28335].

    Thanks and Regards,

    Taruna G

  • Hi Taruna,

    After looking more into your code, I'm a little confused about what you are trying to do. In C, a string literal is simply an array of characters with a null character at the end to terminate. Since you are starting with an array of ints, you could just cast them to unsigned chars and add on a null character at the end to make a string. If the input is:

    unsigned int receivedData[10] = {'\x02', 'F', 'R', 'M','2', 'D','0','M','\x03'};

    What do you want the resulting string/char array to look like? Are you just trying to remove the beginning and ending characters?

    Best Regards,

    Delaney