---
title: "ARP & TCP Connection Issues with W5500: Client and Server Modes Failing to Establish Connections (W5500 does not respond to ARP reply from PC)"
url: "https://maker.wiznet.io/forum/15276"
markdown_url: "https://maker.wiznet.io/forum/15276/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "Joshua.O"
created: "2024-09-09T13:58:40+09:00"
last_activity: "2024-09-09T17:10:14+09:00"
language: "en"
views: 10
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# ARP & TCP Connection Issues with W5500: Client and Server Modes Failing to Establish Connections (W5500 does not respond to ARP reply from PC)

## Question

Asked by Joshua.O on 2024-09-09 in Ethernet Chips.

**Problem Description:**

I’m currently facing an issue with my project involving the W5500 Ethernet module. Specifically, I’m unable to establish a successful TCP connection, whether the W5500 is configured as a client or a server. My initial goal was to configure it to be a server, but because it did not work as a server I though to would

### Details:

1. **Client Mode:**

- When the W5500 is set up as a client, it successfully sends out an ARP broadcast, and my PC responds as expected. However, after this initial exchange, the W5500 does nothing further. Initially, I suspected that the issue might be related to the MAC address, so I tried using a MAC address from a known working Microchip device, but the problem persists.

1. **Server Mode:**

- In server mode, when I attempt to connect to the W5500 using Hercules, the connection times out with no response from the W5500.

- The code seems to get stuck in a `do-while` loop. I added several register calls to check the state of the chip, but I haven’t identified the cause of the problem.

- I also tried pinging the W5500 from the Command Prompt, but it didn’t respond. Disabling the firewall didn’t make a difference either.

- I printed out the states of the sockets to diagnose the issue, but I haven’t found anything wrong with the configurations.

### Summary:

The W5500 is unable to establish a TCP connection in either client or server mode. Below is the code I’m using. Any insights or suggestions would be greatly appreciated.

**My Code**

// Static Network Details
wiz_NetInfo gWIZNETINFO = {
.mac = { 0x80, 0x34, 0x28, 0x74, 0xA5, 0xCB }, //MSB → LSB
.ip ={ 192, 168, 50, 14 },
.sn = { 255, 255, 255, 0 },
.gw ={ 192, 168, 50, 254 },
.dns = { 192, 168, 50, 254 },
.dhcp = NETINFO_STATIC };

// TCP CLIENT
#if TCP_CLIENT_TEST == 1
// TCP Client Test
printf(“\r\n* TCP CLIENT**\r\n”);

```
if(socket(1, Sn_MR_TCP, 0, SF_TCP_NODELAY)==1)
{
	  printf("\r\nSocket Created Successfully");
}
else
{
	  printf("\r\nCannot create socket");
	  while(1);
}

// Set Block or Non-block Mode
uint8_t socket_io_mode = SOCK_IO_BLOCK;
ctlsocket(1, CS_SET_IOMODE, &socket_io_mode); // Set blocking IO mode



printf("\r\nConnecting to server: %d.%d.%d.%d @ TCP Port: %d",destination_ip[0],destination_ip[1],destination_ip[2],destination_ip[3],destination_port);
if(connect(1, destination_ip, destination_port)==SOCK_OK)
{
  printf("\r\nConnected with server.");

}
else
{
  //failed
  printf("\r\nCannot connect with server!");
  while(1){
	#if UART_DEBUG == 1
		//Read the PHYCFGR register
		uint8_t phycfgr_value = getPHYCFGR();

		//Check and print the status based on the PHYCFGR register
		//Print the entire PHYCFGR register value
		printf("\r\nPHYCFGR Register Value: 0x%02X\n", phycfgr_value);
	#endif
  }
}

while (1)
{
  //Return value of the send() function is the amount of data sent
  if(send(1, "ICH HABE DICH!\r\n", 16)<=SOCK_ERROR)
  {
	  printf("\r\nSending Failed!");
	  while(1);

  }
  else
  {
	  printf("\r\nSending Success!");
  }

  HAL_Delay(1000);
}
```

#endif

//TCP SERVER
printf(“\r\n* TCP SERVER**\r\n”);

