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.
- 🌎 http://www.ieee.org/
- 🌎 http://standards.ieee.org/regauth/oui/index.shtml
- 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 UDP is a Connection-less protocol. It communicates without “connection SOCKET.” The TCP protocol guarantees reliable data communication, but the UDP protocol uses datagram communication which has no guarantees of data communication. Because the UDP does not use “connection SOCKET,” it can communicate with many other devices with the known host IP address and port number. This is a great advantage; communication with many others by using just one SOCKET, but also it has many problems such as loss of transmitted data, unwanted data received from others, etc. To avoid these problems and guarantee reliability, the host retransmits damaged data or ignores the unwanted data which is received from others. The UDP protocol supports unicast, broadcast, and multicast communication. It follows the below communication flow.
The unicast is one method of UDP communication. It transmits data to one destination at one time. On the other hand, the broadcast communication transmits data to all receivable destinations by using ‘broadcast IP address (255.255.255.255)’. For example, suppose that the user transmits data to destination A, B, and C. The unicast communication transmits each destination A, B, and C at each time. At this time, the ARPTO can also occur when the user gets the destination hardware address of destinations A, B and C. User cannot transmit data to destinations which have ARPTO. The broadcast communication can simultaneously transmit data to destination A, B and C at one time by using “255.255.255.255” or “local address | (~subnet address)” IP address. At this time, there is no need to get the destination hardware address about destination A, B and C, and also ARPTOis not occurred.
=> The Broadcast IP address can be obtained by performing a bit-wise
logical OR operation between the bit complement of the subnet mask and
the host’s IP address.
ex> If IP:”188.8.131.52” and the subnet mask:“255.255.255.0”, broadcast IP is “184.108.40.206”
|Bit Complement Subnet mask||000.000.000.255||00000000.00000000.00000000.11111111|
For the UDP data communication, SOCKET initialization is required; it opens the SOCKET. The SOCKET open process is as followed. At first, choose one SOCKET among the 8 SOCKETS of W5500, then set the protocol mode (Sn_MR(P3:P0)) of the chosen SOCKET and set the source port number Sn_PORT0 for communication. Finally, execute the OPEN command. After the OPEN command, the state of Sn_SR is changed to SOCK_UDP. Then the SOCKET initialization is complete.
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.
Check the reception of UDP data from destination. User can also check for received data via TCP communication. It is strongly recommended to use the second method because of the same reasoning from TCP. Please refer to the “TCP SERVER” section. TCP SERVER
Process the received UDP data in Internal RX memory.
The structure of received UDP data is as below.
The received UDP data consists of 8bytes PACKET-INFO, and DATA packet. The PACKETINFO contains transmitter’s information (IP address, Port number) and the length of DATA packet. The UDP can receive UDP data from many others. User can classify the transmitter by transmitter’s information of PACKET-INFO. It also receives broadcast SOCKET by using “255.255.255.255” IP address. So the host should ignore unwanted reception by analysis of transmitter’s information. If the DATA size of Socket n is larger than Internal RX memory free size, user cannot receive that DATA and also cannot receive fragmented DATA.
The size of DATA that the user wants to transmit cannot be larger than Internal TX memory. If it is larger than MTU, it is automatically divided by MTU unit and transmitted. The Sn_DIPR0 is set “255.255.255.255” when user wants to broadcast.
To transmit the next data, user must check that the prior SEND command is completed. The larger the data size, the more time to complete the SEND command. Therefore, the user must properly divide the data to transmit. The ARPTO can occur when user transmits UDP data. If ARPTO occurs, the UDP data transmission has failed.
If user doesn’t need the communication any more, close the Socket n.
The broadcast communication communicates with many and unspecified
others. But the multicast communication communicates with many specified
others who registered at a multicast-group. Suppose that A, B, and C are
registered at a specified multicast-group. If user transmits data to
multicast-group (contains A), B and C also receive the DATA for A. To
use multicast communication, the destination list registers to
multicast-group by using IGMP protocol. The multicast-group consists of
‘Group hardware address,’ ‘Group IP address,’ and ‘Group port number.’
User cannot change the ‘Group hardware address’ and ‘Group IP address.’
But the ‘Group port number’ can be changed.
The ‘Group hardware address’ is selected at the assigned range (From “01:00:5e:00:00:00”to “01:00:5e:7f:ff:ff”) and the ‘Group IP address’ is selected in D-class IP address (From “220.127.116.11” to “18.104.22.168”, please refer to the website; http://www.iana.org/assignments/multicast-addresses).
When selecting, the upper 23bit of 6bytes ‘Group hardware address’ and the 4bytes ‘Group IP address’ must be the same. For example, if the user selects the ‘Group IP address’ to “244.1.1.11,” the ‘Group hardware address’ is selected to “01:00:5e:01:01:0b.” Please refer to the “RFC1112” (http://www.ietf.org/rfc.html).
In the W5500, IGMP processing to register the multicast-group is internally (automatically) processed. When the user opens the Socket n with multicast mode, the “Join” message is internally transmitted. If the user closes it, the “Leave” message is internally transmitted. After the SOCKET opens, the “Report” message is periodically and internally transmitted when the user communicates.
The W5500 support IGMP version 1 and version 2 only. If user wants use an updated version, the host processes IGMP directly by using the IPRAW mode SOCKET.
Choose one SOCKET for multicast communication among 8 SOCKETS of W5500. Set the Sn_DHAR0 to ‘Multicast-group hardware address’ and set the Sn_DIPR0 to ‘Multicastgroup IP address.’ Then set the Sn_PORT0 and Sn_DPORT0 to ‘Multicast-group port number.’ Set the Sn_MR(P3:P0) to UDP and set the Sn_MR(MULTI) to ‘1.’ Finally, execute OPEN command. If the state of Sn_SR is changed to SOCK_UDP after the OPEN command, the SOCKET initialization is completed.
Refer to the “Unicast & Broadcast.” section.
Refer to the “Unicast & Broadcast.” section. Unicast & Broadcast
Since the user sets the information about multicast-group at SOCKET initialization, user does not need to set IP address and port number for destination any more. Therefore, copy the transmission data to internal TX memory and executes SEND command.
Since the host manages all protocol process for data communication, timeout cannot occur.
Refer to the “Unicast & Broadcast.” section. Unicast & Broadcast