Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Not able to communicate with ENC28J60

Status
Not open for further replies.

khansaab21

Advanced Member level 4
Joined
Apr 12, 2008
Messages
108
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,298
Activity points
2,214
Microcontroller: PIC18F4520
Ethernet controller: ENC28J60
Compiler: MikroC
Libraries used: SPI

Code description: Following code has been picked up from
EasyPic2 with on-board Ethernet Adapter

/*
* ENC SPI commands
*/
#define WCRCMD 0b01000000 // write control register
#define BFCCMD 0b10100000 // bit field clear
#define BFSCMD 0b10000000 // bit field set
#define BFCCMD 0b10100000 // bit field clear

/*
* ENC SFR
*/
#define MIREGADR 0x14
#define ECON1 0x1f

#define PHLCON 0x14
#define MIWRL 0x16

/*
* ENC PHY register
*/
#define MIWRH 0x17

/*
* ENC CS control
*/
#define Select() PORTC.F1 = 0
#define Deselect() PORTC.F1 = 1

/*
* 1 ms delay
*/
void delay1ms()
{
Delay_ms(1) ;
}

/*
* writes byte v in ENC register addr of the current bank
*/
void writeReg(unsigned char addr, unsigned short v)
{
Select() ;
SPI1_Write(WCRCMD | addr) ;
SPI1_Write(v) ;
Deselect() ;
}

/*
* main entry
*/
void main()
{
PORTC = 0 ;
TRISC = 0b11111100 ; // set PORTC as input except for bits 0 (RESET) and 1 (CS)

Deselect() ; // don't talk to ENC

SPI1_Init() ; // init SPI communication, clock = Fosc / 4

PORTC.F0 |= 0b00000001 ; // reset = high
delay1ms() ; // wait a little bit
PORTC.F0 &= 0b11111110 ; // reset = low, HW reset
delay1ms() ; // wait a little bit
PORTC.F0 |= 0b00000001 ; // end of reset
delay1ms() ; // wait for completion

/*
* set ENC memory bank 2
*/
Select() ;
SPI1_Write(BFCCMD | ECON1) ;
SPI1_Write(0b00000001) ;
Deselect() ;

Select() ;
SPI1_Write(BFSCMD | ECON1) ;
SPI1_Write(0b00000010) ;
Deselect() ;

/*
* set address of PHY register to write
*/
writeReg(MIREGADR, PHLCON) ;

/*
* set LEDA for link status display
* and LEDB for blink fast
*/
writeReg(MIWRL, 0b10100010) ;
writeReg(MIWRH, 0b00000100) ;
}


This code sets LEDA as link status display and makes LEDB blink permanently

Problem: As you must have expected, the system is not working. The code seems correct and has been tested by many people, so nothing wrong with. Same page displays the hardware schematic, and the circuit configuration is same except I have also used level translator buffers (for the pins as indicated by data sheet). I have checked connections and re-checked connections countless times but nothing appears wrong.

Can anybody please help me on this!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top