0
\$\begingroup\$

I am using a CC1352P1 launchpad from TI and trying to connect it to ENC28J60 for ethernet. I am able to transmit messages to my computer such as an ARP request, and the computer recognizes it and sends back its MAC address. However, I seem to be unable to read packets on the ENC28J60. I have written my own driver to interface with the ENC28J60 and can successfully set and read back values to and from registers on the ENC28J60.

My question is about when to actually call the packet receive function. I modeled my packetReceive function after the packetReceive function in the EtherCard project. I am unsure of where to actually call this function. So far, I have it in a while loop like so:

I've read in the datasheet that when the buffer is fully written to, and packet is available to read, the EIR.PKTIF bit is set and EPKCNT is incremented. Thus, it seemed to me that this would be the place to call my packetReceive function. However, this is not working, as the function either never gets called or never receives valid data. The data that I read from the receive buffer is always all zeros or no data.

while(1){

    ethernet_receiveEnable();

    if(spi_read(EIR) & 0x40){

        uint8_t len = ethernet_packetReceive(receive_Buffer);

    }

    ethernet_receiveDisable();

    sleep(1);


}

Here's my read function

uint8_t ethernet_packetReceive(uint8_t* receiveBuffer){

uint8_t len = 0;

uint8_t status = 0;

uint8_t* header = (uint8_t*) malloc(sizeof(uint8_t)*6);

if (spi_read(EPKTCNT)>0){

    spi_write(ERDPTL, gnextPacketPtr & 0x00ff);

    spi_write(ERDPTH, (gnextPacketPtr & 0xff00)>>8);

    readBufferMemory(header, gnextPacketPtr, 6);

    gnextPacketPtr = header[0] << 8 | header[1];

    status = (header[2]<<8 | header[3]);

    len = (header[4]<<8 | header[5]) - 4;

    if (len > 8092-1)

        len = 8092-1;

    if ((status & 0x80) ==0)

        len = 0;

    else{


        readBufferMemory(receiveBuffer, gnextPacketPtr, len);

        receiveBuffer[len] = 0;

    }

    if(gnextPacketPtr-1 > RXSTOP_INIT){

        spi_write(ERXRDPTL,RXSTOP_INIT & 0x00ff);

        spi_write(ERXRDPTH,(RXSTOP_INIT & 0xff00 )>>8);

    }

    else{

        spi_write(ERXRDPTL,(gnextPacketPtr -1 ) & 0x00ff);

        spi_write(ERXRDPTH,((gnextPacketPtr -1 ) & 0xff00) >> 8 );

    }

    /* set ECON2.PKTDEC */

    selectMemBank(0);

    bitFieldSet(0x1e, 0x40);

} 

return len;

}

I am using the lwIP net stack and intend to call the other wrapper functions if EIE.PKTIF is set, but that's not been working so far.

\$\endgroup\$
3
  • \$\begingroup\$ I don't know anything about the ENC28J60, but does ethernet_receiveDisable stop it from being able to receive packets? \$\endgroup\$ Commented Nov 22, 2019 at 13:12
  • \$\begingroup\$ It does, but in the loop I enable reception again. I disable it to prevent receiving unexpected packets while I'm trying to transmit. \$\endgroup\$ Commented Nov 22, 2019 at 16:08
  • \$\begingroup\$ Well, it looks like 99.999% of the time receiving is disabled. What if the packet comes when receiving is disabled? \$\endgroup\$ Commented Nov 22, 2019 at 16:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.