Skip to content

Instantly share code, notes, and snippets.

@quartzjer
Created August 23, 2014 17:26
Show Gist options
  • Save quartzjer/9c54e36fb69e270be6b9 to your computer and use it in GitHub Desktop.
Save quartzjer/9c54e36fb69e270be6b9 to your computer and use it in GitHub Desktop.
minimal spi w5100 ethernet boot test for debugging
/**************************************************************************\
* Pinoccio Library *
* https://github.com/Pinoccio/library-pinoccio *
* Copyright (c) 2014, Pinoccio Inc. All rights reserved. *
* ------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the MIT License as described in license.txt. *
\**************************************************************************/
#include <SPI.h>
#include <Wire.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x9C, 0x42 };
byte ip[] = { 192, 168, 2, 2 };
//EthernetClient client;
void write(uint8_t a, uint8_t b, uint8_t c)
{
digitalWrite(SS, LOW);
SPI.transfer(0xF0);
SPI.transfer(a);
SPI.transfer(b);
SPI.transfer(c);
digitalWrite(SS, HIGH);
}
uint8_t read(uint8_t a, uint8_t b)
{
uint8_t ret;
digitalWrite(SS, LOW);
SPI.transfer(0x0F);
SPI.transfer(a);
SPI.transfer(b);
ret = SPI.transfer(0);
digitalWrite(SS, HIGH);
return ret;
}
void setup() {
Serial.begin(115200);
// Scout.setup("ethernet", "custom", 42);
// Ethernet.begin(mac, ip);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SS, OUTPUT);
delay(1000);
SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
write(0, 0, 0x80);
write(0, 0x1B, 0x55);
write(0, 0x1A, 0x55);
write(0, 0x09, mac[0]);
write(0, 0x0A, mac[1]);
write(0, 0x0B, mac[2]);
write(0, 0x0C, mac[3]);
write(0, 0x0D, mac[4]);
write(0, 0x0E, mac[5]);
write(0, 0x0F, ip[0]);
write(0, 0x10, ip[1]);
write(0, 0x11, ip[2]);
write(0, 0x12, ip[3]);
delay(1000);
Serial.print("READ ");
Serial.print(read(0x04, 0x03),HEX);
Serial.print(" ");
Serial.print(read(0x05, 0x03),HEX);
Serial.print(" ");
Serial.print(read(0x06, 0x03),HEX);
Serial.print(" ");
Serial.print(read(0x07, 0x03),HEX);
Serial.print(" ");
Serial.println(" done");
SPI.endTransaction();
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment