From 1cf264caca77b425e32ec73a0319af7e8143ec2b Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Fri, 22 Feb 2013 20:05:17 +0100 Subject: [PATCH] Allow to choose the chip select pin on ENC28J60. Nanode uses pin 8 as CS for ethernet module, but not all the ENC28J60 boards uses the same pin. --- NanodeUIP.cpp | 6 +++++- NanodeUIP.h | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NanodeUIP.cpp b/NanodeUIP.cpp index cfa4fea..a3e9530 100644 --- a/NanodeUIP.cpp +++ b/NanodeUIP.cpp @@ -48,11 +48,15 @@ NanodeUIP::NanodeUIP(void) { } void NanodeUIP::init(const byte *macaddr) { + init(macaddr, NANODE_DEFAULT_CS); +} + +void NanodeUIP::init(const byte *macaddr, int cs) { const struct uip_eth_addr *mac=(struct uip_eth_addr *)macaddr; uip_setethaddr((*mac)); enc28j60SpiInit(); - enc28j60InitWithCs(macaddr, 8); + enc28j60InitWithCs(macaddr, cs); enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz delay(10); timer_set(&periodic_timer, CLOCK_SECOND / 2); diff --git a/NanodeUIP.h b/NanodeUIP.h index 620a854..16801ae 100644 --- a/NanodeUIP.h +++ b/NanodeUIP.h @@ -7,6 +7,8 @@ #include // Arduino 0022 #endif +#define NANODE_DEFAULT_CS 8 + #include "uip.h" #include "timer.h" @@ -33,6 +35,7 @@ class NanodeUIP { NanodeUIP(void); void init(const byte *macaddr); // Call in setup() + void init(const byte *macaddr, int cs); void poll(void); // Must be called regularly in your sketch's loop() /* Link status functions */