```
while(1)
{
    printf("\r\nInitializing server socket\r\n");

    int8_t sockID = socket(1, Sn_MR_TCP, LISTEN_PORT, SF_TCP_NODELAY);
    if(sockID != 1)
    {
        printf("Cannot create Socket! Socket ID: %d\r\n", sockID);
        while(1); // Stop here if socket creation fails
    }

    printf("Socket Created Successfully! Socket ID: %d\r\n", sockID);

    // Check the Sn_SR Configuration Register (Sn_SR) for 10 repetitions
	printf("\r\nSn_SR OPEN SOCKET CHECK");
	uint8_t sn_sr_value_1 = 0;
	int repetitions_4 = 0;  // Counter for loop iterations

	for (repetitions_4 = 0; repetitions_4 < REPETITIONS_CHECK; repetitions_4++)
	{
		// Read the Sn_SR register
		sn_sr_value_1 = getSn_SR(1);

		// Print the current value of the Sn_SR register
		printf("Sn_SR Value: 0x%02X\r\n", sn_sr_value_1);

		HAL_Delay(1000); // Wait 1 sec before checking again
	}

    uint8_t socket_io_mode = SOCK_IO_BLOCK;
    ctlsocket(1, CS_SET_IOMODE, &socket_io_mode); // Set blocking IO mode

    printf("Start listening on port %d! Waiting for a client connection.\r\n", LISTEN_PORT);

    if(listen(1) != SOCK_OK)
    {
        printf("Cannot listen on port %d\r\n", LISTEN_PORT);
        while(1);
    }

    uint8_t sr = 0x00; // Socket status register
```

