WIZnet Developer Forum

WIZ550IO Can not send UDP broadcast message

I am trying to answer udp broadcast message but even I have not get any error during send, message does not recieved by computer.

Here my code

void main(void)
{
    unsigned char i;
    uint8_t macread[8];

    SYSTEM_Initialize();
    
  //w5500
  
    __delay_ms(30);
  
    printf("W5500 EVB initialization over.\r\n");
  
    WIZ550_PWR_SetLow();
    Reset_W5500();/*Ó²ÖØÆôW5500*/
  
    printf("W5500 initialized!\r\n");

    setSHAR(mac);/*ÅäÖÃMacµØÖ·*/
    setSUBR(sub);/*ÅäÖÃ×ÓÍøÑÚÂë*/
    setGAR(gw);/*ÅäÖÃĬÈÏÍø¹Ø*/
    setSIPR(lip);/*ÅäÖÃIpµØÖ·*/

      //Init. TX & RX Memory size of w5500
    wizchip_init(w5500_tx_buffer_len,w5500_rx_buffer_len);

    setRTR(2000);/*ÉèÖÃÒç³öʱ¼äÖµ*/
    setRCR(3);/*ÉèÖÃ×î´óÖØз¢ËÍ´ÎÊý*/

    getSIPR(ip);
    printf("IP : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]);
    getSUBR(ip);
    printf("SN : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]);
    getGAR(ip);
    printf("GW : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]);
    getSHAR(macread);
    printf("MAC : %02X:%02X:%02X:%02X:%02X:%02X\r\n", macread[0],macread[1],macread[2],macread[3],macread[4],macread[5]);
    printf("Network is ready.\r\n");
    //w5500
    while (1)
    {
        // Add your application code
        for(i=0;i<_WIZCHIP_SOCK_NUM_-1;i++)
        {
            loopback_tcps(i,buffer,port+i);
        }
        i=_WIZCHIP_SOCK_NUM_-1;
        loopback_udps(i,buffer,65535);
    }
}


int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port)
{
   int32_t  ret;
   uint16_t size, sentsize;
   uint8_t  destip[4];
   uint16_t destport;

   switch(getSn_SR(sn))
   {
      case SOCK_UDP :
         if((size = getSn_RX_RSR(sn)) > 0)
         {
            if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
            ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
            if(ret <= 0)
            {
#ifdef _LOOPBACK_DEBUG_
               printf("%d: recvfrom error. %ld\r\n",sn,ret);
#endif
               return ret;
            }
            printf("\r\nIP:%u.%u.%u.%u port:%u DATA:",destip[0],destip[1],destip[2],destip[3],destport);
            size = (uint16_t) ret;
            buf[size]=0;
            printf("%s",buf);
            sentsize = 0;
            while(sentsize != size)
            {
//                destip[0]=255;
//                destip[1]=255;
//                destip[2]=255;
//                destip[3]=255;
               ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
               if(ret < 0)
               {
#ifdef _LOOPBACK_DEBUG_
                  printf("%d: sendto error. %ld\r\n",sn,ret);
#endif
                  return ret;
               }
               else
               {
                   printf(" send: %ld\r\n",ret);
               }
               sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
            }
         }
         break;
      case SOCK_CLOSED:
#ifdef _LOOPBACK_DEBUG_
         //printf("%d:UDP loopback start\r\n",sn);
#endif
         if((ret = socket(sn, Sn_MR_UDP, port, SF_MULTI_ENABLE)) != sn)
            return ret;
#ifdef _LOOPBACK_DEBUG_
         printf("%d:Opened, UDP loopback, port [%u]\r\n", sn, port);
#endif
         break;
      default :
         break;
   }
   return 1;
}



int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
{
   int32_t ret;
   uint16_t size = 0, sentsize=0;

#ifdef _LOOPBACK_DEBUG_
   uint8_t destip[4];
   uint16_t destport;
#endif

   switch(getSn_SR(sn))
   {
      case SOCK_ESTABLISHED :
         if(getSn_IR(sn) & Sn_IR_CON)
         {
#ifdef _LOOPBACK_DEBUG_
			getSn_DIPR(sn, destip);
			destport = getSn_DPORT(sn);

			printf("%d:Connected - %d.%d.%d.%d : %u\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
#endif
			setSn_IR(sn,Sn_IR_CON);
         }
		 if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
         {
			if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
			ret = recv(sn, buf, size);

			if(ret <= 0) return ret;      // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
			size = (uint16_t) ret;
            buf[size]=0;
            printf("%s",buf);
			sentsize = 0;

			while(size != sentsize)
			{
				ret = send(sn, buf+sentsize, size-sentsize);
				if(ret < 0)
				{
					close(sn);
					return ret;
				}
				sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
			}
         }
         break;
      case SOCK_CLOSE_WAIT :
#ifdef _LOOPBACK_DEBUG_
         printf("%d:CloseWait\r\n",sn);
#endif
         if((ret = disconnect(sn)) != SOCK_OK) return ret;
#ifdef _LOOPBACK_DEBUG_
         printf("%d:Socket Closed\r\n", sn);
#endif
         break;
      case SOCK_INIT :
#ifdef _LOOPBACK_DEBUG_
    	 printf("%d:Listen, TCP server loopback, port [%u]\r\n", sn, port);
#endif
         if( (ret = listen(sn)) != SOCK_OK) return ret;
         break;
      case SOCK_CLOSED:
#ifdef _LOOPBACK_DEBUG_
         printf("%d:TCP server loopback start\r\n",sn);
#endif
         if((ret = socket(sn, Sn_MR_TCP, port, 0x00)) != sn) return ret;
#ifdef _LOOPBACK_DEBUG_
         printf("%d:Socket opened\r\n",sn);
#endif
         break;
      default:
         break;
   }
   return 1;
}

The fact that

does not mean there’s nothing being sent. Look at the Wireshark log to identify what is being sent by W5500. If there’s really nothing send at the respective time, then close consideration of the code will be needed.

If I change module ip to computer network there is no problem it is working. And also I have product which using udp broadcast with the same sutiation works just fine.

That’s why you need to look at what is actually going on the network in faulty setup instead of trying to guess what it could be.

I did not see any broadcast or data from the w5500. Is there any setting should be made on wireshart to check more detailed way.

If there’s nothing on the wire, then you have set up the chip wrongly. You must review IP address/mask, MAC address and other settings to be correct.

Do you say that when you change IP address (from whic one to which one?) it starts working and you can see respective packets on the network?

Thank you Eugeny. I start from beginign and find out the mistake. The flag variable of the socket subroutine set wrong. Now everything work fine.
Best regards,

Hasan YILDIZ

Hiroshima (A Little Girl / The Dead Girl)

It’s me knocking on the doors
On the doors one after the other
I can’t be seen in your eyes
For deaths can’t be seen in eyes

It has been some ten years
Since I died in Hiroshima
But I’m still a seven years old girl
Dead children don’t grow up

My hair was the first to catch the fire
My eyes burned and charred
I just became a handful of ashes
My ashes got scattered into the air

(There’s nothing at all that I’m asking you for myself
Well, a child who burned like a paper can’t even eat candies)

I’m knocking on your door…
Aunt, uncle, give a signature…
Children shalln’t get killed
So that they are also able to eat candies

Nazim Hikmet

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.