---
title: "W5500: Can't Open Socket, getSn_SR(sn) returns always SOCK_CLOSED"
url: "https://maker.wiznet.io/forum/15925"
markdown_url: "https://maker.wiznet.io/forum/15925/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "yahyaemb"
created: "2025-11-04T01:41:54+09:00"
last_activity: "2025-11-05T11:05:34+09:00"
language: "en"
tags: ["W5500"]
views: 5
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500: Can't Open Socket, getSn_SR(sn) returns always SOCK_CLOSED

## Question

Asked by yahyaemb on 2025-11-04 in Ethernet Chips.

Hello everyone,

I'm working with the W5500 Ethernet module connected to an STM32 microcontroller. The initialization seems to be working correctly:

- I can read the version register and get `0x04` as expected.

- I successfully set a static IP configuration.

- The W5500 responds to ping requests, so basic communication is fine.

However, I'm facing an issue when trying to use DHCP or open a socket. The code gets stuck at this line in `socket.c` at the end of socket() function:

while(getSn_SR(sn) == SOCK_CLOSED);

The `getSn_SR(sn)` function always returns `SOCK_CLOSED`, and the socket never transitions to another state. This happens both when trying to run DHCP and when attempting to open a UDP socket.

Has anyone encountered this issue before? Could it be related to SPI communication, socket configuration, or something else in the initialization sequence?

Any help or suggestions would be greatly appreciated!

Thanks,
Yahya Aouled Amer

## Replies

### Reply 1 by TheoIm, 2025-11-05

hi,

First, you need to verify that the basic SPI operations are functioning correctly. Try reading the network information below and then directly issue a UDP open command to the socket.

use this function to read the network information first.

```c
void print_network_information(wiz_NetInfo net_info)
{
    uint8_t tmp_str[8] = {
        0,
    };

    ctlnetwork(CN_GET_NETINFO, (void *)&net_info);
    ctlwizchip(CW_GET_ID, (void *)tmp_str);

    if (net_info.dhcp == NETINFO_DHCP)
    {
        printf("====================================================================================================\n");
        printf(" %s network configuration : DHCP\n\n", (char *)tmp_str);
    }
    else
    {
        printf("====================================================================================================\n");
        printf(" %s network configuration : static\n\n", (char *)tmp_str);
    }

    printf(" MAC         : %02X:%02X:%02X:%02X:%02X:%02X\n", net_info.mac[0], net_info.mac[1], net_info.mac[2], net_info.mac[3], net_info.mac[4], net_info.mac[5]);
    printf(" IP          : %d.%d.%d.%d\n", net_info.ip[0], net_info.ip[1], net_info.ip[2], net_info.ip[3]);
    printf(" Subnet Mask : %d.%d.%d.%d\n", net_info.sn[0], net_info.sn[1], net_info.sn[2], net_info.sn[3]);
    printf(" Gateway     : %d.%d.%d.%d\n", net_info.gw[0], net_info.gw[1], net_info.gw[2], net_info.gw[3]);
    printf(" DNS         : %d.%d.%d.%d\n", net_info.dns[0], net_info.dns[1], net_info.dns[2], net_info.dns[3]);
    printf("====================================================================================================\n\n");
    }
```

Then, try issuing the UDP command directly.

```c
    setSn_MR(sn, 0x02);                     
    uint8_t val = getSn_MR(sn);             
    printf("Sn_MR: 0x%02X\n", val);
```

please share the results with me afterward

thanks

---

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