WIZnet Developer Forum

Can't get Wiz5500 to communicate with pc via Ethernet

Good evening, I have laid out a pcb with an W5500 and an Atmega256RFR2, the W5500 implementation is straight from the example using the jack with magnetics for a smaller footprint, after some initial problems with the SPI config I can talk with the chip via SPI and do the init routine, but whatever I do/change in code I can’t get it so send back even one single packet back(I have been monitorizing the ethernet with Wireshark).
I have already tried a couple “libs” that build on top of Wiznet own lib/driver, but none gets me anywhere.

My printf inside TCP_Server always returns 0x14 and nothing else, reading back the NetConf values from the chip with TCP_Server running in the main loop I get this:

=== NET CONF : STATIC === ====== HW ID : 4 ====== MAC : 00:14:A3:72:17:3F IP : 192.168.1.2 GW : 192.168.1.1 SN : 255.255.255.0 =======================================

I really cant understand if this an hardware fail, or some software problem, I can probe the TX+/- and RX+/- lines that go to the mag jack, but with a 100Mhz scope I cant really “see” anything right or wrong with them, if I disconnect the cable I can see a series os pulses on TXN/TXP and nothing on RXP/RXN, expected, at least from my understanding.

I will also attach a couple print-screens from my layout and schematic.
About that, I swaped MISO and MOSI lines(dohh), already taken care of, and forgot the load caps on the 25Mhz crystal because I had an oscillator in there first, the caps where also added right next to the crystal and its indeed oscillating at 25Mhz.

Using this code:

[code]void TCP_Server(void){
int32_t ret;
uint16_t size = 0, sentsize = 0;
int16_t funcVal = 0;

//uartPutsP("\nTCP_Server\n");
// Get status of socket
funcVal = getSn_SR(SOCK_ID_TCP);
sprintf(gPtrintBuff, "\ngetSn_SR(%i):  %#02x\n", SOCK_ID_TCP, funcVal);
uartPuts(gPtrintBuff);

switch(funcVal){
	// Connection established
	case SOCK_ESTABLISHED :{
		uartPutsP("\nScoket estabilished\n");
		// Check interrupt: connection with peer is successful
		if(getSn_IR(SOCK_ID_TCP) & Sn_IR_CON){
			// Clear corresponding bit
			setSn_IR(SOCK_ID_TCP,Sn_IR_CON);
		}

		// Get received data size
		if((size = getSn_RX_RSR(SOCK_ID_TCP)) > 0){
			// Cut data to size of data buffer
			if(size > DATA_BUF_SIZE){
				size = DATA_BUF_SIZE;
			}

			// Get received data
			ret = recv(SOCK_ID_TCP, gDATABUF, size);

			// Check for error
			if(ret <= 0){
				return;
			}

			// Send echo to remote
			sentsize = 0;
			while(size != sentsize){
				ret = send(SOCK_ID_TCP, gDATABUF + sentsize, size - sentsize);
				
				// Check if remote close socket
				if(ret < 0){
					close(SOCK_ID_TCP);
					return;
				}

				// Update number of sent bytes
				sentsize += ret;
			}
		}
		break;
	}

	// Socket received the disconnect-request (FIN packet) from the connected peer
	case SOCK_CLOSE_WAIT :{
		// Disconnect socket
		if((ret = disconnect(SOCK_ID_TCP)) != SOCK_OK){
			
			
			return;
		}

		break;
	}

	// Socket is opened with TCP mode
	case SOCK_INIT :{
		uartPutsP("SOCK_INIT\n");
		// Listen to connection request
		if( (ret = listen(SOCK_ID_TCP)) != SOCK_OK){
			
			return;
		}

		break;
	}

	// Socket is released
	case SOCK_CLOSED:{
		// Open TCP socket
		if((ret = socket(SOCK_ID_TCP, Sn_MR_TCP, PORT_TCP, 0x00)) != SOCK_ID_TCP){
			return;
		}

		break;
	}

	default:{
		break;
	}
}

}

