Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SPI Testing with ENC28J60

Status
Not open for further replies.

mikesmixes777

New Member
Hi
I have connected my PIC18LF252 to an ENC28J60 via SPI.

I want to test that the SPI is working. I have written a routine to query one of the ENC28J60 register...but I'm not getting anything back.

Can someone shed any light on the ENC28J60 and its SPI interface...

THanks

Code:
unsigned int spi_rxbuf;


void spi_rw(void);
void init_spi(void);


void main(void)

{
	
	TRISA=0b00001011;	//AN0,AN1,AN3 =>Inputs
	TRISC=0b10010000;	//RC7(RX), RC4(SDI) =>Inputs.

	
	init_spi();
	LED1 = ON;


	while(1)
	{
		spi_rw();
	}
}


void init_spi(void)		//Setup SPI comms
{
	SSPSTAT=0b01000000;	//SPI data at middle of output time,
				//Data tx on RISING edge of SCK *ENC28J60
	SSPCON1=0b00100001;	//Fosc/16, SSPEN=enabled, 
}
	

void spi_rw(void)
{
	CS = LOW;		//Start 
	SSPBUF = 0b00011110;	//Read (000) ECON2 at addr 0x1E (11110)
	spi_rxbuf = SSPBUF;
	CS = HIGH;		//Stop
}
 
You need till the end of the transfer before reading SSPBUF.

Code:
/* writes to SPI. BF is checked inside the procedure */
/* returns SSPBUF	*/ 
BYTE wr_SPI ( BYTE data )
{
 SSPBUF = data;          		// write byte to SSPBUF register
 while( !SSPSTATbits.BF ); 	// wait until bus cycle complete 
 return ( SSPBUF );         //
}
 
I'm not sure if its working properly now, I'm not sure of the data received back. Are there any constant registers that I can poll in the ENC28J60 that I will know what to expect?

Code:
	while(1)
	{
		spi_rw(0x1E);		//0b00011110
		
	}	


char spi_rw(char data)
{
	CS = LOW;
	CS = LOW;			//Start 
	SSPBUF = data;			//Read (000) ECON2 at addr 0x1E (11110
	while (!SSPSTATbits.BF);
	return (SSPBUF);
	CS = HIGH;			//Stop
}
 
I'm REALLY new to this SPI so you have to exscuse my lack of understanding...

Im trying to get the steps to write to MACON1...

I see MACON1 is in BANK2 & addr 00h (pg12)

Now to select BANK2 I need to write to the ECON1, but when do i actually send 010(op-code) 00000 (addr of MACON1) 00000101 (data) ?
 
Ahh... I am actually just on the site at the moment...Thanks for the link...

I came to the conclusion that it is a VERY tricky chip. I been looking thru all the project details at this site and I found that there applications are very indepth, even the mini10T application (http://www.ljcv.net/projects/minipic10t/index.html).

I want to have my own html webpage aswell as log some analog inputs and control digital outputs...but they are running "multi-layer" programs and to see where or how i can add my application and code in seems a nightmare.

Any suggestions...Is there a plain ENC28J60 driver generic for the PIC18F...?

Thanks for the help.
 
That is the generic version. Writing an Ethernet stack is no cakewalk.
An ENC28J60 / 18F4620 is likely the next kit coming out from us. I've got a working prototype :) just working on the "super I/O" part.
 
I agree that writing an ethernet stack and driver for the ENC28J60 is NOT a cakewalk.

Will I have any luck with my small 18F252? I was thinking of adding a 25LC256 SPI eeprom.

So would your advice be to get my project up and running?
Thanks
Mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top