Mbed library for ENC28J60 Ethernet modules. Full support for TCP/IP and UDP Server, Client and HTTP server (webserver). DHCP and DNS is included.

Dependents:   mBuino_ENC28_MQTT Nucleo_Web_ENC28J60 Nucleo_Web_ENC28J60_ADC Serial_over_Ethernet ... more

Library for ENC28J60 Ethernet modules.

/media/uploads/hudakz/enc28j60_module01.jpg

Ported to mbed from Norbert Truchsess's UIPEthernet library for Arduino. Thank you Norbert!

  • Full support for persistent (streaming) TCP/IP and UDP connections Client and Server each, ARP, ICMP, DHCP and DNS.
  • Works with both Mbed OS 2 and Mbed OS 5.

Usage:

  • Import the library into your project.
  • Add #include "UipEthernet.h" to main.cpp
  • Create one instance of the UipEthernet class initialized with the MAC address you'd like to use and SPI pins of the connected Mbed board.

Example programs:

Import programWebSwitch_ENC28J60

HTTP Server serving a simple webpage which enables to remotely turn a digital output on/off. Compile, download, run and type 'IP_address/secret/' (don't forget the last '/') into your web browser and hit ENTER.

Import programHTTPServer_Echo_ENC28J60

A simple HTTP server echoing received requests. Ethernet connection is over an ENC28J60 board. Usage: Type the server's IP address into you web browser and hit <ENTER>.

Import programTcpServer_ENC28J60

Simple TCP/IP Server using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programTcpClient_ENC28J60

Simple TCP/IP Client using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programUdpServer_ENC28J60

Simple UDP Server using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programUdpClient_ENC28J60

Simple UDP Client using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programMQTT_Hello_ENC28J60

MQTT Client example program. Ethernet connection is via an ENC28J60 module.

Committer:
hudakz
Date:
Thu Jul 23 15:30:54 2020 +0000
Revision:
18:8d5738a6646e
Parent:
14:7648334eb41b
Mbed library for ENC28J60 Ethernet modules.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 9:a156d3de5647 1 /*
hudakz 9:a156d3de5647 2 Enc28J60Network.h
hudakz 9:a156d3de5647 3 UIPEthernet network driver for Microchip ENC28J60 Ethernet Interface.
hudakz 9:a156d3de5647 4
hudakz 9:a156d3de5647 5 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
hudakz 9:a156d3de5647 6 All rights reserved.
hudakz 9:a156d3de5647 7
hudakz 9:a156d3de5647 8 based on enc28j60.c file from the AVRlib library by Pascal Stang.
hudakz 9:a156d3de5647 9 For AVRlib See http://www.procyonengineering.com/
hudakz 9:a156d3de5647 10
hudakz 9:a156d3de5647 11 Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com>
hudakz 9:a156d3de5647 12
hudakz 9:a156d3de5647 13 This program is free software: you can redistribute it and/or modify
hudakz 9:a156d3de5647 14 it under the terms of the GNU General Public License as published by
hudakz 9:a156d3de5647 15 the Free Software Foundation, either version 3 of the License, or
hudakz 9:a156d3de5647 16 (at your option) any later version.
hudakz 9:a156d3de5647 17
hudakz 9:a156d3de5647 18 This program is distributed in the hope that it will be useful,
hudakz 9:a156d3de5647 19 but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 9:a156d3de5647 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
hudakz 9:a156d3de5647 21 GNU General Public License for more details.
hudakz 9:a156d3de5647 22
hudakz 9:a156d3de5647 23 You should have received a copy of the GNU General Public License
hudakz 9:a156d3de5647 24 along with this program. If not, see <http://www.gnu.org/licenses/>.
hudakz 9:a156d3de5647 25 */
hudakz 9:a156d3de5647 26 #ifndef ENC28J60PHY_H
hudakz 9:a156d3de5647 27 #define ENC28J60PHY_H
hudakz 9:a156d3de5647 28
hudakz 9:a156d3de5647 29 #include "mbed.h"
hudakz 9:a156d3de5647 30 #include "MemPool.h"
hudakz 9:a156d3de5647 31
hudakz 9:a156d3de5647 32 #define UIP_RECEIVEBUFFERHANDLE 0xff
hudakz 9:a156d3de5647 33
hudakz 9:a156d3de5647 34 //#define ENC28J60DEBUG
hudakz 9:a156d3de5647 35
hudakz 11:647d53d146f1 36 class Enc28j60Eth : public MemPool
hudakz 9:a156d3de5647 37 {
hudakz 9:a156d3de5647 38 private:
hudakz 9:a156d3de5647 39 SPI _spi;
hudakz 9:a156d3de5647 40 DigitalOut _cs;
hudakz 9:a156d3de5647 41 static uint16_t nextPacketPtr;
hudakz 9:a156d3de5647 42 static uint8_t bank;
hudakz 9:a156d3de5647 43
hudakz 9:a156d3de5647 44 static struct memblock receivePkt;
hudakz 9:a156d3de5647 45
hudakz 9:a156d3de5647 46 uint16_t setReadPtr(memhandle handle, memaddress position, uint16_t len);
hudakz 9:a156d3de5647 47 void setERXRDPT();
hudakz 9:a156d3de5647 48 void readBuffer(uint16_t len, uint8_t* data);
hudakz 9:a156d3de5647 49 void writeBuffer(uint16_t len, uint8_t* data);
hudakz 9:a156d3de5647 50 void setBank(uint8_t address);
hudakz 9:a156d3de5647 51 uint8_t readReg(uint8_t address);
hudakz 9:a156d3de5647 52 void writeReg(uint8_t address, uint8_t data);
hudakz 9:a156d3de5647 53 void phyWrite(uint8_t address, uint16_t data);
hudakz 9:a156d3de5647 54 uint16_t phyRead(uint8_t address);
hudakz 9:a156d3de5647 55 void clkout(uint8_t clk);
hudakz 9:a156d3de5647 56
hudakz 9:a156d3de5647 57 friend void enc28j60_mempool_block_move_callback(memaddress, memaddress, memaddress);
hudakz 9:a156d3de5647 58 public:
hudakz 11:647d53d146f1 59 Enc28j60Eth(PinName mosi, PinName miso, PinName sclk, PinName cs);
hudakz 9:a156d3de5647 60 uint8_t getrev();
hudakz 9:a156d3de5647 61 void powerOn();
hudakz 9:a156d3de5647 62 void powerOff();
hudakz 9:a156d3de5647 63 bool linkStatus();
hudakz 9:a156d3de5647 64
hudakz 9:a156d3de5647 65 void init(uint8_t* macaddr);
hudakz 9:a156d3de5647 66 memhandle receivePacket();
hudakz 9:a156d3de5647 67 void freePacket();
hudakz 14:7648334eb41b 68 size_t blockSize(memhandle handle);
hudakz 9:a156d3de5647 69 void sendPacket(memhandle handle);
hudakz 9:a156d3de5647 70 uint16_t readPacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len);
hudakz 9:a156d3de5647 71 uint16_t writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len);
hudakz 9:a156d3de5647 72 void copyPacket(memhandle dest, memaddress dest_pos, memhandle src, memaddress src_pos, uint16_t len);
hudakz 9:a156d3de5647 73 uint16_t chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len);
hudakz 9:a156d3de5647 74
hudakz 9:a156d3de5647 75 uint8_t readOp(uint8_t op, uint8_t address);
hudakz 9:a156d3de5647 76 uint8_t readByte(uint16_t addr);
hudakz 9:a156d3de5647 77 void writeOp(uint8_t op, uint8_t address, uint8_t data);
hudakz 9:a156d3de5647 78 void writeRegPair(uint8_t address, uint16_t data);
hudakz 9:a156d3de5647 79 void writeByte(uint16_t addr, uint8_t data);
hudakz 9:a156d3de5647 80 };
hudakz 9:a156d3de5647 81
hudakz 9:a156d3de5647 82 #endif