---
title: "W5500 PHY link status reading PHYCFGR problem"
url: "https://maker.wiznet.io/forum/15254"
markdown_url: "https://maker.wiznet.io/forum/15254/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "arcticPlatypus"
created: "2024-08-02T19:46:33+09:00"
last_activity: "2024-08-03T13:21:27+09:00"
language: "en"
views: 32
replies: 2
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 PHY link status reading PHYCFGR problem

## Question

Asked by arcticPlatypus on 2024-08-02 in Ethernet Chips.

Hello,
I’m using the W5500-EVB-Pico module. LwIP and c.
At the very start of my code, immediatley after wizhip_initialize() I try and detect if the PHY link is up by reading bit 0 of the 5500 PHYCFGR register. My problem is if the code starts with no physical link (RJ45 jack is unplugged) it appears that getPHYCFGR() never returns and the program hangs. As soon as an RJ45 cable is plugged in the code starts to run as expected, even when the cable is subsequently un-plugged again.
(The W5500 initialize code is based upon any Wiznet RP2040-HAT-LWIP-C refernce code)

int main()
{
set_clock_khz();
stdio_init_all();
printf(“Hello from Main\n”);
wizchip_spi_initialize();
wizchip_cris_initialize();
wizchip_reset();
sleep_ms(200);
wizchip_initialize();

// Check RJ45 plugged in! Registers specific to Wizchip W5500
// Non blocking 1 second loop
while (connected == 0){
time_now = to_ms_since_boot(get_absolute_time());
if (time_now - time_then >= 1000){
time_then = time_now;
if ((getPHYCFGR() & PHY_LINK_ON) != 0){
connected = 1;
}
printf(“* Awaiting Ethernet PHY Up *\n");
}
}
printf("* Ethernet PHY Up *\n”);
wizchip_check();

code continues…
So I’m expecting the code above to print “Awaiting Ethernet PHY Up” every second until the RJ45 is connected. In reality I get nothing until the RJ45 is connected.

Can someone point out the error in my ways please?
Thank you.

## Replies

### Reply 1 by Eugeny, 2024-08-02

Format code properly. And it has nothing to do with W5500. It is purely C exercise.

### Reply 2 by arcticPlatypus, 2024-08-03 (in reply to reply 1)

OK. I will try again.
Hopefully this code is better formatted and massively simplified to show my problem (Or missunderstanding)
With an ethernet cable connected (LINK UP) 191 is printed.
Which is what I would expect.
191 = b’1011 1111’. bit 0 is set indicating LINK UP.
With no ethernet cable connected (LINK DOWN) nothing is printed and the code doesn’t even proceed to print “End”. It appears getPHYCFGR is not returning a value.
As soon as I plug a cable in the code resumes and prints 191.
If I have a basic mis-understanding please help me understand.
Thank you

```
int main(){
    stdio_init_all();
    sleep_ms(1000);
    printf("Hello from Main\n");
    wizchip_spi_initialize();
    wizchip_cris_initialize();
    wizchip_reset();
    wizchip_initialize();
    uint8_t temp = getPHYCFGR();
    printf("PHYCFGR = %d\n", temp);
    wizchip_check();
    printf("End\n");
    while (1){
        sleep_ms(1000);
        printf("Loop Forever\n");
    }
}
```

---

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