---
title: "PHYCFGR register cannot be read and My code stucks at socket() function"
url: "https://maker.wiznet.io/forum/14994"
markdown_url: "https://maker.wiznet.io/forum/14994/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "Anonimo"
created: "2023-08-02T10:18:22+09:00"
last_activity: "2023-08-02T10:18:23+09:00"
language: "en"
views: 227
replies: 0
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# PHYCFGR register cannot be read and My code stucks at socket() function

## Question

Asked by Anonimo on 2023-08-02 in Ethernet Chips.

Hi.
I want to transfer data by connecting the W5500 module to the STM32H7 board. I wanted to test it before starting my project. My test code is as follows. My code gets stuck and does not progress in the socket() function. As suggested, i tried to read the PHYCFGR register. i obtained the value of 255 from this register. And when i attempted to set the IP address and other settings at line 80 (You can check my code below, i numbered them), and tried to get all the parameters set in the W5500 at line 83, all the parameters returned with a value of 255. What could be the problem? I believe i have made the GPIO connections correctly. I used SPI5. What should i do?

1. /* USER CODE BEGIN Header */

2. /* USER CODE END Header */*
* *
* *
3. * *
   */* Includes ------------------------------------------------------------------*/

4. #include “main.h”

5. /* Private includes ----------------------------------------------------------*/*
* *
* *
6. * *
   */* USER CODE BEGIN Includes */

7. #include “socket.h”

8. #include “wizchip_conf.h”

9. #include &lt;string.h>

10. #include “loopback/loopback.h”

11. /* USER CODE END Includes */

12. /* Private typedef -----------------------------------------------------------*/*
* *
* *
13. * *
    */* USER CODE BEGIN PTD */*
* *
*
14. int sn = 0;

15. #define mydata “test\n”

16. int i = 0;

17. uint8_t bufSizeTx={2,2,2,2};

18. uint8_t bufSizeRx={2,2,2,2};
*
19. * *
    */* USER CODE END PTD */

20. /* Private define ------------------------------------------------------------*/*
* *
* *
21. * *
    */* USER CODE BEGIN PD */

22. /* USER CODE END PD */

23. /* Private macro -------------------------------------------------------------*/*
* *
* *
24. * *
    */* USER CODE BEGIN PM */

25. /* USER CODE END PM */

26. /* Private variables ---------------------------------------------------------*/

27. SPI_HandleTypeDef hspi1;

28. SPI_HandleTypeDef hspi5;

29. /* USER CODE BEGIN PV */

30. /* USER CODE END PV */

31. /* Private function prototypes -----------------------------------------------*/*
* *
*
32. void SystemClock_Config(void);

33. static void MX_GPIO_Init(void);

34. static void MX_SPI1_Init(void);

35. static void MX_SPI5_Init(void);
*
36. * *
    */* USER CODE BEGIN PFP */

37. /* USER CODE END PFP */

38. /* Private user code ---------------------------------------------------------*/*
* *
* *
39. * *
    */* USER CODE BEGIN 0 */

40. void W5500_Select(void) {

41. HAL_GPIO_WritePin(W5500_CS_EX_GPIO_Port, W5500_CS_EX_Pin, GPIO_PIN_RESET);

}

1. void W5500_Unselect(void) {

2. HAL_GPIO_WritePin(W5500_CS_EX_GPIO_Port, W5500_CS_EX_Pin, GPIO_PIN_SET);

}

1. uint8_t spi_rb(void){

2. uint8_t cdata;

3. HAL_SPI_Receive(&hspi5, &cdata, sizeof(cdata), 100);

4. return cdata;

}

1. void spi_wb(uint8_t b){

2. HAL_SPI_Transmit(&hspi5, &b, sizeof(b), 100);

}

1. enum Status
   {

2. Failed = 0,

3. Success = 1
   };

4. uint8_t validSetNetInfoResult(wiz_NetInfo* _set, wiz_NetInfo* _get)
   {

5. return(!memcmp(_set, _get, sizeof(wiz_NetInfo)));
   }

6. /* USER CODE END 0 */

7. /**

8. - @brief The application entry point.

9. - @retval int

10. */*
* *
*
11. int main(void)
    {
*
12. * *
    */* USER CODE BEGIN 1 */

13. /* USER CODE END 1 */

14. /* MCU Configuration--------------------------------------------------------*/

15. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

16. HAL_Init();

17. /* USER CODE BEGIN Init */

18. /* USER CODE END Init */

19. /* Configure the system clock */

20. SystemClock_Config();

21. /* USER CODE BEGIN SysInit */

22. /* USER CODE END SysInit */

23. /* Initialize all configured peripherals */*
* *
*
24. MX_GPIO_Init();

25. //MX_SPI1_Init();

26. MX_SPI5_Init();
*
27. * *
    */* USER CODE BEGIN 2 */

28. reg_wizchip_cs_cbfunc(W5500_Select,W5500_Unselect);

29. reg_wizchip_spi_cbfunc(spi_rb, spi_wb);

30. wiz_NetInfo gGetNetInfo;

31. wiz_NetInfo gSetNetInfo = {
    .mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef},
    .ip = {192,168,2,192},
    .sn = {255, 255,255,0},
    .gw = {192,168,2,1},
    .dns = {130,130,130,130},
    .dhcp = NETINFO_STATIC};

32. wizchip_setnetinfo(&gSetNetInfo);

33. HAL_Delay(100);

34. wizchip_getnetinfo(&gGetNetInfo);

35. HAL_Delay(100);

36. wizchip_init(bufSizeTx, bufSizeRx);

37. HAL_Delay(100);

38. uint16_t port = 8880;

39. socket(sn, Sn_MR_TCP, port, SF_TCP_NODELAY);

40. HAL_Delay(1000);

41. connect(sn, gSetNetInfo.ip, port);

42. HAL_Delay(1000);

43. /* USER CODE END 2 */

44. /* Infinite loop */*
* *
* *
45. * *
    */* USER CODE BEGIN WHILE */*
* *
*
46. while (1)
    {
*
47. * *
    */* USER CODE END WHILE */

```
97. /* USER CODE BEGIN 3 */


98. i ++;
99. send(sn, &mydata, strlen(mydata));
100. if (i == 2){
101. 	break;
}
```

}

1. close(sn);

2. /* USER CODE END 3 */
   }

---

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