Sunday, July 8, 2012

ENC28J60 - PSoC3 - Part 2 - Memory Operations

Based on what we talked about in the last post,I'll detail the PSoC-side functions to deal with different types of memory that the ENC28J60 has to offer.

The first function we need is one to write to a control register.Thats pretty straightforward,

Similarly,we'd have one for Reading from control registers too.

Since the registers are divided into 4 Banks,Bank0 to Bank3,the next basic function to play with the registers is the Bank Select function.
The ECON1 register hold a 2 bit field for selecting any one of the 4 banks.

Heres what that code looks like:

We'll briefly look into Reading and Writing of PHY Registers.I'll let the comments do the talking.

And based on the sequence of events to Read a PHY Register as mentioned in Section 3.3.1 on Page 21 of the datasheet,we'll need to
1.Write into MIREGADR (MI REGister ADRess! Its all logical.) the address of the PHY Register we wish to Read.
2.Then command a read by setting the MIIRD bit in the MICMD Register,
3.We then need to check the MISTAT register for the busy status,that will prevail till that Read is over.The MAC will auto-clear that when its done reading,and has deposited the data in MIRDL and MIRDH registers.
4.Once the read is over,we should clear the MIIRD bit,and then read off the 16 bit data,with the higher byte in MIRDH and lower one in MIRDL.
And heres what that looks like in code:


Basically,we should look to have a function for each of the basic SPI commands mentioned in Table 4-1 on Page 28 of the datasheet.

The Bit Field Set and Clear functions are pretty much easy to put together.The buffer reading/writing functions come next.These are the functions that will be used most often,since we will be using these to read and write packets that we need from the ENC chip.
Theres nothing great with these either,but you need to follow the datasheet properly.


Note how the Chip Select is toggled around the entire write operation.Thats very important.I missed that point an year back,and which is why I never got consistent read/write operations.The Read buffer function is also very similar.

You may check out the all the ENC28J60 driver code here : ENC28J60 Driver functions

No comments:

Post a Comment