Well I took a break after making my IP stack that could sometimes transmit.  Now that I have had a bit of time to sleep on it I am deciding to go back and make sure it crashes less often.

I still don’t know quite why it likes to crash but I have found one or two mistakes in my code so hopefully as I go through everything writing extensive tests the bugs will be found.  The first bug I have noticed is that there is an errata for the ENC28J60 that was missed that could corrupt the received packets.  This has now being fixed.

The first test was to check the SPI link as shown in part 3. The test file can be found on github. It does include the ENC28J60 driver but that is only for the register names and locations.  Whilst writing this test I found another small bug in the ENC28J60 driver.  When the device is reset by SPI 0xff is sent. You are meant to wait for 1ms after this occurs as the register that should tell you that it is busy is broken. In my code I was waiting for 1ms but this was not working.  Turns out you should also wait for the PHY component to come online as well. To be on the safe side I also increased the delay to 0.2s as this is at the start time is never really an issue.

The next test was to send an ARP packet and receive a reply. This ensures that the ENC28J60 driver is working correctly for reading and writing a packet of data. It also shows that the EtherNetII and ARP headers are working as expected.  This test file can also be found on github. When I started writing this test I decided that I should probably rewrite a lot of the old ip stack as it doesn’t really read well and is a bit of a mish mash of tests and actual code.  No bugs were found in this section though so that makes a change. I did manage to reduce the memory footprint of the program though.

The next stage is to get the ping example working. This will require a bit more thought than the other sections as I want to make it part of the rewritten ip stack.