This repository provides MPLAB® X IDE projects that are suitable for the AVR Dx product family and contain solutions for User Datagram Protocol (UDP), as well as Transmission Control Protocol/Internet Protocol (TCP/IP) Client and Server demo applications.
- AVR64DD32 Curiosity Nano
- ETH Click
- Curiosity Nano Base for Click Boards™
- RJ45 Network Connector Cable
- USB 2.0 to Micro B Cable
- MPLAB X IDE v6.10 or later
- MPLAB XC8 Compiler v2.41 or later
- MPLAB Code Configurator (MCC) v5.3.7 or later
- MCC Melody Core v5.5.7 or later
- Ethernet Drivers Library v6.0.0
- TCP/IP Lite Library v5.0.0
- Microchip TCP/IP Demo GUI
- Wireshark Network Analyzer Tool
- AVR64DD32 Data Sheet
- ENC28J60
- Ethernet Drivers Library Release Notes
- TCP/IP Lite Library Release Notes
- Mount the AVR64DD32 Curiosity Nano board on the Curiosity Nano Base for Click boards and power it on using a USB 2.0 to Micro B Cable.
- Mount the ETH Click board on the mikroBUS™ socket 1 of Curiosity Nano Base and connect to a network switch using a RJ45 network connector cable.
-
Open MPLAB X IDE.
-
Select File>Open Project>enc28j60-avr-tcpclient.X.
-
Right click
enc28j60-avr-tcpclient.X
and select Set as Main Project. -
Open the Command Prompt/Terminal window, type
ipconfig
and press 'Enter' to get the system IP address. -
Modify the server IP address with your system IP address in the
tcp_client_demo.c
file under theTCP_Client_Initialize()
function. Make a note of theremoteSocket.port
set in the code.
void TCP_Client_Initialize(){
// Initialize the server IP address with your system IP address
remoteSocket.addr.s_addr = MAKE_IPV4_ADDRESS(10, 14, 5, 127);
remoteSocket.port = 65534;
}
-
Click Clean and Build Main Project and make sure the project builds successfully.
-
Click Make and Program Device Main Project and check that the programming is complete.
-
Open Wireshark Network Analyser Tool with Administrator Privileges. From the Capture menu, select an interface to which the board and PC are connected. Click Start capturing packets.
-
Open Microchip TCP/IP Demo GUI. Go to the TCP Server Demo tab and assign the port number as 65534 (noted in Step 5), then click the Listen button. The status of the TCP connection is printed in the STATUS text box.
-
After the connection is established:
-
Type your text in the Send text box (e.g., 'Hello CNano') and click the Send button. The text sent is displayed in the Sent/Received Data box.
-
Switch back to Wireshark and observe the packets with your system IP address as the source
-
Click the Led 0 button in the TCP Server Demo tab to toggle the LED0 on the Curiosity Nano board
-
Switch back to Wireshark and observe the packets with your system IP address as the source
- Click the Disconnect button to close the TCP connection. A "Client disconnected" message will appear in the STATUS text box.
-
Open MPLAB X IDE.
-
Select File>Open Project>enc28j60-avr-tcpserver.X.
-
Right click
enc28j60-avr-tcpserver.X
and select Set as Main Project. -
Open Wireshark Network Analyser Tool with Administrator Privileges. From the Capture menu, select an interface to which the board and PC are connected. Click Start capturing packets.
-
Click Clean and Build Main Project and make sure the project builds successfully.
-
Click Make and Program Device Main Project and check that the programming is complete.
-
Switch to Wireshark Network Analyser Tool and wait to receive the Dynamic Host Configuration Protocol (DHCP) handshake packets. Click DHCP ACK and expand the 'Dynamic Host Configuration Protocol' field to reveal the details. Make a note of the IP address in 'Your (client) IP address'.
-
Open Microchip TCP/IP Demo GUI. Go to the TCP Client Demo tab and assign the port number as 7 and server IP address as 10.14.5.95 (noted in Step 8). Click the Connect button. The status of the TCP connection is printed in the STATUS text box.
-
After the connection is established:
-
Type your text in the Send text box (e.g., 'Hello CNano') and click the Send button. The text sent is displayed in the Sent/Received Data box.
-
Switch back to Wireshark and observe the packets with your server IP address as the source to check the response
- Click the Disconnect button to close the TCP connection. A "Connection Closed" message will appear in the STATUS text box.
-
Open MPLAB X IDE.
-
Select File>Open Project>enc28j60-avr-udp.X.
-
Right click
enc28j60-avr-udp.X
and select Set as Main Project. -
Open the Command Prompt/Terminal window, type
ipconfig
and press 'Enter' to get the system IP address. -
Modify the server IP address with your system IP address in the
udp_demo.c
file under theUDP_Demo_Initialize()
function.
void UDP_Demo_Initialize(void)
{
//Initialize the Destination IP address with your PC's IP address and Destination Port
/* UDP Packet Initializations*/
udpPacket.destinationAddress = MAKE_IPV4_ADDRESS(10,14,5,127);
udpPacket.destinationPortNumber = 65531;
udpPacket.sourcePortNumber = 65533;
}
-
Make a note of the
udpPacket.destinationPortNumber
you set in the code (anything in the range of dynamic ports). -
Open Wireshark Network Analyser Tool with Administrator Privileges. From the Capture menu, select an interface to which the board and PC are connected. Click Start capturing packets.
-
Click Clean and Build Main Project and make sure the project builds successfully.
-
Click Make and Program Device Main Project and check that the programming is complete.
-
Switch to Wireshark Network Analyser Tool and wait to receive the Dynamic Host Configuration Protocol (DHCP) handshake packets. Click DHCP ACK and expand 'Dynamic Host Configuration Protocol' field to reveal the details. Make a note of the IP address in 'Your (client) IP address'.
-
Open Microchip TCP/IP Demo GUI:
-
Go to the UDP tab and assign the port number as 65531 (noted in Step 5). Click the Listen button (Click 'Allow Access' if a warning occurs).
-
Assign server IP address as 10.14.5.128 (noted in Step 11). Click the Claim button.
-
Click 1 under the LED section to toggle LED0 on the Curiosity Nano board and observe the Wireshark capture
-
Type your text in the Send Data box (e.g., 'Hello CNano') and click the Send button. Observe the packet in the Wireshark capture.