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.

Compiler/TM4C1294NCPDT: Issue sending a char array though ethernet

Part Number: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

I am working with the example echo_tcp of lwip, I have no problems in sending and receiving data but my goal is to send data from the ADC via ethernet, apparently I am not making the conversion correctly or maybe I am not understanding how to send it.

In my code below, it shows how I'm trying, I open a RAW session in putty and I can see the "echo" part working, but when I send the 'a', the buffer does not take anything, I added the UART to verify that it is doing the conversion, and in effect, in the serialt erminal shows my value converted to hexadecimal

if (tcp_buffer[0] == 'a'){
            uint32_t adc1 =1054;
            char yourstring[6];
            snprintf(yourstring,strlen(yourstring) ,"%X04", adc1);

            tcp_write( pcb, yourstring, strlen(yourstring), 0 );
            tcp_sent( pcb, NULL );
            UARTprintf(yourstring);

         }

i would appreciate any guidance

Best

  • I see two problems with this line ...

    Rocamadour said:
    snprintf(yourstring,strlen(yourstring) ,"%X04", adc1);

    One, you are calling strlen on an uninitialized string.  Who knows what it returns,  Though 0 seems the most likely guess.  You should probably pass the value 6 instead.  Two, instead of "%X04", you probably mean "%04X".  Once you have the first problem fixed, try it both ways.  The first one is probably what you intend.

    If, after all that, you still have problems ... snprintf takes a lot of stack and heap.  Make sure you are not running out. 

    If the problem is somehow connected to the functions tcp_write or tcp_sent, I cannot help with that.

    Thanks and regards,

    -George  

  • Dear George,

    You were rigth, after initialize the string and change the format is working, I dare to ask some other thing, now I want to create a string with several concatenated values from an array, I just get the last value of the array, can you give some advise?

    for ( h = 0; h<3; h++){
    snprintf(yourstring, 20, "%04X\n", adc2[h]);
    UARTprintf(h); // Use it to check is in the loop
    }

    many thanks
  • Update: In case somebody need it, here is how I solved it

    int ptr = 0;
    for( h = 0; h < 3; h++)
    {
    ptr += snprintf(yourstring + ptr, sizeof(yourstring) - ptr, "%04X", adcx[h]);
    }

    regards