// brief Handle UDP socket state.
void UDP_Server(void)
{
int32_t ret;
uint16_t size, sentsize;
uint8_t destip[4];
uint16_t destport;

// Get status of socket
switch(getSn_SR(SOCK_ID_UDP)){
	// Socket is opened in UDP mode
	case SOCK_UDP:{
		// Get received data size
		if((size = getSn_RX_RSR(SOCK_ID_UDP)) > 0){
			// Cut data to size of data buffer
			if(size > DATA_BUF_SIZE){
				size = DATA_BUF_SIZE;
			}

			// Get received data
			ret = recvfrom(SOCK_ID_UDP, gDATABUF, size, destip, (uint16_t*)&destport);

			// Check for error
			if(ret <= 0){
				return;
			}

			// Send echo to remote
			size = (uint16_t) ret;
			sentsize = 0;
			while(sentsize != size){
				ret = sendto(SOCK_ID_UDP, gDATABUF + sentsize, size - sentsize, destip, destport);
				if(ret < 0){
					return;
				}
				// Update number of sent bytes
				sentsize += ret;
			}
		}
		break;
	}

	// Socket is not opened
	case SOCK_CLOSED:{
		// Open UDP socket
		if((ret=socket(SOCK_ID_UDP, Sn_MR_UDP, PORT_UDP, 0x00)) != SOCK_ID_UDP){
			return;
		}

		break;
	}

	default :{
		break;
	}
}

}

// brief Initialize modules
static void W5500_Init(void){
// Set Tx and Rx buffer size to 2KB
uint8_t buffsize[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };

// Reset module
PMOD_PORT &= ~_BV(RST_W5500);		//Set Rst low
_delay_ms(500);						//Minimun of 500us, 10ms to be safe
PMOD_PORT |= _BV(RST_W5500);		//Set rst high
_delay_ms(1);

// Wizchip initialize
wizchip_init(buffsize, buffsize, 0, 0, cs_sel, cs_desel, 0, 0, spi_rb, spi_wb);

// Wizchip netconf
ctlnetwork(CN_SET_NETINFO, (void*) &gWIZNETINFO);
ctlwizchip(CW_SET_PHYCONF, (void*) &phyConf);

}[/code]



Thanks for your time.

EDIT:
Forgot to say that when I connect the ethernet cable ipconfig says that the IP is 169.254.68.247 and the subnet mask is 255.255.0.0 in case this extra info might help.

It seems you are trying direct connect? What is network topology?
I assume you talk about your PC on the network because 169.254 is IP address auto-assign feature of Microsoft Windows when it can not find DHCP server. And of course, with this address you will not see anything on the network using Wireshark installed on this PC. You have to ensure this PC is “included” into the network receiving proper IP address (e.g. 192.168.1.3) from gateway/DHCP server configured pool. As soon as both devices - W5500 and your PC are on the same network, only then you may be able to see some communication (except if you send broadcast UDP packets). Also, W5500 should have valid gateway listed in its gateway register, because W5500 relies on the gateway to perform specific actions (in particular perform ARP process).

Thanks for your response, so, I can’t just connect the Wiz directly to my pc for debug/code development?
I need to connect it into a switch(not that is a problem, just curious/want to know).

I dont understand a lot about network(ing), as you might already noted, and I have spent days around this little critter(in a good way), what would be a valid gateway value for W5500?

EDIT:
Connected the board into the switch, Wireshark up and running, there is no packet from the W5500 MAC adress, I have also tried changing the GW into the GW that the network assigns to my laptop(192.168.32.3), going by the TCP_Server state machine, I’m still stuck getting 0x14 from this line:
funcVal = getSn_SR(SOCK_ID_TCP);

And so the only thing that happens is that is says sock init(from the SOCK_INIT state) and nothing else happens.
I cant be sure if this is an hardware or software problem right now :confused:
I have already checked all the footprints a dozen times.

EDIT2:
It was indeed a problem with IP/gateway!
It finally works!
So happy that I can ping the board.
Thanks again for your insight.

Best regards.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.