W5300 DPORTR 값이 이상합니다.

W5300 16bit 로 사용하고 있습니다.

PC의 IP는 이며, W5300의 IP는 입니다.
W5300 에서는 loopback 를 사용하며
tcps 와 udps 가 동작하고 있습니다.

socket 0 = UDP
socket 1 = TCP

아래 메세지는 UDP 에서 recvfrom & sendto 를 수행한 다음
DPORTR 을 읽기 위한 출력 입니다.
아무리 해도 제대로된 값이 나오지 않아 아예 Sn_DHAR부터 6 word를 읽어 출력하였습니다.
getSn_DPORT2 가 6 word 읽는 매크로 입니다.

하지만, DHAR, DPORTR, DIPR 셋 중에서
DPORTR 만 값이 잘못 나옵니다.
실제 사용한 PC포트는 10000 인데 0x2710 입니다.
하지만 W5300의 DPORT 레지스터에는 0x2727 로 잘못된 값이이 들어 있습니다.

0:SOCK_UDP - : 10023(0x2727)
0:getSn_DPORT2 - 3CE1.A1BA.797D.2727.C0A8.230C

1:Connected - : -12337(0xCFCF)
1:getSn_DPORT2 - 3CE1.A1BA.797D.CFCF.C0A8.230C

TCP 소켓의 경우에도 동일 합니다.

소켓 번호를 4000, 5000, 6000, 7000 등등 변화해 보면서 접속해보면
DPORTR 의 상위바이트만 값이 정상이고 하위 바이트는 상위바이트와 같은 값이 들어있습니다.

어떻게 해야 DPORTR을 제대로 읽을 수 있습니까?
아니면 상대방 (클라이언트) 의 포트 번호를 어떻게 확인 가능할까요?

0x2710 is exact hexadecimal representation of the decimal 10000. Thus port number must be correct, but the display radix is different.

Edit: seems the above is the problem in the translator I used, and it was not a question :slight_smile: but a statement.

To my understanding, your application driving W5300 must set DPORT value. Thus value is writable. The datasheet says the following

Sn_DPORTR (SOCKETn Destination Port Register) [WO]

And WO means write only. This register is not designed to be readable, and value you read is not guaranteed to be correct by design :cry:

Hi, Eugeny

fully understand DPORTR is WO register
and thank you so much.

following is my test configuration.

[PC: TCP Client using port=10000 or others] ----connect to W5300----> [W5300: Listen port 5000]

my question is that how can i figure out client port number running on W5300 side firmware.

For TCP server mode you must set up socket’s source port for W5300 to listen on. When client successfully connects to W5300, socket’s destination port number is set automatically, you do NOT need to set it manually. This DPORTR port number is used by the W5300 socket to send packets to the client matching client’s socket properties so that client can understand its exact socket it received packet for.
This is really not covered by the datasheet. Datasheet only says that you must set source port, but nothing about what to do with destination port. The answer is: you do not need to do anything on destination port, it is already set properly when connection from the client is established.

Currently, communication between W5300 TCP server and PC client is normal.

DPORTR and destination port (PC client port) are different (except MSB), but communication is fine.

Wireshark shows exact port numbers.

I was just wondering if there is a way to know the port number of the PC client from the W5300 side firmware.

As you mentioned it wasn’t explained in the datasheet.

Thank you for your answer.