Created
November 7, 2020 19:49
-
-
Save mdukat/e3ef586d720686be27a7d29836a32072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment