By setting some register and memory operation, W5500 provides internet connectivity. This chapter describes how it can be operated.
You must check PHY LINK (0 bit of PHYCFGR) before attempting to make a network connection using sockets.
For the W5500 operation, select and utilize appropriate registers shown below.
- Mode Register (MR)
- Interrupt Mask Register (IMR)
- Retry Time-value Register (RTR)
- Retry Count Register (RCR)
For more information of above registers, refer to the “Register Descriptions.”
Basic network information setting for communication: It must be set the basic network information.
- SHAR(Source Hardware Address Register)
- It is prescribed that the source hardware addresses, which is set by SHAR, use unique hardware addresses (Ethernet MAC address) in the Ethernet MAC layer. The IEEE manages the MAC address allocation. The manufacturer which produces the network device allocates the MAC address to product.
- Details on MAC address allocation refer to the website as below.
- GAR(Gateway Address Register)
- SUBR(Subnet Mask Register)
- SIPR(Source IP Address Register)
This stage sets the socket tx/rx memory information. The base address and mask address of each socket are fixed and saved in this stage.
In case of, assign 2KB rx, tx memroy per SOCKET
After the initialization process, W5500 can transmit and receive the data with others by ‘open’ the SOCKET of TCP, UDP, IPRAW, and MACRAW mode. The W5500 supports the independently and simultaneously usable 8 SOCKETS. In this section, the communication method for each mode will be introduced.
The TCP is a connection-oriented protocol. The TCP make the connection SOCKET by using its own IP address, port number and destination IP address, port number. Then transmits and receives the data by using this SOCKET. Methods of making the connection to SOCKET are “TCP SERVER” and “TCP CLIENT”. It is divided by transmitting the connect-request (SYN packet). The “TCP SERVER” listens to the connect-request from the “TCP CLIENT”, and makes connection SOCKET by accepting the transmitted connect-request (Passive-open). The “TCP CLIENT” transmits the connect-request first to “TCP SERVER” to make the connection (Active-open).
SOCKET initialization is required for TCP data communication. The initialization is opening the SOCKET. The SOCKET opening process selects one SOCKET from 8 SOCKETS of the W5500, and sets the protocol mode (Sn_MR) and Sn_PORT0 which is source port number (Listen port number in “TCP SERVER”) in the selected SOCKET, and then executes OPEN command. After the OPEN command, if the status of Sn_SR is changed to SOCK_INIT, the SOCKET initialization process is completed. The SOCKET initialization process is identically applied in “TCP SERVER” and “TCP CLIENT.”The Initialization process of Socket n in TCP mode is shown below.
After W5500 accepts the command, the Sn_CR register is automatically cleared to 0x00. Even though Sn_CR is cleared to 0x00, the command is still being processed. To check whether the command is completed or not, please check the Sn_IR or Sn_SR.
Run as “TCP SERVER” by LISTEN command.
When the status of Sn_SR is SOCK_LISTEN, if it receives a SYN packet, the status of Sn_SR is changed to SOCK_SYNRECV and transmits the SYN/ACK packet. After that, the Socket n makes a connection. After it makes the connection of Socket n , it enables the data communication. There are two methods to confirm the connection of Socket n .
Confirm the reception of the TCP data.
The First method: set the Sn_IR(RECV) to ‘1’ whenever you receive a DATA packet. If the host receives the next DATA packet without setting the Sn_IR(RECV) as ‘1’ in the prior DATA packet, it cannot recognize the Sn_IR(RECV) of the next DATA packet. This is due to the prior Sn_IR(RECV) and next Sn_IR(RECV) being overlapped. So this method is not recommended if the host cannot perfectly process the DATA packets of each Sn_IR(RECV).
In this process, it processes the TCP data which was received in the Internal RX memory. At the TCP mode, the W5500 cannot receive the data if the size of received data is larger than the RX memory free size of Socket n . If the prior stated condition is happened, the W5500 holds on to the connection (pauses), and waits until the RX memory’s free size is larger than the size of the received data.
The size of the transmit data cannot be larger than assigned internal TX
memory of Socket n. If the size of transmit data is larger than
configured MSS, it is divided by size of MSS and transmits. To transmit
the next data, user must check the completion of prior SEND command. An
error may occur if the SEND command executes before completion of prior
SEND command. The larger the data size, the more time to complete the
SEND command. So the user should properly divide the data to transmit.
To check the completion of the SEND command, it should be check that the send data length is equal with the actual sent data length. The actual sent data length is calculated by the difference of the Sn_TX_RD before and after performing the SEND command. If the actual sent data is less than the send data length, the SEND command is retried for sending the left data. The send process is therefore completed the SENDwhen the sum of the actual sent data is equal the send data length. A simple example of the send process is as below
Ex) Send Data Length Size= 10,
- Execute SEND Command with send data length
- Calculate the actual sent data length
- If the actual sent data length is 7 (= Sn_TX_RD_after_SEND-Sn_TX_RD_befor_SEND),
- the left Data length= 3
- Retry SEND Command until the sum of the actual sent data length is
same the send data length.
Note: Don’t copy data until the sum of the actual sent data length is the send data length.
Check if the Disconnect-request(FIN packet) has been received. User can confirm the reception of FIN packet as below.
When the user does not need data communication with others, or receives a FIN packet, disconnect the connection SOCKET.
Confirm that the Socket n is disconnected or closed by DISCON or close command.
The timeout can occur by Connect-request(SYN packet) or its response(SYN/ACK packet), the DATA packet or its response(DATA/ACK packet), the Disconnect request FIN packet) or its response(FIN/ACK packet) and transmission all TCP packet. If it cannot transmit the above packets within ‘timeout’ which is configured at RTR and RCR, the TCP final timeout(TCPTO) occurs and the state of Sn_SR is set to SOCK_CLOSED. Confirming method of the TCPTO is as below:
It can be used to close the Socket n , which disconnected by disconnect-process, or closed by TCPTO or closed by host’s need without disconnect-process.
It is same as TCP server except ‘CONNECT’ state. User can refer to the above "TCP SERVER” section.
Transmit the connect-request (SYN packet) to “TCP SERVER”. It may occurs the timeout such as ARPTO, TCPTO when make the “connection SOCKET” with “TCP SERVER”