Hello,
I am using the W5500 chip as a module and connected it to the Nuvoton M032 chip. I checked the SPI connections. No matter what I do, I can’t get past the following line. The code keeps getting stuck on this line → while( getSn_CR(sn) );
This line is inside this function
socket() → close() → while( getSn_CR(sn) );
For this reason, I cannot create a TCP Server or client application.
When I examine the return value of this function, it gives the following values: 0x01, 0x02 and continues to give 0x01.
Server Program: Hercules
PC IP: 192, 168, 1, 106
Port: 7000
My codes are as follows.
Thanks.
Best regards.
#include "main.h"
#include "wizchip_conf.h"
#include "socket.h"
uint8_t WIZNET_SPI_Read_Byte(void)
{
/* Check SPI0 busy status */
while (USPI_IS_BUSY(SD_SPIx));
/* Read received data */
return (USPI_READ_RX(SD_SPIx) & 0xFF);
}
void WIZNET_SPI_Write_Byte(uint8_t data)
{
/* Write Byte */
USPI_WRITE_TX(SD_SPIx, data);
/* Check SPI0 busy status */
while (USPI_IS_BUSY(SD_SPIx));
}
uint8_t serverIP[4] = { 192, 168, 1, 106 };
uint16_t serverPort = 7000;
int main(void)
{
SYSTEM_Initialize();
SPI_Init(SD_SPIx, SPI_CLK_FREQ);
WIZNET_RESET_LOW();
Delay_ms(5);
WIZNET_RESET_HIGH();
SPI_CS_High();
reg_wizchip_cs_cbfunc(SPI_CS_Low, SPI_CS_High);
reg_wizchip_spi_cbfunc(WIZNET_SPI_Read_Byte, WIZNET_SPI_Write_Byte);
uint8_t memsize[2][8] = { {2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2} };
uint8_t tmp;
if(ctlwizchip(CW_INIT_WIZCHIP, (void*)memsize) == -1)
{
//myprintf("WIZCHIP Initialized fail.\r\n");
LED_On();
while(1);
}
/* PHY link status check */
do {
if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1)
{
//printf("Unknown PHY Link status.\r\n", 1, 10);
while(1);
}
} while (tmp == PHY_LINK_OFF);
wiz_NetInfo netInfo = { .mac = { 0x2C, 0xF7, 0xF1, 0x08, 0x00, 0x9A }, // Mac address
.ip = { 192, 168, 1, 31 }, // IP address
.sn = { 255, 255, 255, 0 }, // Subnet mask
.gw = { 192, 168, 1, 1 },
.dns = { 0, 0, 0, 0 },
.dhcp = NETINFO_STATIC };
wizchip_setnetinfo(&netInfo);
wizchip_getnetinfo(&netInfo);
while (1)
{
ret = socket(sn, Sn_MR_TCP, serverPort, 0x00); // STUCK HERE !
LED_On();
}
}