Continueing my quest to get the enc28j60 working on the atmega328p..
Yesterday I found some weirdness on the SPI pins (MOSI idle high) that didn't appear to be a problem really.
Today I found something that IS a problem. To me this looks to be a silicon bug, but maybe I'm just missing something, please your thoughts.
I still have the loopback setup, miso connected to mosi (and sometimes Vcc and sometimes GND, to simulate various situations), first the SPI thing must work really well before I start again with the enc28j60.
This works, if I output the results on some leds. But I need to be able to debug properly, so using DebugWire.
It appears everytime I output a byte (write to SPDR), the code hangs. Further investigation makes clear the SPIF bit in SPSR is never set. Hmmm, looks very much like the problem here:
And indeed, it appears the MSTR bit is cleared, SPI is in slave mode, and that explains the lot.
BUT my /SS (aka PORTB2) is OUTPUT. I checked this with the debugger, but also by simply setting the port ON and then indeed it goes "ON".
Also very interesting, when I turn PORTB2 ON, the MSTR bit is no longer cleared and it works.
So to summerise:
- /SS is set to output (like sheet says)
- SPI works when in normal running mode
- SPI goes to slave when run in DebugWire mode, unless /SS is set HIGH
To me that looks like some internal multiplexer is (incorrectly) overriden by DebugWire mode.
Any thoughts, experiences?