W5500evb UDP mode test and understanding-Xinhua Dragon Electronics

Source: Internet
Author: User

WIZnet has previously described the W5500evb in TCP mode of two (server and client) data transmission implementation process, then the Transmission Control Protocol, UDP is also very common, this non-connected protocol in more places to provide users with convenience, such as e-mail , QQ chat and receive messages ... Well, then learn today, the UDP mode on the W5500evb simple implementation.

An experimental hardware and its connection

Two-UDP experiment-related knowledge

The W5500 is an all-hardware TCP/IP embedded Ethernet controller that provides an easy-to-access Internet connection solution for embedded systems. W5500 integrates the TCP/IP protocol stack, 10/100m Ethernet Data Link layer (MAC) and Physical layer (PHY), the user does not have to pay special attention to TCP and UDP implementation process, only need to configure and query the appropriate work. The following is the main explanation of TCP and UDP differences for reference

1 connection-based vs. no connection

The Tcp-Transmission Control Protocol provides a connection-oriented, reliable byte-stream service. Before the customer and the server Exchange data with each other, a TCP connection must be established between the two parties before the data can be transferred. TCP provides time-out re-send, discard duplicate data, test data, flow control and other functions to ensure that data can be transmitted from one end to the other.

The transfer process for each packet is to establish a link, data transfer, and then clear the link. The packet does not contain a destination address. The end and the originator are not only consistent in order, but also in the same content. It is highly reliable.

udp-User Datagram Protocol is non-connected, each packet has a complete source, destination address and group number, respectively, in the network independent transmission, transmission regardless of its order, the data arrives at the end of the sorting assembly, in case of loss, error and disorder, through the request to re-send to solve. It is relatively efficient and is a simple transport layer protocol for datagram. UDP does not provide reliability, it simply sends the application to the IP layer's datagram, but does not guarantee that it will reach its destination. Because UDP does not have to establish a connection between the client and the server before transmitting the datagram, and there is no mechanism such as time-out retransmission, the transmission speed is very fast.

2, the requirements of the system resources (TCP more, less UDP)

3, the UDP program structure is relatively simple

4. Stream mode and datagram mode

5, TCP guarantees data correctness, UDP may drop packets, TCP guaranteed Data order, UDP does not guarantee

6, TCP is a reliable byte stream service, UDP does not provide a reliable mechanism for IP protocol, flow control and error recovery functions, etc.

For TCP and UDP applications

Introduction of three key procedures

3.1 Compilation tool for IAR5.4

3.2 1-5 UDP experimental routines to implement the function:

In UDP mode, the destination IP address and port are continuously sent data test:ecountr, and if the destination IP is received, the information will be copied back. In this case, the network cable is connected directly to the PC machine. PC IP as the target IP, note that the PC IP and eVB IP are in the same network segment.

3.3 Experimental Function Flow:

Step 1: Initialize STM32 clock GPIO USART, etc.

STEP2: Initialize SPI and W5500

STEP3: Configure MAC address native IP address subnet mask default gateway and other information, after configuration, then read the above information, and print to the serial port

STEP4: Initialize 8 sockets

STEP5: Real-time Read socket 0 status, if the socket 0 is closed, then open socket 0 as the UDP port. If the read socket 0 is UDP mode, the destination IP address and port are sent the data test:ecountr, and if the destination IP is received to send information, copy the information to reply.

3.4 Molecular Program explanation

Uint8 GETSN_SR (socket s)//Get socket s status

{

Return Iinchip_read (SN_SR (s));

}

Implementation of/*W5500 SPI communication protocol

The W5500 SPI data frame has three data segment control segments and data segments in turn */

Uint8 Iinchip_read (UInt32 ADDRBSB)

{

Uint8 data = 0;

Iinchip_isr_disable (); Turn off interrupts

Iinchip_csoff (); Cs=0, SPI enable chip selection

Iinchip_spisenddata ((ADDRBSB & 0x00ff0000) >>16);//write address segment High 8-bit addresses byte 1

Iinchip_spisenddata ((ADDRBSB & 0x0000FF00) >> 8);//write to address segment low 8 bits address byte 2

Iinchip_spisenddata ((ADDRBSB & 0x000000f8));//write to control segment in read mode

data = Iinchip_spisenddata (0x00); Write Data segment

/*SPI Master-Slave interface is equivalent to a cyclic serial shift register, the host (STM32) sends data 0x00, slave (W5500) will take over 0x00, and move the data into the host, the function return value is read data */

Iinchip_cson (); Cs=1, SPI end loss-of-energy chip selection

Iinchip_isr_enable (); Turn off interrupt

return data;

}

The SN_SR (s) function prototype is (0x000308 + (ch<<5)) for the purpose of acquiring the State register address of the socket s, similar functions have many, mainly to obtain the register absolute address

Where 0x0003 is the state register 16-bit offset address of socket n, which is the address segment of the SPI communication

(ch<<5) is the control section, which indicates the attribution of the offset address, the read-write mode and

SPI operating mode, 08 = 00001000

SPI Control Section:

  

BSB4 BSB3 BSB2 is ch means the address is the State register address of Socket CH

BSB1 BSB0 for Select register type 01 refers to select Socket register

rwb:0 Read 1 Write

OM1 OM0 control SPI for variable data length operation or fixed data length operation mode

00 variable data Length (variable data length operating mode recommended)

01 1 byte Data length

10 2 Byte data length

11 4 Byte Data length

Four program download and experiment phenomena

4.1 Downloads

Hit Flash loader find eVB com port, press BOOT0 key to make it 1, enter the ISP mode to download.

4.2 Observation of experimental phenomena

Run the network debugging assistant software,

PC ip:192.168.1.119 Port 8080

Development Board ip:192.168.1.90 Port 8080

The normal Development Board sends the test and counts, replies when the message is received, shuts down the PC port and opens again, and finds that some UDP data has been lost, which is not the same as the TCP mode. This indicates that UDP drops packets under certain circumstances and is not available for high data integrity requirements.

Five summary

This routine can be used to learn how to configure W5500 to work in UDP mode via the SPI interface.

Welcome to login, Xinhua dragon Electronic website To see more wiznet W5500 information: http://www.xhl.com.cn/ylogin/w5500.asp

W5500evb UDP mode test and understanding-Xinhua Dragon Electronics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.