|
| 1 | +<!-- <a href="https://www.microchip.com"><img src="images/microchip.png" alt="Microchip" width=20% /></a> --> |
| 2 | + |
| 3 | +<a target="_blank" href="https://www.microchip.com/" id="top-of-page"> |
| 4 | + <picture> |
| 5 | + <source media="(prefers-color-scheme: light)" srcset="images/mchp_logo_light.png" width="350"> |
| 6 | + <source media="(prefers-color-scheme: dark)" srcset="images/mchp_logo_dark.png" width="350"> |
| 7 | + <img alt="Microchip Technologies Inc." src="https://www.microchip.com/content/experience-fragments/mchp/en_us/site/header/master/_jcr_content/root/responsivegrid/header/logo.coreimg.100.300.png/1605828081463/microchip.png"> |
| 8 | + </picture> |
| 9 | +</a> |
| 10 | + |
| 11 | +# TCP/IP Lite Solutions for PIC® Using ENC28J60 |
| 12 | + |
| 13 | +## Introduction |
| 14 | + |
| 15 | +This repository provides MPLAB® X IDE projects that are suitable for the PIC18F-Q10 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. |
| 16 | + |
| 17 | +## Hardware Requirements |
| 18 | + |
| 19 | +1. [PIC18F47Q10 Curiosity Nano Evaluation Kit](https://www.microchip.com/en-us/development-tool/dm182029) |
| 20 | +2. [ETH Click](https://www.mikroe.com/eth-click) |
| 21 | +3. [Curiosity Nano Base for Click Boards™](https://www.microchip.com/en-us/development-tool/AC164162) |
| 22 | +4. RJ45 Network Connector Cable |
| 23 | +5. USB 2.0 to Micro B Cable |
| 24 | + |
| 25 | +## Software Requirements |
| 26 | + |
| 27 | +1. [MPLAB X IDE v6.10 or later](https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide#tabs) |
| 28 | +2. [MPLAB XC8 Compiler v2.41 or later](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/downloads-documentation#XC8) |
| 29 | +3. [MPLAB Code Configurator (MCC) v5.3.7 or later](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator) |
| 30 | +4. MCC Melody Core v5.5.7 or later |
| 31 | +5. Ethernet Drivers Library v6.0.0 |
| 32 | +6. TCP/IP Lite Library v5.0.0 |
| 33 | +7. [Microchip TCP/IP Demo GUI](Microchip TCPIP Demo GUI.jar) |
| 34 | +8. [Wireshark Network Analyzer Tool](https://www.wireshark.org/) |
| 35 | + |
| 36 | +## Related Documentation |
| 37 | + |
| 38 | +1. [PIC18F47Q10 Data Sheet](https://www.microchip.com/en-us/product/PIC18F47Q10) |
| 39 | +2. [ENC28J60](https://www.microchip.com/en-us/product/ENC28J60) |
| 40 | +3. [Ethernet Drivers Library Release Notes](https://onlinedocs.microchip.com/oxy/GUID-F319A0CC-8179-4113-B2F3-AA69D1B2C216-en-US-4/GUID-8B345417-6295-49E6-ABEB-D2FA8A5D5561.html) |
| 41 | +4. [TCP/IP Lite Library Release Notes](https://onlinedocs.microchip.com/oxy/GUID-AD30B8D1-D966-45C9-950F-6B266508AA41-en-US-4/index.html) |
| 42 | + |
| 43 | +## Hardware Setup |
| 44 | + |
| 45 | +1. Mount the PIC18F47Q10 Curiosity Nano board on the Curiosity Nano Base for Click boards and power it on using a USB 2.0 to Micro B Cable. |
| 46 | +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. |
| 47 | +<br><img src="images/PIC_Setup.png" alt="PIC Setup" width=40% /> |
| 48 | + |
| 49 | +## TCP/IP Client Solution |
| 50 | + |
| 51 | +1. Open MPLAB X IDE. |
| 52 | +2. Select *File>Open Project>enc28j60-pic-tcpclient.X*. |
| 53 | +3. Right click ```enc28j60-pic-tcpclient.X``` and select Set as Main Project. |
| 54 | +<br><img src="images/project_setup.png" alt="project_setup" width=80% /> |
| 55 | + |
| 56 | + |
| 57 | +4. Open the Command Prompt/Terminal window, type ```ipconfig``` and press 'Enter' to get the system IP address. |
| 58 | +<br><img src="images/pcipaddress.png" alt="pcipaddress" width=80% /> |
| 59 | + |
| 60 | +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. |
| 61 | +``` |
| 62 | +void TCP_Client_Initialize(){ |
| 63 | + |
| 64 | + // Initialize the server IP address with your system IP address |
| 65 | + remoteSocket.addr.s_addr = MAKE_IPV4_ADDRESS(10, 14, 5, 127); |
| 66 | + remoteSocket.port = 65534; |
| 67 | +} |
| 68 | +``` |
| 69 | +6. Click **Clean and Build Main Project** and make sure the project builds successfully. |
| 70 | +7. Click **Make and Program Device Main Project** and check that the programming is complete. |
| 71 | +8. 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**. |
| 72 | +<br><img src="images/Wireshark_homepage.png" alt="Wireshark_homepage" width=80% /> |
| 73 | + |
| 74 | +9. Add the following filters: ```dhcp||icmp||tcp.port==65534```. |
| 75 | +<br><img src="images/tcpclient_filter.png" alt="tcpclient_filter" width=80% /> |
| 76 | + |
| 77 | +10. 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. |
| 78 | +<br><img src="images/tclient_listen.png" alt="tclient_listen" width=40% /> <img src="images/tclient_connected.png" alt="tclient_connected" width=40% /> |
| 79 | + |
| 80 | + |
| 81 | +11. After the connection is established: |
| 82 | +* 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. |
| 83 | +<br><img src="images/tcpclient_send1.png" alt="tcpclient_send1" width=40% /> <img src="images/tcpclient_send2.png" alt="tcpclient_send2" width=40% /> |
| 84 | + |
| 85 | +* Switch back to Wireshark and observe the packets with your system IP address as the source |
| 86 | +<br><img src="images/send_wireshark.png" alt="send_wireshark" width=80% /> |
| 87 | + |
| 88 | +* Click the **Led 0** button in the **TCP Server Demo** tab to toggle the LED0 on the Curiosity Nano board |
| 89 | +<br><img src="images/tcpclient_led0.png" alt="tcpclient_led0" width=40% /> |
| 90 | + |
| 91 | +* Switch back to Wireshark and observe the packets with your system IP address as the source |
| 92 | +<br><img src="images/ledon_wireshark.png" alt="ledon_wireshark" width=80% /> |
| 93 | + |
| 94 | +12. Click the **Disconnect** button to close the TCP connection. A "Client disconnected" message will appear in the STATUS text box. |
| 95 | +<br><img src="images/tcpclient_disconnect.png" alt="tcpclient_disconnect" width=40% /> |
| 96 | + |
| 97 | +## TCP/IP Server Solution |
| 98 | +1. Open MPLAB X IDE. |
| 99 | +2. Select *File>Open Project>enc28j60-pic-tcpserver.X*. |
| 100 | +3. Right click ```enc28j60-pic-tcpserver.X``` and select Set as Main Project. |
| 101 | +<br><img src="images/project_setup.png" alt="project_setup" width=80% /> |
| 102 | + |
| 103 | +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**. |
| 104 | +<br><img src="images/Wireshark_homepage.png" alt="Wireshark_homepage" width=80% /> |
| 105 | + |
| 106 | +5. Add the following filters: ```dhcp||icmp||tcp.port==7```. |
| 107 | +<br><img src="images/tcpserver_wfilter.png" alt="tcpserver_wfilter" width=80% /> |
| 108 | + |
| 109 | + |
| 110 | +6. Click **Clean and Build Main Project** and make sure the project builds successfully. |
| 111 | +7. Click **Make and Program Device Main Project** and check that the programming is complete. |
| 112 | +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'. |
| 113 | +<br><img src="images/tcpserver_ipaddress.png" alt="tcpserver_ipaddress" width=80% /> |
| 114 | + |
| 115 | +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. |
| 116 | +<br><img src="images/tcpserver_connect.png" alt="tcpserver_connect" width=40% /> <img src="images/tcpserver_connect2.png" alt="tcpserver_connect" width=40% /> |
| 117 | + |
| 118 | +10. After the connection is established: |
| 119 | +* 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. |
| 120 | +<br><img src="images/tcpserver_send1.png" alt="tcpserver_send1" width=40% /> <img src="images/tcpserver_send2.png" alt="tcpserver_send2" width=40% /> |
| 121 | + |
| 122 | +* Switch back to Wireshark and observe the packets with your server IP address as the source to check the response |
| 123 | +<br><img src="images/tcpserver_send_wiresrk.png" alt="tcpserver_send_wiresrk" width=80% /> |
| 124 | + |
| 125 | +11. Click the **Disconnect** button to close the TCP connection. A "Connection Closed" message will appear in the STATUS text box. |
| 126 | +<br><img src="images/tcpserver_con_closed.png" alt="tcpserver_con_closed" width=40% /> |
| 127 | + |
| 128 | +## TCP/IP UDP Solution |
| 129 | +1. Open MPLAB X IDE. |
| 130 | +2. Select *File>Open Project>enc28j60-pic-udp.X*. |
| 131 | +3. Right click ```enc28j60-pic-udp.X``` and select Set as Main Project. |
| 132 | +<br><img src="images/pic_udp_setup.png" alt="pic_udp_setup" width=80% /> |
| 133 | + |
| 134 | +4. Open the Command Prompt/Terminal window, type ```ipconfig``` and press 'Enter' to get the system IP address. |
| 135 | +<br><img src="images/pcipaddress.png" alt="pcipaddress" width=80% /> |
| 136 | + |
| 137 | +5. Modify the server IP address with your system IP address in the ```udp_demo.c``` file under the ```UDP_Demo_Initialize()``` function. |
| 138 | +``` |
| 139 | +void UDP_Demo_Initialize(void) |
| 140 | +{ |
| 141 | + //Initialize the Destination IP address with your PC's IP address and Destination Port |
| 142 | + |
| 143 | + /* UDP Packet Initializations*/ |
| 144 | + udpPacket.destinationAddress = MAKE_IPV4_ADDRESS(10,14,5,127); |
| 145 | + udpPacket.destinationPortNumber = 65531; |
| 146 | + |
| 147 | + udpPacket.sourcePortNumber = 65533; |
| 148 | +} |
| 149 | +``` |
| 150 | +6. Make a note of the ```udpPacket.destinationPortNumber``` you set in the code (anything in the range of dynamic ports). |
| 151 | +7. 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**. |
| 152 | +<br><img src="images/Wireshark_homepage.png" alt="Wireshark_homepage" width=80% /> |
| 153 | + |
| 154 | +8. Add the following filters: ```dhcp||icmp||udp.port==65531```. |
| 155 | +<br><img src="images/udp_filter.png" alt="udp_filter" width=80% /> |
| 156 | + |
| 157 | +9. Click **Clean and Build Main Project** and make sure the project builds successfully. |
| 158 | +10. Click **Make and Program Device Main Project** and check that the programming is complete. |
| 159 | +11. 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'. |
| 160 | +<br><img src="images/udp_handshake.png" alt="udp_handshake" width=80% /> |
| 161 | + |
| 162 | +12. Open Microchip TCP/IP Demo GUI: |
| 163 | +* 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). |
| 164 | +<br><img src="images/udp_listen.png" alt="udp_listen" width=40% /> |
| 165 | + |
| 166 | +* Assign server IP address as **10.14.5.128** (noted in Step 11). Click the **Claim** button. |
| 167 | +<br><img src="images/udp_claim.png" alt="udp_claim" width=40% /> |
| 168 | + |
| 169 | +* Click **1** under the LED section to toggle LED0 on the Curiosity Nano board and observe the Wireshark capture |
| 170 | +<br><img src="images/udp_led2.png" alt="udp_led2" width=40% /> |
| 171 | +<br><img src="images/udp_led_wireshark.png" alt="udp_led_wireshark" width=80% /> |
| 172 | + |
| 173 | + |
| 174 | +* Type your text in the Send Data box (e.g., 'Hello CNano') and click the **Send** button. Observe the packet in the Wireshark capture. |
| 175 | +<br><img src="images/udp_send1.png" alt="udp_send1" width=40% /> |
| 176 | +<br><img src="images/udp_send_wireshark.png" alt="udp_send_wireshark" width=80% /> |
| 177 | + |
| 178 | +13. Press the SW0 switch on the Curiosity Nano board. Observe the packet which says 'Hello World' in the Wireshark capture. |
| 179 | +<br><img src="images/udp_helloworld.png" alt="udp_helloworld" width=80% /> |
0 commit comments