Hi!
After a while away from the hobby I'm back on the seddle and my next project requires an Ethernet Gatway connected to a Moteino Mega.
But I just can't make the ENC28J60 work.
I'm connecting MISO to pin 6, SCK to pin 7, and MOSI to pin 5. The SS/CS is the problem here. I tried connecting it to several places and nothing work. I'm using Ethercard.h library and on this library there is a file called enc28j60.h where pin 8 is assumed to be the CS pin.
/** @brief Initialise network interface
* @param size Size of data buffer
* @param macaddr Pointer to 6 byte hardware (MAC) address
* @param csPin Arduino pin used for chip select (enable network interface SPI bus). Default = 8
* @return <i>uint8_t</i> ENC28J60 firmware version or zero on failure.
*/
static uint8_t initialize (const uint16_t size, const uint8_t* macaddr,
uint8_t csPin = 1);
I tried to use pin 8, changed the code to use pin 1 and nothing makes the board work.
I know there are here those who managed to do this so I ask for some guidance on how to tackle this.
As for the code I'm using it 's nothing fancy:
#include <EtherCard.h>
#define STATIC 0 //Para definir um IP estático mudar de 0 para 1
//To set a static IP change from 0 to 1
#if STATIC
static byte myip[] = { 192,168,1,70 }; //Definição do IP estático/Setting the static IP
static byte gwip[] = { 192,168,1,1 }; //Endereço IP do Gateway da rede/Gateway IP address of the network
#endif
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; //*MAC Address
//*MAC Address da interface ethernet - Tem de ser único na sua rede
//*MAC Address of the Ethernet interface - must be unique in your network
byte Ethernet::buffer[500];
const char page[] PROGMEM = //Página HTML/HTML page
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Refresh: 5\r\n"
"\r\n"
"<html>"
"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"
" <head>"
" <title>Arduino WebServer</title>"
" </head>"
" <body>"
" <center>"
" <h1>Módulo Ethernet ENC28J60</h1>"
" <hr>"
" <h3>Página de resposta do nosso Arduino.</h3>"
" <h4>Para mais informações visite o blogue TecnoDomos.</h4>"
" <a href='http://www.tecnodomos.blogspot.com'>TecnoDomos</a>"
" <hr>"
" </center>"
" </body>"
"</html>"
;
void setup(){
Serial.begin(57600);
Serial.println( "Modulo Ethernet ENC28J60/ENC28J60 Ethernet module");
Serial.println("\n[webserver]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Falha ao aceder ao controlador Ethernet/Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP falhou / DHCP failed");
#endif
Serial.println("Parametros da rede / Network parameters");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}
It will get me this on the Serial monitor:
Modulo Ethernet ENC28J60/ENC28J60 Ethernet module
[webserver]
DHCP falhou / DHCP failed
Parametros da rede / Network parameters
IP: 0.0.0.0
GW: 0.0.0.0
DNS: 0.0.0.0
Thank you
Luis