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
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
}