Writing to socket registers

Hello,

our company wants to use the WIZ820io (W5200) for TCP-communication in a product. At the implementation we can’t set all the socket registers to the right value. For example writing the source port register works fine, but writing to the destination port register doesn’t work. So the connunication via SPI works correctly (also checked with oscilloscope).

Is there a special command we have to use, before we can access the destination port registers?
Or is there a special order the commands have to be sent?

Kind regards
Lance

Hi, Lance.

We can access all socket registers using same SPI command.
(IINCHIP_WRITE and IINCHIP_READ functions in Ref. codes)
How about the other network Information registers? (MAC, IP, Gateway, Subnet … and etc.)
Please check the register map in source codes again.

Regards,
Eric.

Hi,

at the socket registers I can write the mode, command and source port register. But if I write to the destination hardware address, the destination IP-address or the destination port register, I can’t read these values out of these registers. Are these registers “double buffered” as mentioned here: Problem writing in the Sn_DIPR registers

But the problem is, the connection is set up with the wrong parameters. For example I write the destination IP to 192.168.0.20. Then I read the IP register with 0.0.0.0 and after setting the connect command the W5200 trys to connect to 0.0.0.0 (analysed by wireshark).

Thank you for your help.
Best regards,

Lance

The destination IP address (and dest port) is possible to read after send (UDP) / connect (TCP - established) complete.
if else, read values are 0.0.0.0. it’s correct.
please refer to connect() function in W5200 reference code.

Regards,
Eric.

Can you please just post the relevant code to show us how to write to the destination ip address, mac address and port please. I can use the device is server mode easily, no luck in client mode. The connect() function is very overloaded and difficult to follow! You may have notices this problem has caused issues for many users.

Thanks,

dp

Hi, dp.
Please refer to next code.
This is the part of ‘connect’ function in W5200 reference code.
It’s very simple, just write the destIP and destPort to W5200 using SPI interface.

/* socket.c */
uint8 connect(SOCKET s, uint8 * addr, uint16 port)
{
...
		// set Destination IP and Port
		IINCHIP_WRITE(Sn_DIPR0(s),addr[0]);
		IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]);
		IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]);
		IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]);
		IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8));
		IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff));
...
}

What code are you using?
If you attach your code - connect function - in this post, we are possible to help you.

Regards,
Eric.