Wednesday, June 27, 2012

ENC28J60 - PSoC3 - Part 1 - SPI

Okay,
First,we need to hook-up our module to the PSoC board,and get it talking over SPI.
A couple of points first:
  • The module runs on 3.3V,so set logic levels accordingly.
  • We need the MOSI,MISO,SCK,CS and RST pins from the module connected to our chip.Yes,the usual SPI ones.Ensure that these connections are secure and well,since we cant be doubting and debugging everything.
Connections with the ENC28J60 module.(Image Credits to www.embeddedmarket.com)



 
  • This chip takes 3.3V at a max operating current of 250mA,so that makes almost 0.825W of heat.I've put on some thermal paste to my chip,and stuck on a small heatsink.The heatsink kind that you could use for any chip in a TO-220 package works well.
A TO-220 heatsink fastened with a plastic tie on the ENC28J60.

  • Arrange your board and module so that that its convenient to connect a LAN cable to the module later.

So,what we need to do first,is test if our hardware connections are fine.We will try and talk to the chip over SPI,and read some fixed registers.Most chips have a silicon revision register,and so does this one.Infact,we'll see if we can do something more too :-P

You should read through your copy of the datasheet,upto the section titled 'Ethernet Overview'.
Heres a quick summary of the ..


Memory Organization:
-So it has 3 kinds of registers,Control,Ethernet and PHY registers.Control and Ethernet registers can be accessed by the SPI commands,while the PHY ones need some extra work,and cant be directly written to by our host controller,the PSoC.

Apart from these,theres the 8kb Packet buffer,which will store your packets to be sent,or the ones it receives.This can be accessed via the relevant SPI command.

SPI Commands:
So there are a bunch of commands,and note that this runs in Mode 0 of SPI.If you look at the errata,there is a point that says you may have problems of data integrity if you work at SPI clock speeds lower than 8Mhz.I'm running at 10Mhz.Everything else about the SPI interface is pretty standard,so I wrote out a bunch of functions to do this SPI talking,..you know,the basics.Byte Send,Byte Receive..and multi-byte RX/TX functions too.

Oh and,heres what my TopDesign view looks like in PSoC Creator,

Note how the RESET pin is tied to a logic level '1'.Thats required to hold the chip in a usable state.You may also have noted that the SS(Slave select) pin hasnt been connected to the SPIM module,since we will be controlling this ourselves around an operation,rather than a byte transferred.

And heres what I configured my SPIM module as:
 


I tried to read the Silicon Revision of the chip,and tried to blink the LEDs on the Magjack of the chip,over SPI.
If your connections are fine,and the SPI module is setup correctly,there should be no issues.

Check out the hardware test code here.

The next post will deal with Chip Initialization and then some actual packet play! :-)