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/SW-EK-TM4C1294XL: Getting garbage data in UDP packet

Part Number: SW-EK-TM4C1294XL

Tool/software: Code Composer Studio

Hello everyone!

I am learning the implementation of UDP. I have implemented a UDP receive function. For small data like "Hello" is successfully received by the controller but when I send large string like "Prateek-Client-UDP-Testing", I receive the following message:

Prateek-Client-UDP-Testing▒bJ▒▒bJ▒▒bJ▒.250:1900
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1
Man: "ssdp:discover"
MX: 3

▒▒▒▒"▒▒▒"▒▒▒"

My callback function is as follows:

void udp_recv_print(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port){
      if (p != NULL) {
          UARTprintf("Data Received --->> %s\n",p->payload);
          pbuf_free(p);
      }
}


Please suggest some solutions to get rid of the garbage data.

  • Hi,
    You might want to check your UART baudrate. Try to increase the baudrate and see if it helps. Or if you decrease the baudrate, will it make it worst? If by changing the UART baudrate will make a difference one way or the other then it is the baudrate issue. Your UART might not be able to keep up with your incoming UDP packet. Make sure your terminal baudrate speed matches with your MCU UART baudrate configuration. The reason to check the baudrate is that you said you are trying to send a large string of data. How big is the data and how fast are you sending them.


    Bear in mind that UDP protocol does not perform any error checking on the packet. When using UDP, packets are just sent to the recipient. The sender will not wait to make sure the recipient received the packet — it will just continue sending the next packets. If the recipient misses some UDP packets, you can not ask for those packets again. There is no guarantee you are getting all the packets and there is no way to ask for a packet again if you miss it. You might want to try TCP and see if you are getting different results.
  • Thanks for the quick reply. I tried changing the UART baudrate but it didn't help. Probably because I am just printing the p->payload on screen and the data being received is at a very low rate (~5 seconds). I suspected that my method of printing the the p->payload is wrong. When we look at the pbuf data structure, the payload is defined as void *payload. Therefore, I used memcpy instead to copy the contents of payload to a message array as follows:

    void udp_recv_print(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port){
    if (p != NULL) {
    char mesg[30] = "";
    memcpy(msg, p->payload, p->len);
    UARTprintf("Data Received --->> %s\n",msg);
    pbuf_free(p);
    free(msg);
    }
    }

    This worked for me and it makes much more sense now. Thanks for the help.