// uint32_t timeout = HAL_GetTick() + 10000; // 10-second timeout
// uint8_t testip[4] = { 2, 2, 2, 2 };
// uint8_t recievedip[4] = {0, 0, 0, 0};
do
{
printf(“\r\n*REGISTER STATUS START**\r\n”);

```
    	// Read status register (SR) of socket 1
        sr = getSn_SR(1);
        printf("\r\nSocket Status Register (SR): 0x%02X\r\n", sr); // Debugging info

        // Read and print the Socket n Mode (Sn_MR) register
        uint8_t sn_mr = WIZCHIP_READ(Sn_MR(1));
        printf("Socket Mode Register (Sn_MR): 0x%02X\r\n", sn_mr);

        // Read and print the Socket n Command (Sn_CR) register
        uint8_t sn_cr = WIZCHIP_READ(Sn_CR(1));
        printf("Socket Command Register (Sn_CR): 0x%02X\r\n", sn_cr);

        // Read and print the Socket n Interrupt (Sn_IR) register
        uint8_t sn_ir = WIZCHIP_READ(Sn_IR(1));
        printf("Socket Interrupt Register (Sn_IR): 0x%02X\r\n", sn_ir);

        // Read and print the Socket n Interrupt (Sn_IMR) register
		uint8_t sn_imr = WIZCHIP_READ(Sn_IMR(1));
		printf("Socket Interrupt Register (Sn_IMR): 0x%02X\r\n", sn_imr);

        // Read and print the Socket n RX Received Size (Sn_RX_RSR0, Sn_RX_RSR1) registers
        uint16_t sn_rx_rsr = getSn_RX_RSR(1);
        printf("Socket RX Received Size (Sn_RX_RSR): 0x%04X\r\n", sn_rx_rsr);

        // Read and print the Socket n TX Write Pointer (Sn_TX_WR0, Sn_TX_WR1) registers
        uint16_t sn_tx_wr = getSn_TX_WR(1);
        printf("Socket TX Write Pointer (Sn_TX_WR): 0x%04X\r\n", sn_tx_wr);

        // Read and print the Socket n RX Read Pointer (Sn_RX_RD0, Sn_RX_RD1) registers
        uint16_t sn_rx_rd = getSn_RX_RD(1);
        printf("Socket RX Read Pointer (Sn_RX_RD): 0x%04X\r\n", sn_rx_rd);

        // Read and print the Socket n TX Free Size (Sn_TX_FSR0, Sn_TX_FSR1) registers
        uint16_t sn_tx_fsr = getSn_TX_FSR(1);
        printf("Socket TX Free Size (Sn_TX_FSR): 0x%04X\r\n", sn_tx_fsr);

        // Read and print the Socket n Destination IP Address (Sn_DIPR0 to Sn_DIPR3) registers
        uint8_t sn_dipr[4];
        getSn_DIPR(1, sn_dipr);
        printf("Socket Destination IP Address (Sn_DIPR): %d.%d.%d.%d\r\n", sn_dipr[0], sn_dipr[1], sn_dipr[2], sn_dipr[3]);

        // Read and print the Mode Register (MR)
        uint8_t mr = WIZCHIP_READ(MR);
        printf("Mode Register (MR): 0x%02X\r\n", mr);

        // Read and print the Gateway Address (GAR0 to GAR3) registers
        uint8_t gar[4];
        getGAR(gar);
        printf("Gateway Address (GAR): %d.%d.%d.%d\r\n", gar[0], gar[1], gar[2], gar[3]);

        // Read and print the Subnet Mask Address (SUBR0 to SUBR3) registers
        uint8_t subr[4];
        getSUBR(subr);
        printf("Subnet Mask Address (SUBR): %d.%d.%d.%d\r\n", subr[0], subr[1], subr[2], subr[3]);

        // Read and print the Source Hardware Address (SHAR0 to SHAR5) registers
        uint8_t shar[6];
        getSHAR(shar);
        printf("Source Hardware Address (SHAR): %02X:%02X:%02X:%02X:%02X:%02X\r\n",
               shar[0], shar[1], shar[2], shar[3], shar[4], shar[5]);

        // Read and print the Source IP Address (SIPR0 to SIPR3) registers
        uint8_t sipr[4];
        getSIPR(sipr);
        printf("Source IP Address (SIPR): %d.%d.%d.%d\r\n", sipr[0], sipr[1], sipr[2], sipr[3]);

        // Read and print the Interrupt Mask Register (IMR)
        uint8_t imr = WIZCHIP_READ(_IMR_);
        printf("Interrupt Mask Register (IMR): 0x%02X\r\n", imr);

        // Read and print the Retry Time-value Register (RTR0 to RTR1)
        uint16_t rtr = getRTR();
        printf("Retry Time-value Register (RTR): 0x%04X\r\n", rtr);

        // Read and print the Retry Count Register (RCR)
        uint8_t rcr = WIZCHIP_READ(_RCR_);
        printf("Retry Count Register (RCR): 0x%02X\r\n", rcr);

        // Read and print the PHY Configuration Register (PHYCFGR)
        uint8_t phycfgr = getPHYCFGR();
        printf("PHY Configuration Register (PHYCFGR): 0x%02X\r\n", phycfgr);

        // Read and print the Socket Source Port (Sn_PORT0, Sn_PORT1) register
        uint16_t sn_port = getSn_PORT(1);
        printf("Socket Source Port (Sn_PORT): 0x%04X\r\n", sn_port);

        // End line
        printf("\r\n***************** REGISTER STATUS END******************\r\n");

        HAL_Delay(5000); // Small delay to avoid busy waiting

    } while (sr != 0x17 && sr != 0x00);


    if(sr == 0x00)
    {
        printf("Some error occurred on server socket. Please restart.\r\n");
        while(1);
    }

    if(sr == 0x17)
    {
        printf("A client connected! Waiting for Client Data ...\r\n");

        while(1)
        {
            int len = recv(1, receive_buff, RECEIVE_BUFF_SIZE);

            if(len == SOCKERR_SOCKSTATUS)
            {
                printf("Client has disconnected\r\n");
                printf("*** SESSION OVER ***\r\n\r\n");
                break;
            }

            receive_buff[len] = '\0';

            printf("Received %d bytes from client\r\n", len);
            printf("Data Received: %s\r\n", receive_buff);

            send(1, (uint8_t*)"[", 1); // Starting sq bracket
            send(1, receive_buff, len); // The data
            send(1, (uint8_t*)"]", 1); // Closing sq bracket

            printf("ECHO sent back to client\r\n");

            if(strcmp((char*)receive_buff, "QUIT") == 0)
            {
                printf("Received QUIT command from client\r\n");
                printf("Disconnecting ... \r\n");
                printf("*** SESSION OVER ***\r\n\r\n");
                disconnect(1); // Disconnect from the client
                break; // Come out of the while loop
            }
        } // While loop (as long as client is connected)
    } // If block, client connect success
} // While loop for next client wait
```

[![Image (1)](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/d/db1b8deab9145f26bf09333f33499971a430fa7f.jpeg) Image (1)1920×1440 431 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/d/db1b8deab9145f26bf09333f33499971a430fa7f.jpeg)

## Replies

### Reply 1 by Eugeny, 2024-09-09

![](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/48.png) Joshua.O:

> I printed out the states of the sockets to diagnose the issue, but I haven’t found anything wrong with the configurations.

Is it possible to see it, as well as all the communication which includes IP 192.168.50.14 (better with wireshark log file and not screenshot).

And please choose the mode to troubleshoot - either client or server.

---

Source: https://maker.wiznet.io/forum/15276
