ENC28J60 receive buffer first time receive discrepancy
I posted here earlier about being able to transmit but being unable to receive packets into the ENC28J60. I mostly fixed some of the bugs in my receive function and to find out the length of the packet that is being input.
However I still have a bug in my receive logic that I have worked around but I want to eventually fix since I feel it is error prone.
According to the ENC28J60 datasheet, Each packet should first contain 2 bytes of a nextpacketpointer, 4 bytes of status, and then the payload data described below.
The first time I receive a packet into the ENC28J60, EPKTCNT is incremented and I process the packet. For example, I receive the following bytes in the first packet: Packet 1______________________ Next Packet Pointer: (2 bytes)
(4 bytes) (According to ENC28J60 datasheet I should get
Destination MAC address (6 bytes)
Source MAC address (6 bytes)
Type of protocol (say, ARP) (2 bytes)
Hardware type (Ethernet) (2 bytes)
Protocol Type (IPv4) (2 bytes)
Hardware size (6 bytes)
Protocol size (4 bytes)
Payload data (variable bytes)
CRC (4 bytes) Packet 2
:Next packet pointer
When I dump the receive buffer, I always seem to miss the first byte of nextpacketpointer for the very first packet I receive, but I get it for each subsequent packet. This means that I have to guess the nextpacketpointer for the first time (It should be 0x45 since the length of the packet is 70 based on where the next packet is actually coming in) which I have managed to do since I know the first packet is going to be an ARP request, and then I can proceed from there, but I would rather find out why I am not getting this first byte in the first place.
post edited by sramnath - 2019/12/06 13:36:07