Please refer to the following links for updated solutions for PICs and AVRs:
- https://github.com/microchip-pic-avr-solutions/pic-tcpip-lite-enc28j60-solution
- https://github.com/microchip-pic-avr-solutions/avr-tcpip-lite-enc28j60-solution
This repository provides MPLAB X IDE projects that can work out of the box. The solutions that are included in the repository include functionality for UDP, TCP Server and TCP Client Demos. Note that the TCP/IP Lite stack needs to be serviced every 1 second and the timer callback function needs to be set to 1 second.
More details can be found at the following links:
- MPLAB® X IDE v5.40 or later (microchip.com/mplab/mplab-x-ide)
- MPLAB® XC8 v2.20 or later (microchip.com/mplab/compilers)
- TCP/IP Lite Stack v3.0.0
- Ethernet Drivers Library v3.0.0
- TCPIP Demo GUI v2.0
- Wireshark Tool
- Curiosity High Pin Count (HPC) Development Board (dm164136)
- ETH Click by MikroE (ETH Click)
- PIC18F26K42
- Open MPLABX IDE.
- From the downloaded projects, open enc28j60-udp-solution.X.
- Open Windows Command Prompt application on your PC. Type “ipconfig” to get the IP address of your PC.
- Sending UDP Packets: In udp_demo.c, under the function UDP_DEMO_Send ():
- Modify the Destination IP address with PC’s IP address as noted in Step 3.
- Destination Port (anything in the range of dynamic ports)
5. Receiving UDP Packets: In Source Files\MCC generated files\ udpv4_port_handler_table.c, add the following code:
- In UDP_CallBackTable, add the following code to perform UDP Receive:
6. Click on Program Device to program the code to the device.
7. Launch Wireshark. From the Capture menu, click Options. Select an Interface from the list to which your board and PC are connected, click Start for capturing packets.
e.g.: Local Area Network
8. In Wireshark, set the filter field as bootp||arp||icmp.
9. In Wireshark, notice the DHCP packets handshake to get the device IP address.
10. In Wireshark, double click on “Offer” packet. Expand “Dynamic Host Configuration Protocol” to get the device IP address.
11. Open the Java application TCPIP_Demo.exe. Go to the UDP tab and assign the same port number as ‘DestPort’(65531). Click on ‘Listen’ button. Click “Allow Access” if warning occurs. Assign the IP Address of your board which is found from step 10(192.168.0.37). Click on ‘Claim’ button.
12. In Wireshark, set the filter field as bootp||udp.port==65531.
13. In Demo GUI, click on LED 1, 2, 3, 4 to light the LEDs D1, D2, D3, D4, respectively and observe the Wireshark capture.
14. In Demo GUI, type data(e.g.: “Hello World”) inside Send Data box and press the Send button and observe the Wireshark capture.
15. On the Curiosity HPC Board, press the Switch S1 and observe the Wireshark capture.
- Open MPLABX IDE.
- From the downloaded projects, open enc28j60-tcp-client-solution.X.
- Open Windows Command Prompt application on your PC. Type “ipconfig” to get the IP address of your PC.
- Modify the server IP address with PC's IP address in tcp_client_demo.c under function call TCP_Client_Initialize:
- Click on Program Device to program the code to the device.
- Open the Java application TCPIP_Demo.exe. Go to the TCP Server Demo tab and assign the port number as ‘65534’. Click on ‘Listen’ button. The status of the TCP Connection is printed inside the STATUS text box.
Also in Wireshark, observe the TCP packets by setting the filter “tcp.port == 65534”.
6. After the connection is established:
- Type text inside the Send text box and click on ‘Send’ button. The text sent is displayed inside the Sent/Received Data box.
Also in Wireshark, observe the TCP packets by setting the filter “tcp.port == 65534”
- Click on the Led buttons {0, 1, 2, 3, 4}. This will toggle LEDs on board.
Also in Wireshark, observe the TCP packets by setting the filter “tcp.port == 65534”
7. Push ‘Disconnect’ button, to close the TCP Connection. A client disconnected message will appear on the STATUS text box.
- Open MPLABX IDE.
- From the downloaded projects, open enc28j60-tcp-server-solution.X.
- Click on Program Device to program the code to the device.
- Launch Wireshark. From the Capture menu, click Options.
Select an Interface from the list to which your board and PC are connected, click Start for capturing packets.
e.g.: Local Area Network
5. In Wireshark, set the filter field as bootp||arp||icmp.
6. In Wireshark, notice the DHCP packets handshake to get the device IP address.
7. In Wireshark, double click on “Offer” packet. Expand “Dynamic Host Configuration Protocol” to get the device IP address.
8. Open the Java application TCPIP_Demo.exe. Go to the TCP Client Demo tab, assign the board IP address as Server IP address in the GUI from step 7. Assign the port number as ‘7’. Click on ‘Connect’ button. The status of the TCP Connection is printed inside the STATUS text box.
9. After the connection is established:
- Type text inside the Send text box and click on ‘Send’ button. The text sent is echoed and displayed inside the Sent/Received Data box.
- Also in Wireshark, observe the TCP packets by setting the filter “tcp.port == 7”
10. Push ‘Disconnect’ button, to close the TCP Connection. TCP server closing the connection message will appear on the STATUS text box.