ATmega1284p & ENC29J60 Ethernet Shield Problem's

Hey guys. very new hear and in fact very new to Arduino’s.

I was up all night trying to wire the ATMega1284 to a pretty standard ENC29J60.

I checked the ENC29j60 on a 2560 wired on pins 54,53,52,51 iv’e also had it working perfectly well on bread boarded Atmega328p pins 11,12,13 and worked an absolute treat. but on the ATmega1284p I’m getting absolutely no where.

using these libary’s https://github.com/jcw/ethercard

Thanks in advanced guys :slight_smile:

If you have the ethercard library running with a Uno and a ENC28J60, you are no longer new to Arduino. It is something for advanced users.

The Mega (and Mega2560) use the SPI bus the same way, but you have to adapt the pin numbers for the Mega. If a different ChipSelect is used, the SS pin of the Mega2560 has to be set as output, to make the SPI hardware working.

The function "xferSPI()" in "enc28j60.cpp" is the function to communicate with the chip. It uses the SPI hardware by direct register access. The ChipSelect line is set with the begin() function (the third csPin parameter). I think if you set that to the SS pin of the Mega, it should work.

thats great, will give this a try later this evening.

thanks for your response will let you know how it goes :)

Thanks.

ectraz:
thats great, will give this a try later this evening.

thanks for your response will let you know how it goes :slight_smile:

Thanks.

I’m just diging thro ENC28J60.cpp and have found this.

static void xferSPI (byte data) {
SPDR = data;
while (!(SPSR&(1<<SPIF)))
;
}

… little lost now lol, any more pointers?

I’m guessing this is what im looking for.

void ENC28J60::initSPI () {
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH);
pinMode(MOSI, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(MISO, INPUT);

digitalWrite(MOSI, HIGH);
digitalWrite(MOSI, LOW);
digitalWrite(SCK, LOW);

SPCR = bit(SPE) | bit(MSTR); // 8 MHz @ 16
bitSet(SPSR, SPI2X);
}

but no reference to pin numbers so im stumped.

The SS has to be output, regardless of which pin you use for ChipSelect. That was what I ment in my previous post. That is what is happening in that initSPI() code. That is good, you don't have to set the SS pin as output yourself.

The begin() function has a third parameter for the ChipSelect. You could use the SS pin, but also another pin can be use for the ChipSelect. If you don't use the third parameter, perhaps it defaults to pin 8 or so.

I have a Mega2560 with Ethernet Shield, and a Uno with ENC28J60 and ethercard. So I don't have your combination, but with the right ChipSelect it should work.

Did you ever get this to work?