Skip to content

This MPLAB® X MCC example shows implementation of TCP/IP Lite Applications using Microchip ENC28J60 Ethernet Driver on an AVR Device

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-solutions/avr-tcpip-lite-enc28j60-solution

Repository files navigation

Microchip Technologies Inc.

TCP/IP Lite Solutions for AVR® Using ENC28J60

Introduction

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.

Hardware Requirements

  1. AVR64DD32 Curiosity Nano
  2. ETH Click
  3. Curiosity Nano Base for Click Boards™
  4. RJ45 Network Connector Cable
  5. USB 2.0 to Micro B Cable

Software Requirements

  1. MPLAB X IDE v6.10 or later
  2. MPLAB XC8 Compiler v2.41 or later
  3. MPLAB Code Configurator (MCC) v5.3.7 or later
  4. MCC Melody Core v5.5.7 or later
  5. Ethernet Drivers Library v6.0.0
  6. TCP/IP Lite Library v5.0.0
  7. Microchip TCP/IP Demo GUI
  8. Wireshark Network Analyzer Tool

Related Documentation

  1. AVR64DD32 Data Sheet
  2. ENC28J60
  3. Ethernet Drivers Library Release Notes
  4. TCP/IP Lite Library Release Notes

Hardware Setup

  1. 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.
  2. 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.
    AVR_setup

TCP/IP Client Solution

  1. Open MPLAB X IDE.

  2. Select File>Open Project>enc28j60-avr-tcpclient.X.

  3. Right click enc28j60-avr-tcpclient.X and select Set as Main Project.
    tcpclient_prosetup

  4. Open the Command Prompt/Terminal window, type ipconfig and press 'Enter' to get the system IP address.
    pcipaddress

  5. Modify the server IP address with your system IP address in the tcp_client_demo.c file under the TCP_Client_Initialize() function. Make a note of the remoteSocket.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;
}
  1. Click Clean and Build Main Project and make sure the project builds successfully.

  2. Click Make and Program Device Main Project and check that the programming is complete.

  3. 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.
    Wireshark_homepage

  4. Add the following filters: dhcp||icmp||tcp.port==65534.
    tcpclient_filter

  5. 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.
    tclient_listen tclient_connected

  6. 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.
    tcpclient_send1 tcpclient_send2

  • Switch back to Wireshark and observe the packets with your system IP address as the source
    send_wireshark

  • Click the Led 0 button in the TCP Server Demo tab to toggle the LED0 on the Curiosity Nano board
    tcpclient_led0

  • Switch back to Wireshark and observe the packets with your system IP address as the source
    ledon_wireshark

  1. Click the Disconnect button to close the TCP connection. A "Client disconnected" message will appear in the STATUS text box.
    tcpclient_disconnect

TCP/IP Server Solution

  1. Open MPLAB X IDE.

  2. Select File>Open Project>enc28j60-avr-tcpserver.X.

  3. Right click enc28j60-avr-tcpserver.X and select Set as Main Project.
    tcpserver_prosetup

  4. 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.
    Wireshark_homepage

  5. Add the following filters: dhcp||icmp||tcp.port==7.
    tcpserver_wfilter

  6. Click Clean and Build Main Project and make sure the project builds successfully.

  7. Click Make and Program Device Main Project and check that the programming is complete.

  8. 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'.
    tcpserver_ipaddress

  9. 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.
    tcpserver_connect tcpserver_connect

  10. 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.
    tcpserver_send1 tcpserver_send2

  • Switch back to Wireshark and observe the packets with your server IP address as the source to check the response
    tcpserver_send_wiresrk

  1. Click the Disconnect button to close the TCP connection. A "Connection Closed" message will appear in the STATUS text box.
    tcpserver_con_closed

TCP/IP UDP Solution

  1. Open MPLAB X IDE.

  2. Select File>Open Project>enc28j60-avr-udp.X.

  3. Right click enc28j60-avr-udp.X and select Set as Main Project.
    avr_udp_setup

  4. Open the Command Prompt/Terminal window, type ipconfig and press 'Enter' to get the system IP address.
    pcipaddress

  5. Modify the server IP address with your system IP address in the udp_demo.c file under the UDP_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;
}
  1. Make a note of the udpPacket.destinationPortNumber you set in the code (anything in the range of dynamic ports).

  2. 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.
    Wireshark_homepage

  3. Add the following filters: dhcp||icmp||udp.port==65531.
    udp_filter

  4. Click Clean and Build Main Project and make sure the project builds successfully.

  5. Click Make and Program Device Main Project and check that the programming is complete.

  6. 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'.
    udp_handshake

  7. 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).
    udp_listen

  • Assign server IP address as 10.14.5.128 (noted in Step 11). Click the Claim button.
    udp_claim

  • Click 1 under the LED section to toggle LED0 on the Curiosity Nano board and observe the Wireshark capture
    udp_led2
    udp_led_wireshark

  • Type your text in the Send Data box (e.g., 'Hello CNano') and click the Send button. Observe the packet in the Wireshark capture.
    udp_send1
    udp_send_wireshark

  1. Press the SW0 switch on the Curiosity Nano board. Observe the packet which says 'Hello World' in the Wireshark capture.
    udp_helloworld

About

This MPLAB® X MCC example shows implementation of TCP/IP Lite Applications using Microchip ENC28J60 Ethernet Driver on an AVR Device

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published