EMAC driver for the ENC28J60 Ethernet controller. This is a simplified fork of https://github.com/tobiasjaster/ENC28J60-EMAC-Driver published by Tobias Jaster.

Dependents:   MQTT_Hello MQTT_HelloENC28J60

EMAC driver for the ENC28J60 Ethernet controller

https://os.mbed.com/media/uploads/hudakz/enc28j60_module01.jpg

This is a fork (the INT and RST pins are not used) of the ENC28J60-EMAC driver published by Tobias Jaster at

https://github.com/tobiasjaster/ENC28J60-EMAC-Driver

Usage:

  • Connect the ENC28J60 module to the Mbed board as follows:

https://os.mbed.com/media/uploads/hudakz/enc28j60-emac.png

  • Import (add) this ENC28J60-EMAC library to your program.
  • Add a "mbed_app.json" file with the following content to the root directory of your program:

    {
        "target_overrides": {
            "*": {
                "platform.callback-nontrivial": true,
                "enc28j60-emac.mosi":  "D11",
                "enc28j60-emac.miso":  "D12",
                "enc28j60-emac.sck" :  "D13",
                "enc28j60-emac.cs"  :  "D10"
            }
        }
    }
  • Replace "D11", ..., "D10" with the actual pin names you selected on the Mbed board to be used for the SPI communication.
  • To set the MAC address define an array with the desired address bytes and call the "set_hwaddr(mac)" function before calling the network interface "connect" function.

For example:

    const uint8_t       MAC[6] = { 0, 1, 2, 3, 4, 5 };
    EthernetInterface   net;
 
    int main()
    {
        net.get_emac().set_hwaddr(MAC);             // set MAC address
        if (net.connect() != 0) {
            printf("Error: Unable to connect to the network.\n");
            return -1;
        }
     ...
Committer:
hudakz
Date:
Mon Mar 29 08:37:01 2021 +0000
Revision:
3:aa88808326b9
Parent:
0:b599e748252c
Mbed OS Ethernet MAC (EMAC) driver for the ENC28J60 Ethernet controller. This a simplified fork of https://github.com/tobiasjaster/ENC28J60-EMAC-Driver published by Tobias Jaster.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:b599e748252c 1 /*
hudakz 0:b599e748252c 2 * enc28j60_emac_config.h
hudakz 0:b599e748252c 3 *
hudakz 0:b599e748252c 4 * Created on: 27.08.2019
hudakz 0:b599e748252c 5 * Author: tobias
hudakz 0:b599e748252c 6 *
hudakz 0:b599e748252c 7 * Modified by Zoltan Hudak
hudakz 0:b599e748252c 8 *
hudakz 0:b599e748252c 9 */
hudakz 0:b599e748252c 10
hudakz 0:b599e748252c 11 #ifndef ENC28J60_EMAC_CONFIG_H_
hudakz 0:b599e748252c 12 #define ENC28J60_EMAC_CONFIG_H_
hudakz 0:b599e748252c 13
hudakz 0:b599e748252c 14 /*
hudakz 0:b599e748252c 15 * ENC28J60 receive buffer size in kylobytes
hudakz 0:b599e748252c 16 */
hudakz 0:b599e748252c 17 #define ENC28J60_ETH_RXBUF_SIZE_KB 6U
hudakz 0:b599e748252c 18 #define ENC28J60_HWADDR_SIZE 6U
hudakz 0:b599e748252c 19 #define ENC28J60_BUFF_ALIGNMENT 4U
hudakz 0:b599e748252c 20
hudakz 0:b599e748252c 21 /*
hudakz 0:b599e748252c 22 * Maximum Transfer Unit
hudakz 0:b599e748252c 23 * The IEEE 802.3 specification limits the data portion of the 802.3 frame
hudakz 0:b599e748252c 24 * to a minimum of 46 and a maximum of 1522 bytes, this is on L2 level.
hudakz 0:b599e748252c 25 */
hudakz 0:b599e748252c 26 #define ENC28J60_ETH_MTU_SIZE 1500U
hudakz 0:b599e748252c 27 #define ENC28J60_ETH_IF_NAME "enc28j60"
hudakz 0:b599e748252c 28
hudakz 0:b599e748252c 29 /** \brief Defines for receiver thread */
hudakz 0:b599e748252c 30 #define LINK_STATUS_TASK_PERIOD_MS 200ms
hudakz 0:b599e748252c 31 #define RECEIVE_TASK_PERIOD_MS 20ms
hudakz 0:b599e748252c 32 #define PHY_STATE_LINK_DOWN false
hudakz 0:b599e748252c 33 #define PHY_STATE_LINK_UP true
hudakz 0:b599e748252c 34 #define CRC_LENGTH_BYTES 4U
hudakz 0:b599e748252c 35
hudakz 0:b599e748252c 36 #endif /* ENC28J60_EMAC_CONFIG_H_ */