Maker Pro
Maker Pro

Initializing an ENC28J60

J

Josef Moellers

Hi,

I'm currently trying to convert a "NET-IO" board of the German shop
"Pollin" into a Serial-to-LAN-adapter and learn something on the way (so
"use the ethersex code" is not an option ;-).

I have disassembled the original code (which allows access to 8 digital
outputs, 4 digital inputs and 4 analog inputs), have the datasheet and
have also d/l-ed the ethersex code but no matter how hard I try, I do
not get a single packet received! EPKTCNT stays 0 even if I ping a
non-existent IP address (UC, MC, and BC are obviously ENabled!)

I have traced this back and I find that MARST is clear after a SOFT
RESET, while it should be set according to the datasheet! So I gather
that the MAC unit is not working.

My code looks like this (I hope the function names are self-explanatory):

/* Wait for ESTAT.CLKRDY */
while (!ENC28J60_RCR(REG_ESTAT) & (1 << 0))
;

CS_low();
SPI_send(0xff);
CS_high();

_delay_ms(10);
ENC28J60_Bank(2);
b = ENC28J60_RCR(REG_MACON2);
USART_puthex(b); USART_Transmit('\r'); USART_Transmit('\n');

The output is "00", with and without the delay.
When I initialize the remaining registers (ERXST(HL), ...) I can read
them back and they come out as I write them, so my access code should be OK.
I have also hooked up a logic analyzer to CS and the SPI lines and I see
that CS goes low, the 8 clock pulses with SI staying high, then CS goes
back high, so the soft reset really leaves the ATMEGA32.

Any hints?

Thanks in advance,

Josef
 
J

Josef Moellers

Oh, this is so emberassing.

Hi,

I'm currently trying to convert a "NET-IO" board of the German shop
"Pollin" into a Serial-to-LAN-adapter and learn something on the way (so
"use the ethersex code" is not an option ;-).

I have disassembled the original code (which allows access to 8 digital
outputs, 4 digital inputs and 4 analog inputs), have the datasheet and
have also d/l-ed the ethersex code but no matter how hard I try, I do
not get a single packet received! EPKTCNT stays 0 even if I ping a
non-existent IP address (UC, MC, and BC are obviously ENabled!)

I have traced this back and I find that MARST is clear after a SOFT
RESET, while it should be set according to the datasheet! So I gather
that the MAC unit is not working.

My code looks like this (I hope the function names are self-explanatory):

/* Wait for ESTAT.CLKRDY */
while (!ENC28J60_RCR(REG_ESTAT) & (1 << 0))
;

CS_low();
SPI_send(0xff);
CS_high();

_delay_ms(10);
ENC28J60_Bank(2);
b = ENC28J60_RCR(REG_MACON2);
USART_puthex(b); USART_Transmit('\r'); USART_Transmit('\n');

The output is "00", with and without the delay.
When I initialize the remaining registers (ERXST(HL), ...) I can read
them back and they come out as I write them, so my access code should be OK.
I have also hooked up a logic analyzer to CS and the SPI lines and I see
that CS goes low, the 8 clock pulses with SI staying high, then CS goes
back high, so the soft reset really leaves the ATMEGA32.

Any hints?

Yes:
"If the address specifies one of the MAC or MII registers,
a dummy byte will first be shifted out the SO pin. After
the dummy byte, the data will be shifted out MSb first
on the SO pin."

So rather than "SPI_send(RCR | MACON2); macon2 = SPI_send(0);" I have to
do "SPI_send(RCR | MACON2); SPI_send(0); macon2 = SPI_send(0);"
*then* the MARST bit comes out set!

Why I still do not see packets coming in is my next concern.
Thanks in advance,

No worries, mate!

Josef
 
J

Josef Moellers

Another followup to self:

Oh, this is so emberassing.



Yes:
"If the address specifies one of the MAC or MII registers,
a dummy byte will first be shifted out the SO pin. After
the dummy byte, the data will be shifted out MSb first
on the SO pin."

So rather than "SPI_send(RCR | MACON2); macon2 = SPI_send(0);" I have to
do "SPI_send(RCR | MACON2); SPI_send(0); macon2 = SPI_send(0);"
*then* the MARST bit comes out set!

Why I still do not see packets coming in is my next concern.

I had inadvertedly set LOOPBK in MACON1, effectively short-circuiting
the chip. That will teach me not to use symbolic names ;-)

I finally received some packets and already dumped one. It was great
seeing MAC- and IP-address of a host in my network.

Josef
 
Top