Connect with us

Initializing an ENC28J60

Discussion in 'Electronic Basics' started by Josef Moellers, Feb 16, 2013.

Scroll to continue with content
  1. 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))


    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,

  2. Oh, this is so emberassing.

    "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.
    No worries, mate!

  3. Another followup to self:

    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.

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day