Skip to content

Instantly share code, notes, and snippets.

@mdukat
Created November 7, 2020 19:49
Show Gist options
  • Select an option

  • Save mdukat/e3ef586d720686be27a7d29836a32072 to your computer and use it in GitHub Desktop.

Select an option

Save mdukat/e3ef586d720686be27a7d29836a32072 to your computer and use it in GitHub Desktop.

Revisions

  1. mdukat created this gist Nov 7, 2020.
    70 changes: 70 additions & 0 deletions enc28j60-register-test.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    #include <SPI.h>

    /*
    * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004
    Everyone is permitted to copy and distribute verbatim or modified
    copies of this license document, and changing it is allowed as long
    as the name is changed.
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
    0. You just DO WHAT THE FUCK YOU WANT TO.
    */

    // I made this code in order to check if my ENC28J60 module works
    // As this program says for now, it's not capable of changing
    // Register Bank, so my conclusion is that it's dead. I don't have
    // working ENC28J60 tho, so don't be pissed if this code says
    // that your ENC is broken, since it's not tested.

    void setup() {
    Serial.begin(115200);
    Serial.println("Starting...");
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    digitalWrite(SS, HIGH);

    }

    void loop() {
    byte MSEND, MRECV; // Master Send/Receive

    digitalWrite(SS, LOW);
    MSEND = 0b11111111; // Send "SYSTEM RESET COMMAND"
    SPI.transfer(MSEND);
    digitalWrite(SS, HIGH);

    digitalWrite(SS, LOW);
    MSEND = 0b00011111; // Send "Read Control Register ECON1"
    MRECV = SPI.transfer(MSEND);
    digitalWrite(SS, HIGH);
    Serial.print("ECON1: ");
    Serial.print(MRECV, BIN);
    Serial.println();

    Serial.println("Sending Bank Select 3...");
    digitalWrite(SS, LOW);
    MSEND = 0b01011111; // Send "Write Control Register ECON1"
    SPI.transfer(MSEND);
    MSEND = 0b00000011; // ECON1 Bank Select 3
    SPI.transfer(MSEND);
    digitalWrite(SS, HIGH);

    digitalWrite(SS, LOW);
    MSEND = 0b00011111; // Send "Read Control Register ECON1"
    MRECV = SPI.transfer(MSEND);
    digitalWrite(SS, HIGH);
    Serial.print("ECON1: ");
    Serial.print(MRECV, BIN);
    Serial.println();

    if(MRECV == 0b00000011)
    Serial.println("ECON1 Bank select OK")
    else
    Serial.println("ECON1 Bank select ERROR")

    while(1){}; // Don't loop
    }